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

Make merge_join pushdown safe #1689

Merged
merged 4 commits into from
Apr 4, 2023
Merged

Make merge_join pushdown safe #1689

merged 4 commits into from
Apr 4, 2023

Conversation

max-hoffman
Copy link
Contributor

Index lookups were being pushed into merge join:

tmp1> explain select /*+ merge_join(xyz,uv) join_order(xy,uv) */ * from xyz join uv on x = u where y = 1;
+--------------------------------+
| plan                           |
+--------------------------------+
| MergeJoin                      |
|  ├─ cmp: (xyz.x = uv.u)        |
|  ├─ IndexedTableAccess(xyz)    |
|  │   ├─ index: [xyz.y]         |
|  │   ├─ filters: [{[1, 1]}]    |
|  │   └─ columns: [x y z]       |
|  └─ IndexedTableAccess(uv)     |
|      ├─ index: [uv.u]          |
|      ├─ filters: [{[NULL, ∞)}] |
|      └─ columns: [u v]         |
+--------------------------------+

In rare cases like above, this pushes an unsafe index into merge join that is not sorted monotonically on the join condition. A merge join index that violates join condition monotonicity will miss matches. In even rarer cases, the out of order value for the join condition included NULLs, causing this error: dolthub/dolt#5633.

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@max-hoffman max-hoffman merged commit 6740be6 into main Apr 4, 2023
@max-hoffman max-hoffman deleted the max/merge-pushdown-filter branch April 4, 2023 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants