Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't forget DISTINCT for derived tables #15672

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/operators/SQL_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ func buildDerivedSelect(op *Horizon, qb *queryBuilder, sel *sqlparser.Select) {
sel.GroupBy = opQuery.GroupBy
sel.Having = mergeHaving(sel.Having, opQuery.Having)
sel.SelectExprs = opQuery.SelectExprs
sel.Distinct = opQuery.Distinct
qb.addTableExpr(op.Alias, op.Alias, TableID(op), &sqlparser.DerivedTable{
Select: sel,
}, nil, op.ColumnAliases)
Expand Down
22 changes: 22 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/from_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,28 @@
]
}
},
{
"comment": "DISTINCT inside derived table",
"query": "select * from (select distinct name from user) as t",
"plan": {
"QueryType": "SELECT",
"Original": "select * from (select distinct name from user) as t",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `name` from (select `name` from `user` where 1 != 1) as t where 1 != 1",
"Query": "select `name` from (select distinct `name` from `user`) as t",
"Table": "`user`"
},
"TablesUsed": [
"user.user"
]
}
},
{
"comment": "',' join unsharded",
"query": "select u1.a, u2.a from unsharded u1, unsharded u2",
Expand Down
Loading