Skip to content

Commit f828b54

Browse files
davidpiegzamhamza15
authored andcommitted
Set parsed comments in operator for subqueries (vitessio#18369)
Signed-off-by: David Piegza <[email protected]>
1 parent 36832b1 commit f828b54

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,74 @@
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+
"skip_e2e": true
901+
},
902+
{
903+
"comment": "Comments with subquery not merged into a single route",
904+
"query": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
905+
"plan": {
906+
"Type": "Complex",
907+
"QueryType": "SELECT",
908+
"Original": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
909+
"Instructions": {
910+
"OperatorType": "UncorrelatedSubquery",
911+
"Variant": "PulloutIn",
912+
"PulloutVars": [
913+
"__sq_has_values",
914+
"__sq1"
915+
],
916+
"Inputs": [
917+
{
918+
"InputName": "SubQuery",
919+
"OperatorType": "Route",
920+
"Variant": "Scatter",
921+
"Keyspace": {
922+
"Name": "user",
923+
"Sharded": true
924+
},
925+
"FieldQuery": "select id from `user` where 1 != 1",
926+
"Query": "select /* comment */ id from `user` where id > 1 and id < 10"
927+
},
928+
{
929+
"InputName": "Outer",
930+
"OperatorType": "Route",
931+
"Variant": "Scatter",
932+
"Keyspace": {
933+
"Name": "user",
934+
"Sharded": true
935+
},
936+
"FieldQuery": "select `user`.col from `user` where 1 != 1",
937+
"Query": "select /* comment */ `user`.col from `user` where :__sq_has_values and foo in ::__sq1"
938+
}
939+
]
940+
},
941+
"TablesUsed": [
942+
"user.user"
943+
]
944+
},
945+
"skip_e2e": true
946+
},
879947
{
880948
"comment": "for update",
881949
"query": "select user.col from user join user_extra for update",

0 commit comments

Comments
 (0)