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

opt: AssociateJoin should push down transitive equalities #36226

Closed
justinj opened this issue Mar 27, 2019 · 2 comments · Fixed by #41250
Closed

opt: AssociateJoin should push down transitive equalities #36226

justinj opened this issue Mar 27, 2019 · 2 comments · Fixed by #41250
Assignees
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@justinj
Copy link
Contributor

justinj commented Mar 27, 2019

Consider this schema+query:

exec-ddl
CREATE TABLE parent1 (pid1 INT PRIMARY KEY, pa1 INT)
----

exec-ddl
CREATE TABLE child1 (
  pid1 INT,
  cid1 INT,
  ca1 INT,
  PRIMARY KEY(pid1, cid1)
)
INTERLEAVE IN PARENT parent1 (pid1)
----

exec-ddl
CREATE TABLE grandchild1 (
  pid1 INT,
  cid1 INT,
  gcid1 INT,
  gca1 INT,
  PRIMARY KEY(pid1, cid1, gcid1)
)
INTERLEAVE IN PARENT child1 (pid1, cid1)
----

memo join-limit=4
SELECT * FROM grandchild1
JOIN child1 USING (pid1, cid1)
JOIN parent1 USING (pid1)
ORDER BY pid1
----

There's a transitive equality which in theory should get pushed down, but since the rule that generates those is a norm rule, it doesn't get applied to the expression generated by AssociateJoin, and we end up with a cross join where we shouldn't.

@justinj justinj added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-sql-optimizer SQL logical planning and optimizations. labels Mar 27, 2019
@justinj justinj self-assigned this Mar 27, 2019
@RaduBerinde RaduBerinde assigned rytaft and unassigned justinj Oct 2, 2019
@RaduBerinde
Copy link
Member

@rytaft this is the same as #38716 - can you confirm that #41250 fixes the case in this issue as well? (maybe add it as a test)

@rytaft
Copy link
Collaborator

rytaft commented Oct 7, 2019

Added as a test - thanks!

@craig craig bot closed this as completed in 53ae9e5 Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants