Skip to content

Commit ccbf2ed

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

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

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

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

0 commit comments

Comments
 (0)