Skip to content
Merged
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 @@ -514,6 +514,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 @@ -876,6 +876,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skip_e2e attribute does not exist on v21 yet, so you might have to remove this here and in the other test case. This is causing the unit test failure:

        --- FAIL: TestPlanTestSuite/TestPlan/select_cases.json (0.00s)
panic: json: unknown field "skip_e2e" [recovered]
	panic: json: unknown field "skip_e2e"

goroutine 1042 [running]:
testing.tRunner.func1.2({0x16b53c0, 0xc00074a6f0})
	/opt/hostedtoolcache/go/1.22.12/x64/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.22.12/x64/src/testing/testing.go:1634 +0x377
panic({0x16b53c0?, 0xc00074a6f0?})
	/opt/hostedtoolcache/go/1.22.12/x64/src/runtime/panic.go:770 +0x132
vitess.io/vitess/go/vt/vtgate/planbuilder.readJSONTests({0x18f7525, 0x11})
	/home/runner/work/vitess-gh/vitess-gh/go/vt/vtgate/planbuilder/plan_test.go:724 +0xf0
vitess.io/vitess/go/vt/vtgate/planbuilder.(*planTestSuite).testFile.func1(0xc0007731e0)
	/home/runner/work/vitess-gh/vitess-gh/go/vt/vtgate/planbuilder/plan_test.go:658 +0x8d
testing.tRunner(0xc0007731e0, 0xc000760200)
	/opt/hostedtoolcache/go/1.22.12/x64/src/testing/testing.go:1689 +0xfb
created by testing.(*T).Run in goroutine 250
	/opt/hostedtoolcache/go/1.22.12/x64/src/testing/testing.go:1742 +0x390
FAIL	vitess.io/vitess/go/vt/vtgate/planbuilder	1.095s

},
{
"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