Skip to content

Commit

Permalink
fix: remove keyspace when merging subqueries (#16019)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
vitess-bot[bot] committed May 29, 2024
1 parent 6bfdccf commit 5480dd1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/operators/subquery_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func tryMergeSubqueryWithOuter(ctx *plancontext.PlanningContext, subQuery *SubQu
return outer, NoRewrite
}
exprs := subQuery.GetMergePredicates()
sqlparser.RemoveKeyspace(subQuery.Original)
merger := &subqueryRouteMerger{
outer: outer,
original: subQuery.Original,
Expand Down
23 changes: 23 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,29 @@
]
}
},
{
"comment": "Merging subqueries should remove keyspace from query",
"query": "select u.id from user.user as u where not exists (select 1 from user.user_extra as ue where u.id = ue.user_id)",
"plan": {
"QueryType": "SELECT",
"Original": "select u.id from user.user as u where not exists (select 1 from user.user_extra as ue where u.id = ue.user_id)",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select u.id from `user` as u where 1 != 1",
"Query": "select u.id from `user` as u where not exists (select 1 from user_extra as ue where u.id = ue.user_id)",
"Table": "`user`"
},
"TablesUsed": [
"user.user",
"user.user_extra"
]
}
},
{
"comment": "Single table equality route with unsigned value",
"query": "select id from user where name = 18446744073709551615",
Expand Down

0 comments on commit 5480dd1

Please sign in to comment.