Skip to content

Conversation

@nuno-faria
Copy link
Contributor

@nuno-faria nuno-faria commented Jan 20, 2026

Which issue does this PR close?

Rationale for this change

Reduce the number of rows retrieved by pushing down more filters when possible. Example:

create table t1 (k int, v int);
create table t2 (k int, v int);

-- k=1 is pushed to t1 and t2
explain select * from t1 left join t2 on t1.k = t2.k where t1.k = 1;
+---------------+------------------------------------------------------------+
| plan_type     | plan                                                       |
+---------------+------------------------------------------------------------+
| physical_plan | ┌───────────────────────────┐                              |
|               | │        HashJoinExec       │                              |
|               | │    --------------------   │                              |
|               | │      join_type: Left      ├──────────────┐               |
|               | │        on: (k = k)        │              │               |
|               | └─────────────┬─────────────┘              │               |
|               | ┌─────────────┴─────────────┐┌─────────────┴─────────────┐ |
|               | │      RepartitionExec      ││      RepartitionExec      │ |
|               | │    --------------------   ││    --------------------   │ |
|               | │ partition_count(in->out): ││ partition_count(in->out): │ |
|               | │          1 -> 12          ││          1 -> 12          │ |
|               | │                           ││                           │ |
|               | │    partitioning_scheme:   ││    partitioning_scheme:   │ |
|               | │      Hash([k@0], 12)      ││      Hash([k@0], 12)      │ |
|               | └─────────────┬─────────────┘└─────────────┬─────────────┘ |
|               | ┌─────────────┴─────────────┐┌─────────────┴─────────────┐ |
|               | │         FilterExec        ││         FilterExec        │ |
|               | │    --------------------   ││    --------------------   │ |
|               | │      predicate: k = 1     ││      predicate: k = 1     │ |
|               | └─────────────┬─────────────┘└─────────────┬─────────────┘ |
|               | ┌─────────────┴─────────────┐┌─────────────┴─────────────┐ |
|               | │       DataSourceExec      ││       DataSourceExec      │ |
|               | │    --------------------   ││    --------------------   │ |
|               | │          bytes: 0         ││          bytes: 0         │ |
|               | │       format: memory      ││       format: memory      │ |
|               | │          rows: 0          ││          rows: 0          │ |
|               | └───────────────────────────┘└───────────────────────────┘ |
|               |                                                            |
+---------------+------------------------------------------------------------+

What changes are included in this PR?

  • Changed push_down_all_join to push down inferred predicates independently of left_preserved/right_preserved semantics.
  • Added unit tests.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@github-actions github-actions bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Jan 20, 2026
Comment on lines 459 to 464
for predicate in inferred_join_predicates {
if left_preserved && checker.is_left_only(&predicate) {
if checker.is_left_only(&predicate) {
left_push.push(predicate);
} else if right_preserved && checker.is_right_only(&predicate) {
} else if checker.is_right_only(&predicate) {
right_push.push(predicate);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning for this is that if this is an inferred predicated (i.e., inferred from the join) and can be pushed to the left/right relation, it should be pushed, independently of the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push down join key filters for LEFT/RIGHT/ANTI joins

1 participant