Skip to content

Commit

Permalink
[release-19.0] fix: don't forget DISTINCT for derived tables (#15672) (
Browse files Browse the repository at this point in the history
…#15678)

Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
  • Loading branch information
vitess-bot[bot] authored Apr 8, 2024
1 parent fa7bc18 commit 22e7d15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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 @@ -612,6 +612,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

0 comments on commit 22e7d15

Please sign in to comment.