Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/select_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,28 @@
]
}
},
{
"comment": "qualified star after join using keeps the join column",
"query": "select b.* from authoritative a join authoritative b using (user_id)",
"plan": {
"Type": "Scatter",
"QueryType": "SELECT",
"Original": "select b.* from authoritative a join authoritative b using (user_id)",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select b.user_id, b.col1, b.col2 from authoritative as a, authoritative as b where 1 != 1",
"Query": "select b.user_id, b.col1, b.col2 from authoritative as a, authoritative as b where a.user_id = b.user_id"
},
"TablesUsed": [
"user.authoritative"
]
}
},
{
"comment": "select * from authoritative table",
"query": "select * from authoritative",
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/semantics/early_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,11 @@ func (r *earlyRewriter) expandTableColumns(
org: org,
expandedColumns: map[sqlparser.TableName][]*sqlparser.ColName{},
}
if !starExpr.TableName.IsEmpty() {
// USING coalescing applies to an unqualified * only: a qualified star
// returns every column of its table, join columns included
state.joinUsing = nil
}

for _, tbl := range tables {
if !starExpr.TableName.IsEmpty() && !tbl.matches(starExpr.TableName) {
Expand Down
14 changes: 14 additions & 0 deletions go/vt/vtgate/semantics/early_rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ func TestExpandStar(t *testing.T) {
}, {
sql: "select 1 from t1 join t5 using (b) where b = 12",
expSQL: "select 1 from t1 join t5 on t1.b = t5.b where t1.b = 12",
}, {
// USING coalescing applies to an unqualified * only: a qualified star
// returns every column of its table, join columns included
sql: "select t2.* from t2 join t4 using (c1)",
expSQL: "select t2.c1, t2.c2 from t2 join t4 on t2.c1 = t4.c1",
}, {
sql: "select t4.* from t2 join t4 using (c1)",
expSQL: "select t4.c1, t4.c4 from t2 join t4 on t2.c1 = t4.c1",
}, {
sql: "select t2.*, t4.* from t2 join t4 using (c1)",
expSQL: "select t2.c1, t2.c2, t4.c1, t4.c4 from t2 join t4 on t2.c1 = t4.c1",
}, {
sql: "select t1.*, t5.* from t1 join t5 using (b)",
expSQL: "select t1.a, t1.b, t1.c, t5.a, t5.b from t1 join t5 on t1.b = t5.b",
}, {
sql: "select * from (select 12) as t",
expSQL: "select `12` from (select 12 from dual) as t",
Expand Down
Loading