Skip to content

Commit 7673484

Browse files
committed
Set parsed comments in operator for subqueries (vitessio#18369)
Signed-off-by: David Piegza <[email protected]>
1 parent 3e8aa8f commit 7673484

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

go/vt/vtgate/planbuilder/operators/subquery_planning.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ func tryMergeSubqueryWithOuter(ctx *plancontext.PlanningContext, subQuery *SubQu
514514
if !subQuery.IsArgument {
515515
op.Source = newFilter(outer.Source, subQuery.Original)
516516
}
517+
if outer.Comments != nil {
518+
op.Comments = outer.Comments
519+
}
517520
ctx.MergedSubqueries = append(ctx.MergedSubqueries, subQuery.originalSubquery)
518521
return op, Rewrote("merged subquery with outer")
519522
}

go/vt/vtgate/planbuilder/testdata/select_cases.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,72 @@
876876
]
877877
}
878878
},
879+
{
880+
"comment": "Comments with subquery",
881+
"query": "select /* comment */ user.col from user where id IN (select id from user where id > 1 and id < 10)",
882+
"plan": {
883+
"Type": "Scatter",
884+
"QueryType": "SELECT",
885+
"Original": "select /* comment */ user.col from user where id IN (select id from user where id > 1 and id < 10)",
886+
"Instructions": {
887+
"OperatorType": "Route",
888+
"Variant": "Scatter",
889+
"Keyspace": {
890+
"Name": "user",
891+
"Sharded": true
892+
},
893+
"FieldQuery": "select `user`.col from `user` where 1 != 1",
894+
"Query": "select /* comment */ `user`.col from `user` where id in (select id from `user` where id > 1 and id < 10)"
895+
},
896+
"TablesUsed": [
897+
"user.user"
898+
]
899+
}
900+
},
901+
{
902+
"comment": "Comments with subquery not merged into a single route",
903+
"query": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
904+
"plan": {
905+
"Type": "Complex",
906+
"QueryType": "SELECT",
907+
"Original": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
908+
"Instructions": {
909+
"OperatorType": "UncorrelatedSubquery",
910+
"Variant": "PulloutIn",
911+
"PulloutVars": [
912+
"__sq_has_values",
913+
"__sq1"
914+
],
915+
"Inputs": [
916+
{
917+
"InputName": "SubQuery",
918+
"OperatorType": "Route",
919+
"Variant": "Scatter",
920+
"Keyspace": {
921+
"Name": "user",
922+
"Sharded": true
923+
},
924+
"FieldQuery": "select id from `user` where 1 != 1",
925+
"Query": "select /* comment */ id from `user` where id > 1 and id < 10"
926+
},
927+
{
928+
"InputName": "Outer",
929+
"OperatorType": "Route",
930+
"Variant": "Scatter",
931+
"Keyspace": {
932+
"Name": "user",
933+
"Sharded": true
934+
},
935+
"FieldQuery": "select `user`.col from `user` where 1 != 1",
936+
"Query": "select /* comment */ `user`.col from `user` where :__sq_has_values and foo in ::__sq1"
937+
}
938+
]
939+
},
940+
"TablesUsed": [
941+
"user.user"
942+
]
943+
}
944+
},
879945
{
880946
"comment": "for update",
881947
"query": "select user.col from user join user_extra for update",

0 commit comments

Comments
 (0)