Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify merging logic #16525

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions .github/workflows/vitess_tester_vtgate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
end_to_end:
- 'go/**/*.go'
- 'go/vt/sidecardb/**/*.sql'
- 'go/test/endtoend/vtgate/vitess_tester/**'
- 'go/test/endtoend/onlineddl/vrepl_suite/**'
- 'test.go'
- 'Makefile'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ insert into corder.corder(order_id, customer_id, sku, price) values(4, 4, 'SKU-1
insert into corder.corder(order_id, customer_id, sku, price) values(5, 5, 'SKU-1002', 30);

select co.order_id, co.customer_id, co.price from corder.corder co left join customer.customer cu on co.customer_id=cu.customer_id where cu.customer_id=1;

# This query was accidentally disallowed by https://github.com/vitessio/vitess/pull/16520
select 1 from customer.customer where id in (select customer_id from corder.corder where price > 50);
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/join_merging.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func mergeJoinInputs(ctx *plancontext.PlanningContext, lhs, rhs Operator, joinPr

// sharded routing is complex, so we handle it in a separate method
case a == sharded && b == sharded:
return tryMergeShardedRouting(ctx, lhsRoute, rhsRoute, m, joinPredicates, false /*isSubquery*/)
return tryMergeShardedRouting(ctx, lhsRoute, rhsRoute, m, joinPredicates)

default:
return nil
Expand Down
13 changes: 3 additions & 10 deletions go/vt/vtgate/planbuilder/operators/sharded_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/slice"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/engine"
"vitess.io/vitess/go/vt/vtgate/evalengine"
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
Expand Down Expand Up @@ -639,9 +638,10 @@ func tryMergeShardedRouting(
routeA, routeB *Route,
m merger,
joinPredicates []sqlparser.Expr,
isSubquery bool,
) *Route {
sameKeyspace := routeA.Routing.Keyspace() == routeB.Routing.Keyspace()
if routeA.Routing.Keyspace() != routeB.Routing.Keyspace() {
return nil
}
tblA := routeA.Routing.(*ShardedRouting)
tblB := routeB.Routing.(*ShardedRouting)

Expand Down Expand Up @@ -670,13 +670,6 @@ func tryMergeShardedRouting(
return nil
}

if !sameKeyspace {
if isSubquery {
panic(vterrors.VT12001("cross-shard correlated subquery"))
}
return nil
}

canMerge := canMergeOnFilters(ctx, routeA, routeB, joinPredicates)
if !canMerge {
return nil
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/subquery_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ func mergeSubqueryInputs(ctx *plancontext.PlanningContext, in, out Operator, joi

// sharded routing is complex, so we handle it in a separate method
case inner == sharded && outer == sharded:
return tryMergeShardedRouting(ctx, inRoute, outRoute, m, joinPredicates, true /*isSubquery*/)
return tryMergeShardedRouting(ctx, inRoute, outRoute, m, joinPredicates)

default:
return nil
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/testdata/unsupported_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@
},
{
"comment": "Cross keyspace query with subquery",
"query": "select 1 from user where id in (select id from t1)",
"plan": "VT12001: unsupported: cross-shard correlated subquery"
"query": "select 1 from user where id = (select id from t1 where user.foo = t1.bar)",
"plan": "VT12001: unsupported: correlated subquery is only supported for EXISTS"
},
{
"comment": "multi-shard union",
Expand Down
1 change: 1 addition & 0 deletions test/templates/cluster_vitess_tester.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
end_to_end:
- 'go/**/*.go'
- 'go/vt/sidecardb/**/*.sql'
- 'go/test/endtoend/vtgate/vitess_tester/**'
- 'go/test/endtoend/onlineddl/vrepl_suite/**'
systay marked this conversation as resolved.
Show resolved Hide resolved
- 'test.go'
- 'Makefile'
Expand Down
Loading