Skip to content

Commit

Permalink
Merge pull request #8947 from planetscale/gen4-distinct-subquery
Browse files Browse the repository at this point in the history
Gen4: add support for distinct on pullout subquery plan
  • Loading branch information
harshit-gangal authored Oct 7, 2021
2 parents d9aac11 + 4c05110 commit 4d0436a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
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`"
}
]
}
]
}
}

0 comments on commit 4d0436a

Please sign in to comment.