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

Multiple left joins with aggregation and unique vindexes can't route plan #4772

Closed
dweitzman opened this issue Apr 1, 2019 · 1 comment · Fixed by #5551
Closed

Multiple left joins with aggregation and unique vindexes can't route plan #4772

dweitzman opened this issue Apr 1, 2019 · 1 comment · Fixed by #5551
Labels
Type: Enhancement Logical improvement (somewhere between a bug and feature)

Comments

@dweitzman
Copy link
Member

I'm going to mail a PR that adds this test case documenting the limitation. Not sure what it would take to fix it. Query planning would succeed if one of the left joins were removed:

# Multi-table unique vindex constraint on left table of left join, two levels of join, simple aggregation
# This should work, but doesn't. If you remove the join with ue2 this works, but for some reason when
# there are two levels of left join instead of just one the query planner fails to realize that all these
# rows must belong to the same shard.
"select user.id, count(*) from user left join user_extra ue1 on user.id = ue1.user_id left join user_extra ue2 on ue1.user_id = ue2.user_id group by user.id"
"unsupported: cross-shard query with aggregates"
@dweitzman
Copy link
Member Author

There's a workaround, incidentally, which is adding "and user.id = ue2.user_id" to the second "on" clause. That should be implied from user.id = ue1.user_id && ue1.user_id = ue2._user_id, though, since both of those use unique vindexes.

dweitzman added a commit to dweitzman/vitess that referenced this issue Apr 1, 2019
…unsupported_cases.txt

vitessio#4772

Signed-off-by: David Weitzman <dweitzman@pinterest.com>
@morgo morgo added the Type: Enhancement Logical improvement (somewhere between a bug and feature) label Nov 4, 2019
sougou added a commit to planetscale/vitess that referenced this issue Dec 12, 2019
Fixes vitessio#4772
Fixes vitessio#5508

Previously, vitess was conservative about using vindexes for tables
involving left joins. After some reasoning, we've determined that it's
actually safe (and more efficient) to use them.

In existing functionality, a reference table had to be on the RHS
of the analysis. There was no benefit if it was on the LHS. When
we changed dual to be a Reference tables, it caused a regression.
If dual was on the LHS of a join or subquery, then it would get
treated as cross-shard. The new change handles the case of ref
tables to be on the LHS. This also fixes the regression.

Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants