Repository: vitessio/vitess
Pull request #8607 (2021-08-09 14:35:29)

Inclusive Naming: Change master to primary in examples:local,legacy_local,region_sharding
Signed-off-by: Rohit Nayak <rohit@planetscale.com>

<!--
  Thank you for your contribution to the Vitess project.
  How to contribute: https://vitess.io/docs/contributing/
  Please first make sure there is an open Issue to discuss the feature/fix suggested in this PR.
  If this is a new feature, please mark the Issue as "RFC".
 -->

<!-- if this PR is Work in Progress please create it as a Draft Pull Request -->

## Description
<!-- A few sentences describing the overall goals of the pull request's commits. -->
<!-- If this is a bug fix and you think the fix should be backported, please write so. -->

## Related Issue(s)
<!-- List related issues and pull requests. If this PR fixes an issue, please add it using Fixes #????  -->


## Checklist
- [ ] Should this PR be backported?
- [ ] Tests were added or are not required
- [ ] Documentation was added or is not required

## Deployment Notes
<!-- Notes regarding deployment of the contained body of work. These should note any db migrations, etc. -->


Patch:
diff --git a/examples/legacy_local/101_initial_cluster.sh b/examples/legacy_local/101_initial_cluster.sh
index 4472412e94..65dae0a507 100755
--- a/examples/legacy_local/101_initial_cluster.sh
+++ b/examples/legacy_local/101_initial_cluster.sh
@@ -37,7 +37,7 @@ for i in 100 101 102; do
  CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ./scripts/vttablet-up.sh
 done
 
-# set one of the replicas to master
+# set one of the replicas to primary
 vtctlclient -server localhost:15999 InitShardMaster -force commerce/0 zone1-100
 
 # create the schema
diff --git a/examples/legacy_local/201_customer_keyspace.sh b/examples/legacy_local/201_customer_keyspace.sh
index f948175195..ea8a0956b7 100755
--- a/examples/legacy_local/201_customer_keyspace.sh
+++ b/examples/legacy_local/201_customer_keyspace.sh
@@ -16,5 +16,5 @@
 
 # this script creates a new keyspace in preparation for vertical resharding
 
-vtctlclient -server localhost:15999 CreateKeyspace -served_from='master:commerce,replica:commerce,rdonly:commerce' customer
+vtctlclient -server localhost:15999 CreateKeyspace -served_from='primary:commerce,replica:commerce,rdonly:commerce' customer
 
diff --git a/examples/legacy_local/205_vertical_migrate_master.sh b/examples/legacy_local/205_vertical_migrate_master.sh
index 211d27eb6a..f2b09140a1 100755
--- a/examples/legacy_local/205_vertical_migrate_master.sh
+++ b/examples/legacy_local/205_vertical_migrate_master.sh
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# this script migrates master traffic for the customer keyspace to the
-# new master tablet
+# this script migrates primary traffic for the customer keyspace to the
+# new primary tablet
 
-vtctlclient -server localhost:15999 MigrateServedFrom customer/0 master
+vtctlclient -server localhost:15999 MigrateServedFrom customer/0 primary
diff --git a/examples/legacy_local/206_clean_commerce.sh b/examples/legacy_local/206_clean_commerce.sh
index 7111a4a91f..d4734338b4 100755
--- a/examples/legacy_local/206_clean_commerce.sh
+++ b/examples/legacy_local/206_clean_commerce.sh
@@ -20,4 +20,4 @@
 vtctlclient -server localhost:15999 ApplySchema -sql-file drop_commerce_tables.sql commerce
 vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 rdonly
 vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 replica
-vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 master
+vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 primary
diff --git a/examples/legacy_local/305_migrate_master.sh b/examples/legacy_local/305_migrate_master.sh
index a9da079ea7..fd3bda4e8c 100755
--- a/examples/legacy_local/305_migrate_master.sh
+++ b/examples/legacy_local/305_migrate_master.sh
@@ -14,8 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# this script migrates traffic for the master tablet
+# this script migrates traffic for the primary tablet
 
-vtctlclient -server localhost:15999 MigrateServedTypes customer/0 master
+vtctlclient -server localhost:15999 MigrateServedTypes customer/0 primary
 # data has been copied over to shards, and databases for the new shards are now available
 
diff --git a/examples/legacy_local/scripts/vtgate-up.sh b/examples/legacy_local/scripts/vtgate-up.sh
index e3fe2d17f8..a9456348ab 100755
--- a/examples/legacy_local/scripts/vtgate-up.sh
+++ b/examples/legacy_local/scripts/vtgate-up.sh
@@ -36,7 +36,7 @@ vtgate \
   -mysql_server_socket_path $mysql_server_socket_path \
   -cell $cell \
   -cells_to_watch $cell \
-  -tablet_types_to_wait MASTER,REPLICA \
+  -tablet_types_to_wait PRIMARY,REPLICA \
   -gateway_implementation discoverygateway \
   -service_map 'grpc-vtgateservice' \
   -pid_file $VTDATAROOT/tmp/vtgate.pid \
diff --git a/examples/local/101_initial_cluster.sh b/examples/local/101_initial_cluster.sh
index 40c83ad8ec..90114bb666 100755
--- a/examples/local/101_initial_cluster.sh
+++ b/examples/local/101_initial_cluster.sh
@@ -37,7 +37,7 @@ for i in 100 101 102; do
 	CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ./scripts/vttablet-up.sh
 done
 
-# set one of the replicas to master
+# set one of the replicas to primary
 vtctldclient InitShardPrimary --force commerce/0 zone1-100
 
 # create the schema
diff --git a/examples/local/204_switch_writes.sh b/examples/local/204_switch_writes.sh
index b2d85708a3..5f73cdfd59 100755
--- a/examples/local/204_switch_writes.sh
+++ b/examples/local/204_switch_writes.sh
@@ -14,9 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# this script migrates master traffic for the customer keyspace to the
-# new master tablet
+# this script migrates primary traffic for the customer keyspace to the
+# new primary tablet
 
 source ./env.sh
 
-vtctlclient MoveTables -tablet_types=master SwitchTraffic customer.commerce2customer
+vtctlclient MoveTables -tablet_types=primary SwitchTraffic customer.commerce2customer
diff --git a/examples/local/305_switch_writes.sh b/examples/local/305_switch_writes.sh
index 2f9c5ad7aa..d4a674d0b6 100755
--- a/examples/local/305_switch_writes.sh
+++ b/examples/local/305_switch_writes.sh
@@ -14,8 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# this script migrates traffic for the master tablet
+# this script migrates traffic for the primary tablet
 
 source ./env.sh
 
-vtctlclient Reshard -tablet_types=master SwitchTraffic customer.cust2cust
+vtctlclient Reshard -tablet_types=primary SwitchTraffic customer.cust2cust
diff --git a/examples/local/scripts/vtgate-up.sh b/examples/local/scripts/vtgate-up.sh
index da04c8d164..35cc108d21 100755
--- a/examples/local/scripts/vtgate-up.sh
+++ b/examples/local/scripts/vtgate-up.sh
@@ -36,7 +36,7 @@ vtgate \
   -mysql_server_socket_path $mysql_server_socket_path \
   -cell $cell \
   -cells_to_watch $cell \
-  -tablet_types_to_wait MASTER,REPLICA \
+  -tablet_types_to_wait PRIMARY,REPLICA \
   -service_map 'grpc-vtgateservice' \
   -pid_file $VTDATAROOT/tmp/vtgate.pid \
   -mysql_auth_server_impl none \
diff --git a/examples/region_sharding/201_main_sharded.sh b/examples/region_sharding/201_main_sharded.sh
index 2b59971d9d..c4e45c5b3a 100755
--- a/examples/region_sharding/201_main_sharded.sh
+++ b/examples/region_sharding/201_main_sharded.sh
@@ -23,7 +23,7 @@ vtctlclient ApplyVSchema -vschema_file main_vschema_sharded.json main
 #vtctlclient ApplySchema -sql-file create_lookup_schema.sql main
 
 # create the lookup vindex
-vtctlclient CreateLookupVindex -tablet_types=MASTER main "$(cat lookup_vindex.json)"
+vtctlclient CreateLookupVindex -tablet_types=PRIMARY main "$(cat lookup_vindex.json)"
 
 # we have to wait for replication to catch up
 # Can see on vttablet status page Vreplication that copy is complete
diff --git a/examples/region_sharding/202_new_tablets.sh b/examples/region_sharding/202_new_tablets.sh
index 5e385ab622..296faee49b 100755
--- a/examples/region_sharding/202_new_tablets.sh
+++ b/examples/region_sharding/202_new_tablets.sh
@@ -16,7 +16,7 @@
 
 source ./env.sh
 
-# start vttablets for new shards. we start only one tablet each (master)
+# start vttablets for new shards. we start only one tablet each (primary)
 CELL=zone1 TABLET_UID=200 ./scripts/mysqlctl-up.sh
 SHARD=-40 CELL=zone1 KEYSPACE=main TABLET_UID=200 ./scripts/vttablet-up.sh
 CELL=zone1 TABLET_UID=300 ./scripts/mysqlctl-up.sh
@@ -26,7 +26,7 @@ SHARD=80-c0 CELL=zone1 KEYSPACE=main TABLET_UID=400 ./scripts/vttablet-up.sh
 CELL=zone1 TABLET_UID=500 ./scripts/mysqlctl-up.sh
 SHARD=c0- CELL=zone1 KEYSPACE=main TABLET_UID=500 ./scripts/vttablet-up.sh
 
-# set master
+# set primary
 vtctlclient InitShardMaster -force main/-40 zone1-200
 vtctlclient InitShardMaster -force main/40-80 zone1-300
 vtctlclient InitShardMaster -force main/80-c0 zone1-400
diff --git a/examples/region_sharding/203_reshard.sh b/examples/region_sharding/203_reshard.sh
index ce1a7f4558..554b5b796d 100755
--- a/examples/region_sharding/203_reshard.sh
+++ b/examples/region_sharding/203_reshard.sh
@@ -16,4 +16,4 @@
 
 source ./env.sh
 
-vtctlclient Reshard -v1 -tablet_types=MASTER main.main2regions '0' '-40,40-80,80-c0,c0-'
+vtctlclient Reshard -v1 -tablet_types=PRIMARY main.main2regions '0' '-40,40-80,80-c0,c0-'
diff --git a/examples/region_sharding/205_switch_writes.sh b/examples/region_sharding/205_switch_writes.sh
index a7f22f430c..87f052b9af 100755
--- a/examples/region_sharding/205_switch_writes.sh
+++ b/examples/region_sharding/205_switch_writes.sh
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# this script migrates traffic for the master tablet
+# this script migrates traffic for the primary tablet
 
 source ./env.sh
 
diff --git a/examples/region_sharding/scripts/vtgate-up.sh b/examples/region_sharding/scripts/vtgate-up.sh
index da04c8d164..35cc108d21 100755
--- a/examples/region_sharding/scripts/vtgate-up.sh
+++ b/examples/region_sharding/scripts/vtgate-up.sh
@@ -36,7 +36,7 @@ vtgate \
   -mysql_server_socket_path $mysql_server_socket_path \
   -cell $cell \
   -cells_to_watch $cell \
-  -tablet_types_to_wait MASTER,REPLICA \
+  -tablet_types_to_wait PRIMARY,REPLICA \
   -service_map 'grpc-vtgateservice' \
   -pid_file $VTDATAROOT/tmp/vtgate.pid \
   -mysql_auth_server_impl none \
diff --git a/go/vt/vtgate/planbuilder/horizon_planning.go b/go/vt/vtgate/planbuilder/horizon_planning.go
index ee871e4492..5f7f8d555d 100644
--- a/go/vt/vtgate/planbuilder/horizon_planning.go
+++ b/go/vt/vtgate/planbuilder/horizon_planning.go
@@ -600,11 +600,15 @@ func (hp *horizonPlanning) planDistinctOA(currPlan *orderedAggregate) error {
 
 func (hp *horizonPlanning) addDistinct() error {
 	eaggr := &engine.OrderedAggregate{}
-	var orderExprs []abstract.OrderBy
+	oa := &orderedAggregate{
+		resultsBuilder: resultsBuilder{
+			logicalPlanCommon: newBuilderCommon(hp.plan),
+			weightStrings:     make(map[*resultColumn]int),
+			truncater:         eaggr,
+		},
+		eaggr: eaggr,
+	}
 	for index, sExpr := range hp.qp.SelectExprs {
-		if isAmbiguousOrderBy(index, sExpr.Col.As, hp.qp.SelectExprs) {
-			return vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "generating order by clause: ambiguous symbol reference: %s", sqlparser.String(sExpr.Col.As))
-		}
 		grpParam := &engine.GroupByParams{KeyCol: index, WeightStringCol: -1}
 		_, wOffset, added, err := wrapAndPushExpr(sExpr.Col.Expr, sExpr.Col.Expr, hp.plan, hp.semTable)
 		if err != nil {
@@ -613,54 +617,11 @@ func (hp *horizonPlanning) addDistinct() error {
 		hp.needsTruncation = hp.needsTruncation || added
 		grpParam.WeightStringCol = wOffset
 		eaggr.GroupByKeys = append(eaggr.GroupByKeys, grpParam)
-
-		var inner sqlparser.Expr
-		if !sExpr.Col.As.IsEmpty() {
-			inner = sqlparser.NewColName(sExpr.Col.As.String())
-		} else {
-			inner = sExpr.Col.Expr
-		}
-		orderExprs = append(orderExprs, abstract.OrderBy{
-			Inner:         &sqlparser.Order{Expr: inner},
-			WeightStrExpr: sExpr.Col.Expr},
-		)
-	}
-	innerPlan, err := hp.planOrderBy(orderExprs, hp.plan)
-	if err != nil {
-		return err
-	}
-	hp.plan = &orderedAggregate{
-		resultsBuilder: resultsBuilder{
-			logicalPlanCommon: newBuilderCommon(innerPlan),
-			weightStrings:     make(map[*resultColumn]int),
-			truncater:         eaggr,
-		},
-		eaggr: eaggr,
 	}
+	hp.plan = oa
 	return nil
 }
 
-func isAmbiguousOrderBy(index int, col sqlparser.ColIdent, exprs []abstract.SelectExpr) bool {
-	if col.String() == "" {
-		return false
-	}
-	for i, expr := range exprs {
-		if i == index {
-			continue
-		}
-		alias := expr.Col.As
-		if alias.IsEmpty() {
-			if col, ok := expr.Col.Expr.(*sqlparser.ColName); ok {
-				alias = col.Name
-			}
-		}
-		if col.Equal(alias) {
-			return true
-		}
-	}
-	return false
-}
-
 func selectHasUniqueVindex(vschema ContextVSchema, semTable *semantics.SemTable, sel []abstract.SelectExpr) bool {
 	for _, expr := range sel {
 		if exprHasUniqueVindex(vschema, semTable, expr.Col.Expr) {


Test patch:
diff --git a/examples/local/orc_test.sh b/examples/local/orc_test.sh
index 0817a47077..8c3cb38d86 100755
--- a/examples/local/orc_test.sh
+++ b/examples/local/orc_test.sh
@@ -44,7 +44,7 @@ for i in 110 111; do
 	CELL=zone2 KEYSPACE=commerce TABLET_UID=$i ./scripts/ovttablet-up.sh
 done
 
-# set one of the replicas to master
+# set one of the replicas to primary
 #vtctlclient InitShardMaster -force commerce/0 zone1-100
 
 # create the schema
diff --git a/go/test/endtoend/vtgate/gen4/gen4_test.go b/go/test/endtoend/vtgate/gen4/gen4_test.go
index 566cfdcec6..3a7cbc20c6 100644
--- a/go/test/endtoend/vtgate/gen4/gen4_test.go
+++ b/go/test/endtoend/vtgate/gen4/gen4_test.go
@@ -142,22 +142,6 @@ func TestDistinctAggregationFunc(t *testing.T) {
 		`[[NULL INT64(2) DECIMAL(11)] [VARCHAR("A") INT64(2) DECIMAL(0)] [VARCHAR("AA") INT64(1) DECIMAL(4)] [VARCHAR("B") INT64(2) DECIMAL(0)] [VARCHAR("BB") INT64(3) DECIMAL(30)] [VARCHAR("C") INT64(1) DECIMAL(0)]]`)
 }
 
-func TestDistinct(t *testing.T) {
-	ctx := context.Background()
-	conn, err := mysql.Connect(ctx, &vtParams)
-	require.NoError(t, err)
-	defer conn.Close()
-
-	defer exec(t, conn, `delete from t2`)
-
-	// insert some data.
-	checkedExec(t, conn, `insert into t2(id, tcol1, tcol2) values (1, 'A', 'A'),(2, 'B', 'C'),(3, 'A', 'C'),(4, 'C', 'A'),(5, 'A', 'A'),(6, 'B', 'C'),(7, 'B', 'A'),(8, 'C', 'A')`)
-
-	// multi distinct
-	assertMatches(t, conn, `select distinct tcol1, tcol2 from t2`,
-		`[[VARCHAR("A") VARCHAR("A")] [VARCHAR("A") VARCHAR("C")] [VARCHAR("B") VARCHAR("A")] [VARCHAR("B") VARCHAR("C")] [VARCHAR("C") VARCHAR("A")]]`)
-}
-
 func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) {
 	t.Helper()
 	qr := checkedExec(t, conn, query)
diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
index 145db7ac5e..34de59996c 100644
--- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
@@ -791,8 +791,7 @@ Gen4 error: In aggregated query without GROUP BY, expression of SELECT list cont
           "Sharded": true
         },
         "FieldQuery": "select col, weight_string(col) from `user` where 1 != 1",
-        "OrderBy": "(0|1) ASC",
-        "Query": "select distinct col, weight_string(col) from `user` order by col asc",
+        "Query": "select distinct col, weight_string(col) from `user`",
         "Table": "`user`"
       }
     ]
@@ -2007,8 +2006,7 @@ Gen4 plan same as above
           "Sharded": true
         },
         "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1",
-        "OrderBy": "(0|2) ASC, (1|3) ASC",
-        "Query": "select distinct col1, col2, weight_string(col1), weight_string(col2) from `user` order by col1 asc, col2 asc",
+        "Query": "select distinct col1, col2, weight_string(col1), weight_string(col2) from `user`",
         "Table": "`user`"
       }
     ]
diff --git a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt
index 326496605d..6d7e40f2e6 100644
--- a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt
@@ -1737,152 +1737,16 @@ Gen4 error: In aggregated query without GROUP BY, expression of SELECT list cont
 "unsupported: memory sort: order by must reference a column in the select list: c1 asc"
 Gen4 error: Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column 'c1' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
 
-# Distinct with cross shard query
-"select distinct user.a from user join user_extra"
-{
-  "QueryType": "SELECT",
-  "Original": "select distinct user.a from user join user_extra",
-  "Instructions": {
-    "OperatorType": "Distinct",
-    "Inputs": [
-      {
-        "OperatorType": "Join",
-        "Variant": "Join",
-        "JoinColumnIndexes": "-1",
-        "TableName": "`user`_user_extra",
-        "Inputs": [
-          {
-            "OperatorType": "Route",
-            "Variant": "SelectScatter",
-            "Keyspace": {
-              "Name": "user",
-              "Sharded": true
-            },
-            "FieldQuery": "select `user`.a from `user` where 1 != 1",
-            "Query": "select `user`.a from `user`",
-            "Table": "`user`"
-          },
-          {
-            "OperatorType": "Route",
-            "Variant": "SelectScatter",
-            "Keyspace": {
-              "Name": "user",
-              "Sharded": true
-            },
-            "FieldQuery": "select 1 from user_extra where 1 != 1",
-            "Query": "select 1 from user_extra",
-            "Table": "user_extra"
-          }
-        ]
-      }
-    ]
-  }
-}
-{
-  "QueryType": "SELECT",
-  "Original": "select distinct user.a from user join user_extra",
-  "Instructions": {
-    "OperatorType": "Aggregate",
-    "Variant": "Ordered",
-    "GroupBy": "(0|1)",
-    "ResultColumns": 1,
-    "Inputs": [
-      {
-        "OperatorType": "Join",
-        "Variant": "Join",
-        "JoinColumnIndexes": "-1,-2",
-        "TableName": "`user`_user_extra",
-        "Inputs": [
-          {
-            "OperatorType": "Route",
-            "Variant": "SelectScatter",
-            "Keyspace": {
-              "Name": "user",
-              "Sharded": true
-            },
-            "FieldQuery": "select `user`.a, weight_string(`user`.a) from `user` where 1 != 1",
-            "OrderBy": "(0|1) ASC",
-            "Query": "select `user`.a, weight_string(`user`.a) from `user` order by `user`.a asc",
-            "Table": "`user`"
-          },
-          {
-            "OperatorType": "Route",
-            "Variant": "SelectScatter",
-            "Keyspace": {
-              "Name": "user",
-              "Sharded": true
-            },
-            "FieldQuery": "select 1 from user_extra where 1 != 1",
-            "Query": "select 1 from user_extra",
-            "Table": "user_extra"
-          }
-        ]
-      }
-    ]
-  }
-}
-
-# Distinct with column alias
-"select distinct a as c, a from user"
-{
-  "QueryType": "SELECT",
-  "Original": "select distinct a as c, a from user",
-  "Instructions": {
-    "OperatorType": "Aggregate",
-    "Variant": "Ordered",
-    "GroupBy": "0, 1",
-    "Inputs": [
-      {
-        "OperatorType": "Route",
-        "Variant": "SelectScatter",
-        "Keyspace": {
-          "Name": "user",
-          "Sharded": true
-        },
-        "FieldQuery": "select a as c, a, weight_string(a) from `user` where 1 != 1",
-        "OrderBy": "(0|2) ASC, (0|2) ASC",
-        "Query": "select distinct a as c, a, weight_string(a) from `user` order by c asc, a asc",
-        "ResultColumns": 2,
-        "Table": "`user`"
-      }
-    ]
-  }
-}
-{
-  "QueryType": "SELECT",
-  "Original": "select distinct a as c, a from user",
-  "Instructions": {
-    "OperatorType": "Aggregate",
-    "Variant": "Ordered",
-    "GroupBy": "(0|2), (1|2)",
-    "ResultColumns": 2,
-    "Inputs": [
-      {
-        "OperatorType": "Route",
-        "Variant": "SelectScatter",
-        "Keyspace": {
-          "Name": "user",
-          "Sharded": true
-        },
-        "FieldQuery": "select a as c, a, weight_string(a) from `user` where 1 != 1",
-        "OrderBy": "(0|2) ASC, (1|2) ASC",
-        "Query": "select distinct a as c, a, weight_string(a) from `user` order by c asc, a asc",
-        "Table": "`user`"
-      }
-    ]
-  }
-}
-
-# Distinct with same column
-"select distinct a, a from user"
+# scatter aggregate with ambiguous aliases
+"select distinct a, b as a from user"
 "generating order by clause: ambiguous symbol reference: a"
 {
   "QueryType": "SELECT",
-  "Original": "select distinct a, a from user",
+  "Original": "select distinct a, b as a from user",
   "Instructions": {
     "OperatorType": "Aggregate",
     "Variant": "Ordered",
-    "GroupBy": "(0|2), (1|2)",
+    "GroupBy": "(0|2), (1|4)",
     "ResultColumns": 2,
     "Inputs": [
       {
@@ -1892,9 +1756,8 @@ Gen4 error: Expression of SELECT list is not in GROUP BY clause and contains non
           "Name": "user",
           "Sharded": true
         },
-        "FieldQuery": "select a, a, weight_string(a) from `user` where 1 != 1",
-        "OrderBy": "(0|2) ASC, (0|2) ASC",
-        "Query": "select distinct a, a, weight_string(a) from `user` order by a asc, a asc",
+        "FieldQuery": "select a, b as a, weight_string(a), b, weight_string(b) from `user` where 1 != 1",
+        "Query": "select distinct a, b as a, weight_string(a), b, weight_string(b) from `user`",
         "Table": "`user`"
       }
     ]
diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.txt b/go/vt/vtgate/planbuilder/testdata/select_cases.txt
index f776c90c8e..612f729257 100644
--- a/go/vt/vtgate/planbuilder/testdata/select_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/select_cases.txt
@@ -1717,3 +1717,87 @@ Gen4 plan same as above
 # Into outfile s3 in sub-query is incorrect
 "select id from (select id from user into outfile s3 'inner_outfile') as t2"
 "Incorrect usage/placement of 'INTO'"
+
+# Distinct with cross shard query
+"select distinct user.a from user join user_extra"
+{
+  "QueryType": "SELECT",
+  "Original": "select distinct user.a from user join user_extra",
+  "Instructions": {
+    "OperatorType": "Distinct",
+    "Inputs": [
+      {
+        "OperatorType": "Join",
+        "Variant": "Join",
+        "JoinColumnIndexes": "-1",
+        "TableName": "`user`_user_extra",
+        "Inputs": [
+          {
+            "OperatorType": "Route",
+            "Variant": "SelectScatter",
+            "Keyspace": {
+              "Name": "user",
+              "Sharded": true
+            },
+            "FieldQuery": "select `user`.a from `user` where 1 != 1",
+            "Query": "select `user`.a from `user`",
+            "Table": "`user`"
+          },
+          {
+            "OperatorType": "Route",
+            "Variant": "SelectScatter",
+            "Keyspace": {
+              "Name": "user",
+              "Sharded": true
+            },
+            "FieldQuery": "select 1 from user_extra where 1 != 1",
+            "Query": "select 1 from user_extra",
+            "Table": "user_extra"
+          }
+        ]
+      }
+    ]
+  }
+}
+{
+  "QueryType": "SELECT",
+  "Original": "select distinct user.a from user join user_extra",
+  "Instructions": {
+    "OperatorType": "Aggregate",
+    "Variant": "Ordered",
+    "GroupBy": "(0|1)",
+    "ResultColumns": 1,
+    "Inputs": [
+      {
+        "OperatorType": "Join",
+        "Variant": "Join",
+        "JoinColumnIndexes": "-1,-2",
+        "TableName": "`user`_user_extra",
+        "Inputs": [
+          {
+            "OperatorType": "Route",
+            "Variant": "SelectScatter",
+            "Keyspace": {
+              "Name": "user",
+              "Sharded": true
+            },
+            "FieldQuery": "select `user`.a, weight_string(`user`.a) from `user` where 1 != 1",
+            "Query": "select `user`.a, weight_string(`user`.a) from `user`",
+            "Table": "`user`"
+          },
+          {
+            "OperatorType": "Route",
+            "Variant": "SelectScatter",
+            "Keyspace": {
+              "Name": "user",
+              "Sharded": true
+            },
+            "FieldQuery": "select 1 from user_extra where 1 != 1",
+            "Query": "select 1 from user_extra",
+            "Table": "user_extra"
+          }
+        ]
+      }
+    ]
+  }
+}
diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
index c981f786ed..94cc9f27af 100644
--- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
@@ -483,8 +483,3 @@ Gen4 error: In aggregated query without GROUP BY, expression of SELECT list cont
 "select avg(id) from user"
 "unsupported: in scatter query: complex aggregate expression"
 Gen4 plan same as above
-
-# scatter aggregate with ambiguous aliases
-"select distinct a, b as a from user"
-"generating order by clause: ambiguous symbol reference: a"
-Gen4 plan same as above