Skip to content

Set parsed comments in operator for subqueries (#18369) #177

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

Open
wants to merge 4 commits into
base: release-21.0-github
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions go/vt/vtgate/planbuilder/operators/subquery_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ func tryMergeSubqueryWithOuter(ctx *plancontext.PlanningContext, subQuery *SubQu
if !subQuery.IsArgument {
op.Source = newFilter(outer.Source, subQuery.Original)
}
if outer.Comments != nil {
op.Comments = outer.Comments
}
ctx.MergedSubqueries = append(ctx.MergedSubqueries, subQuery.originalSubquery)
return op, Rewrote("merged subquery with outer")
}
Expand Down
68 changes: 68 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/select_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,74 @@
]
}
},
{
"comment": "Comments with subquery",
"query": "select /* comment */ user.col from user where id IN (select id from user where id > 1 and id < 10)",
"plan": {
"Type": "Scatter",
"QueryType": "SELECT",
"Original": "select /* comment */ user.col from user where id IN (select id from user where id > 1 and id < 10)",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.col from `user` where 1 != 1",
"Query": "select /* comment */ `user`.col from `user` where id in (select id from `user` where id > 1 and id < 10)"
},
"TablesUsed": [
"user.user"
]
},
"skip_e2e": true
},
{
"comment": "Comments with subquery not merged into a single route",
"query": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
"plan": {
"Type": "Complex",
"QueryType": "SELECT",
"Original": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
"Instructions": {
"OperatorType": "UncorrelatedSubquery",
"Variant": "PulloutIn",
"PulloutVars": [
"__sq_has_values",
"__sq1"
],
"Inputs": [
{
"InputName": "SubQuery",
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id from `user` where 1 != 1",
"Query": "select /* comment */ id from `user` where id > 1 and id < 10"
},
{
"InputName": "Outer",
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.col from `user` where 1 != 1",
"Query": "select /* comment */ `user`.col from `user` where :__sq_has_values and foo in ::__sq1"
}
]
},
"TablesUsed": [
"user.user"
]
},
"skip_e2e": true
},
{
"comment": "for update",
"query": "select user.col from user join user_extra for update",
Expand Down
Loading