-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Join with WHERE clause targeting single shard across joined tables treated as cross-shard #5742
Labels
Component: Query Serving
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Comments
sougou
changed the title
Left join with WHERE clause targeting single shard across joined tables treated as cross-shard
Join with WHERE clause targeting single shard across joined tables treated as cross-shard
Jan 31, 2020
I've updated the title and description because this is a normal join issue (not left join). The issue is still valid. As of #5551, we detect more single-shard left-join constructs. |
harshit-gangal
added
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Component: Query Serving
labels
Oct 30, 2020
This has been added Gen4 in #8569. The planner outputs for this query are as follows - {
"QueryType": "SELECT",
"Original": "select distinct t1.id from t1 inner join t2 on t1.id = t2.t1_id where t1.merchant_id = 1 and t2.merchant_id = 1",
"Instructions": {
"OperatorType": "Distinct",
"Inputs": [
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1",
"JoinVars": {
"t1_id": 0
},
"TableName": "t1_t2",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "SelectEqualUnique",
"Keyspace": {
"Name": "ks1",
"Sharded": true
},
"FieldQuery": "select t1.id from t1 where 1 != 1",
"Query": "select t1.id from t1 where t1.merchant_id = 1",
"Table": "t1",
"Values": [
1
],
"Vindex": "hash"
},
{
"OperatorType": "Route",
"Variant": "SelectEqualUnique",
"Keyspace": {
"Name": "ks1",
"Sharded": true
},
"FieldQuery": "select 1 from t2 where 1 != 1",
"Query": "select 1 from t2 where t2.t1_id = :t1_id and t2.merchant_id = 1",
"Table": "t2",
"Values": [
1
],
"Vindex": "hash"
}
]
}
]
}
} Gen4 - {
"QueryType": "SELECT",
"Original": "select distinct t1.id from t1 inner join t2 on t1.id = t2.t1_id where t1.merchant_id = 1 and t2.merchant_id = 1",
"Instructions": {
"OperatorType": "Route",
"Variant": "SelectEqualUnique",
"Keyspace": {
"Name": "ks1",
"Sharded": true
},
"FieldQuery": "select t1.id from t1, t2 where 1 != 1",
"Query": "select distinct t1.id from t1, t2 where t1.merchant_id = 1 and t2.merchant_id = 1 and t1.id = t2.t1_id",
"Table": "t1, t2",
"Values": [
1
],
"Vindex": "hash"
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Component: Query Serving
Type: Enhancement
Logical improvement (somewhere between a bug and feature)
Scenario:
SQL schema:
vSchema:
The following join query with an aggregate does not work, even though it's obviously targeting a single shard with the compound WHERE clause that covers both the joined tables:
If you add the merchant_id equality to the ON clause of the join, it works as expected:
Vitess should be able to recognize these are equivalent. In fact, the MySQL parser normalizes these queries to exactly the same query (if you EXPLAIN the query and do show warnings):
The text was updated successfully, but these errors were encountered: