Skip to content

Conversation

@findepi
Copy link
Member

@findepi findepi commented Aug 8, 2025

There were optimizations simplifying some arithmetic operations (*, /, % and some bitwise operations) when one operand is constant NULL. This can be extended to almost all other binary operators.

@github-actions github-actions bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Aug 8, 2025
@findepi findepi force-pushed the findepi/simplify-comparisons-and-binary-operations-involving-null-378780 branch 2 times, most recently from 03173f0 to ff9b921 Compare August 8, 2025 12:23
@findepi findepi marked this pull request as draft August 8, 2025 12:27
@findepi findepi force-pushed the findepi/simplify-comparisons-and-binary-operations-involving-null-378780 branch 2 times, most recently from 302956d to 6d9d469 Compare August 8, 2025 13:13
02)--TableScan: t projection=[x]
physical_plan
01)CoalesceBatchesExec: target_batch_size=8192
02)--FilterExec: x@0 < 5 OR NULL
Copy link
Member Author

Choose a reason for hiding this comment

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

To be followed-up: in a projection context this cannot be simplified, but in a filter context (on top-level of a filter), it can.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the difference between Filters and Projections for null semantics has come up before. I think currently there is no way to differentiate

There is a ticket that tracks this idea too:

There were optimizations simplifying some arithmetic operations (`*`,
`/`, `%` and some bitwise operations) when one operand is constant
`NULL`. This can be extended to almost all other binary operators.
@findepi findepi force-pushed the findepi/simplify-comparisons-and-binary-operations-involving-null-378780 branch from 6d9d469 to e3d60b3 Compare August 8, 2025 13:18
@github-actions github-actions bot added the substrait Changes to the substrait crate label Aug 8, 2025
@findepi findepi marked this pull request as ready for review August 8, 2025 13:18
@findepi findepi requested review from alamb and jayzhan211 August 9, 2025 20:44
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

THanks @findepi -- this is a nice cleanup

02)--TableScan: t projection=[x]
physical_plan
01)CoalesceBatchesExec: target_batch_size=8192
02)--FilterExec: x@0 < 5 OR NULL
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the difference between Filters and Projections for null semantics has come up before. I think currently there is no way to differentiate

There is a ticket that tracks this idea too:

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Aug 11, 2025
@findepi findepi added the performance Make DataFusion faster label Aug 11, 2025
@findepi findepi merged commit 876b504 into apache:main Aug 11, 2025
27 checks passed
@findepi findepi deleted the findepi/simplify-comparisons-and-binary-operations-involving-null-378780 branch August 11, 2025 09:52
@alamb
Copy link
Contributor

alamb commented Aug 11, 2025

The extended tests appear to have started failing on main after this PR was merged

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

Labels

logical-expr Logical plan and expressions optimizer Optimizer rules performance Make DataFusion faster sqllogictest SQL Logic Tests (.slt) substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants