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

Gen4: add support for distinct on pullout subquery plan #8947

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/horizon_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ func (hp *horizonPlanning) planDistinct(ctx *planningContext, plan logicalPlan)
}

return hp.addDistinct(ctx, plan)
case *joinGen4:
case *joinGen4, *pulloutSubquery:
return hp.addDistinct(ctx, plan)
case *orderedAggregate:
return hp.planDistinctOA(p)
Expand Down
81 changes: 81 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3187,3 +3187,84 @@ Gen4 plan same as above
]
}
}

#subquery on other table
"select distinct user.id, user.col from user where user.col in (select id from music where col2 = 'a')"
{
"QueryType": "SELECT",
"Original": "select distinct user.id, user.col from user where user.col in (select id from music where col2 = 'a')",
"Instructions": {
"OperatorType": "Distinct",
"Inputs": [
{
"OperatorType": "Subquery",
"Variant": "PulloutIn",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id from music where 1 != 1",
"Query": "select id from music where col2 = 'a'",
"Table": "music"
},
{
"OperatorType": "Route",
"Variant": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.id, `user`.col from `user` where 1 != 1",
"Query": "select `user`.id, `user`.col from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1",
"Table": "`user`"
}
]
}
]
}
}
{
"QueryType": "SELECT",
"Original": "select distinct user.id, user.col from user where user.col in (select id from music where col2 = 'a')",
"Instructions": {
"OperatorType": "Aggregate",
"Variant": "Ordered",
"GroupBy": "(0|2), (1|3)",
"ResultColumns": 2,
"Inputs": [
{
"OperatorType": "Subquery",
"Variant": "PulloutIn",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id from music where 1 != 1",
"Query": "select id from music where col2 = 'a'",
"Table": "music"
},
{
"OperatorType": "Route",
"Variant": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select `user`.id, `user`.col, weight_string(`user`.id), weight_string(`user`.col) from `user` where 1 != 1",
"OrderBy": "(0|2) ASC, (1|3) ASC",
"Query": "select `user`.id, `user`.col, weight_string(`user`.id), weight_string(`user`.col) from `user` where :__sq_has_values1 = 1 and `user`.col in ::__sq1 order by `user`.id asc, `user`.col asc",
"Table": "`user`"
}
]
}
]
}
}