Skip to content

Commit efae039

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

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
@@ -551,6 +551,9 @@ func tryMergeSubqueryWithOuter(ctx *plancontext.PlanningContext, subQuery *SubQu
551551
if !subQuery.IsArgument {
552552
op.Source = newFilter(outer.Source, subQuery.Original)
553553
}
554+
if outer.Comments != nil {
555+
op.Comments = outer.Comments
556+
}
554557
ctx.MergedSubqueries = append(ctx.MergedSubqueries, subQuery.originalSubquery)
555558
return op, Rewrote("merged subquery with outer")
556559
}

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,74 @@
941941
},
942942
"skip_e2e": true
943943
},
944+
{
945+
"comment": "Comments with subquery",
946+
"query": "select /* comment */ user.col from user where id IN (select id from user where id > 1 and id < 10)",
947+
"plan": {
948+
"Type": "Scatter",
949+
"QueryType": "SELECT",
950+
"Original": "select /* comment */ user.col from user where id IN (select id from user where id > 1 and id < 10)",
951+
"Instructions": {
952+
"OperatorType": "Route",
953+
"Variant": "Scatter",
954+
"Keyspace": {
955+
"Name": "user",
956+
"Sharded": true
957+
},
958+
"FieldQuery": "select `user`.col from `user` where 1 != 1",
959+
"Query": "select /* comment */ `user`.col from `user` where id in (select id from `user` where id > 1 and id < 10)"
960+
},
961+
"TablesUsed": [
962+
"user.user"
963+
]
964+
},
965+
"skip_e2e": true
966+
},
967+
{
968+
"comment": "Comments with subquery not merged into a single route",
969+
"query": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
970+
"plan": {
971+
"Type": "Complex",
972+
"QueryType": "SELECT",
973+
"Original": "select /* comment */ user.col from user where foo IN (select id from user where id > 1 and id < 10)",
974+
"Instructions": {
975+
"OperatorType": "UncorrelatedSubquery",
976+
"Variant": "PulloutIn",
977+
"PulloutVars": [
978+
"__sq_has_values",
979+
"__sq1"
980+
],
981+
"Inputs": [
982+
{
983+
"InputName": "SubQuery",
984+
"OperatorType": "Route",
985+
"Variant": "Scatter",
986+
"Keyspace": {
987+
"Name": "user",
988+
"Sharded": true
989+
},
990+
"FieldQuery": "select id from `user` where 1 != 1",
991+
"Query": "select /* comment */ id from `user` where id > 1 and id < 10"
992+
},
993+
{
994+
"InputName": "Outer",
995+
"OperatorType": "Route",
996+
"Variant": "Scatter",
997+
"Keyspace": {
998+
"Name": "user",
999+
"Sharded": true
1000+
},
1001+
"FieldQuery": "select `user`.col from `user` where 1 != 1",
1002+
"Query": "select /* comment */ `user`.col from `user` where :__sq_has_values and foo in ::__sq1"
1003+
}
1004+
]
1005+
},
1006+
"TablesUsed": [
1007+
"user.user"
1008+
]
1009+
},
1010+
"skip_e2e": true
1011+
},
9441012
{
9451013
"comment": "for update",
9461014
"query": "select user.col from user join user_extra for update",

0 commit comments

Comments
 (0)