You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "fzlzjerry (via GitHub)" <gi...@apache.org> on 2026/08/11 09:59:28 UTC
[PR] fix: preserve null semantics in expression simplification [datafusion]
fzlzjerry opened a new pull request, #24258:
URL: https://github.com/apache/datafusion/pull/24258
## Which issue does this PR close?
- Closes #24246.
## Rationale for this change
Several expression simplifications erase SQL NULL semantics. For nullable inputs, identities such as `power(a, 0)`, `log(a, 1)`, and `i XOR i` can return constants instead of NULL. Set algebra over `IN` expressions and the `array_has` to `IN` rewrite can similarly change NULL or false results.
## What changes are included in this PR?
- Apply the affected logarithm, power, and XOR identities only when the operand being eliminated is non-nullable.
- Keep `IN`/`NOT IN` set operations unchanged when list items may be NULL, and preserve the nullable branch when an otherwise safe operation becomes a constant.
- Avoid rewriting `array_has` to `IN` when a nullable array element would change the result, while retaining the safe same-expression case.
- Add unit and SQL logic regression coverage for the reported expressions and their query plans.
## Are these changes tested?
Yes. The following checks pass:
- `./dev/rust_lint.sh`
- `cargo test --profile=ci -p datafusion-functions -p datafusion-functions-nested -p datafusion-optimizer --lib`
- `cargo test --profile=ci --test sqllogictests`
- `RUST_BACKTRACE=1 prlimit --nofile=65536:65536 -- cargo test --profile ci --exclude datafusion-examples --exclude datafusion-benchmarks --exclude datafusion-cli --workspace --lib --tests --bins --features avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption`
## Are there any user-facing changes?
Yes. Expressions involving nullable inputs now retain their SQL three-valued-logic results instead of being simplified to incorrect constants. There are no public API changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3765183594
##########
datafusion/sqllogictest/test_files/predicates.slt:
##########
@@ -976,14 +976,22 @@ create table t(x int) as values (1), (2), (3);
query TT
explain select x from t where x IN (1,2,3) AND x IN (4,5);
----
-logical_plan EmptyRelation: rows=0
-physical_plan EmptyExec
+logical_plan
+01)Filter: t.x IS NULL AND Boolean(NULL)
+02)--TableScan: t projection=[x]
+physical_plan
+01)FilterExec: x@0 IS NULL AND NULL
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
query TT
explain select x from t where x NOT IN (1,2,3,4) OR x NOT IN (5,6,7,8);
----
-logical_plan TableScan: t projection=[x]
-physical_plan DataSourceExec: partitions=1, partition_sizes=[1]
+logical_plan
+01)Filter: t.x IS NOT NULL OR Boolean(NULL)
+02)--TableScan: t projection=[x]
+physical_plan
+01)FilterExec: x@0 IS NOT NULL OR NULL
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
Review Comment:
this is also worse, seems like this changes the behavior of some optimization downstream
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "fzlzjerry (via GitHub)" <gi...@apache.org>.
fzlzjerry commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5265976072
Addressed both plan concerns in c2bdac8 and synced the branch with the latest `main`.
The general expression simplification still preserves NULL in projection contexts, while `EliminateFilter` now reduces the generated positive `AND` / `OR` trees using filter truth semantics. As a result, the disjoint `IN` case is back to `EmptyRelation`, and the `NOT IN` / `OR` case becomes `IS NOT NULL` rather than retaining the compound predicate. The latter must not become a bare scan because NULL inputs do not satisfy the filter.
The overlapping `log`, `power`, and XOR changes are no longer part of this PR. The remaining 8-file scope passes all-target/all-feature clippy, `./dev/rust_lint.sh`, the SQLLogicTest suite, and the extended workspace test matrix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "fzlzjerry (via GitHub)" <gi...@apache.org>.
fzlzjerry commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3916588637
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2304,6 +2332,39 @@ fn inlist_except(mut l1: InList, l2: &InList) -> Result<Expr> {
Ok(Expr::InList(l1))
}
+/// Set algebra on `IN` lists is only sound if nullable list items are not
+/// discarded. When the tested expression is nullable, preserve the NULL branch
+/// of an otherwise constant result explicitly.
+fn simplify_inlist_set_operation(
+ info: &SimplifyContext,
+ left: &InList,
+ right: &InList,
+ result: Expr,
+) -> Option<Expr> {
+ let list_items_are_non_nullable = left
+ .list
+ .iter()
+ .chain(&right.list)
+ .all(|item| matches!(info.nullable(item), Ok(false)));
+
+ if !list_items_are_non_nullable {
+ return None;
+ }
+
+ if !is_true(&result) && !is_false(&result) {
Review Comment:
`is_bool_lit` also matches `Boolean(None)`, whereas this branch must only handle non-null boolean constants. I kept the explicit `is_true` / `is_false` check and added a regression test for a NULL boolean result.
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2304,6 +2332,39 @@ fn inlist_except(mut l1: InList, l2: &InList) -> Result<Expr> {
Ok(Expr::InList(l1))
}
+/// Set algebra on `IN` lists is only sound if nullable list items are not
+/// discarded. When the tested expression is nullable, preserve the NULL branch
+/// of an otherwise constant result explicitly.
+fn simplify_inlist_set_operation(
Review Comment:
Updated — the helper now returns `Result<Option<Expr>>`. Nullability errors from both list items and the tested expression propagate through all four callers, with regression coverage for both error paths.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5253303685
FYI there is also #24247 and #24248
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5469315782
Will do, thanks for pinging me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "fzlzjerry (via GitHub)" <gi...@apache.org>.
fzlzjerry commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5497465235
Rebased onto the current `main` and fixed the SQLite-suite regression from the previous head. `EliminateFilter` now only drops the other side of `NULL`/`FALSE AND ...` when that expression is known safe to discard; potentially fallible expressions remain in the predicate, preserving runtime errors such as division by zero. I added optimizer and SQLLogicTest coverage for both operand orders.
Validated on `c6dc40034` with:
- `cargo fmt --all -- --check`
- `cargo clippy --all-targets --all-features -- -D warnings`
- the full `datafusion-optimizer` and `datafusion-functions-nested` library test suites (770 + 115 tests)
- the affected `predicates` / `simplify_expr` SQLLogicTests
- all nine SQLite files reported by the failed CI job
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "fzlzjerry (via GitHub)" <gi...@apache.org>.
fzlzjerry commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5253568874
Thanks for flagging these. I compared the scopes:
- #24247 overlaps the `log` / `power` fixes.
- #24248 overlaps the XOR cancellation fix.
- This PR additionally covers the `IN` / `NOT IN` set operations and the `array_has` to `IN` rewrite from #24246.
I'll keep the current comparison available for the review pass, then promptly rebase and drop whichever overlapping implementation the maintainers decide not to use.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5511593277
Overall this LGTM, just a couple of minor comments/questions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5252410730
I'll try and review it later today
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5252702066
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/24258?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `92.19512%` with `16 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 81.01%. Comparing base ([`a05388e`](https://app.codecov.io/gh/apache/datafusion/commit/a05388e82374ed2943595980b0539b6c1fa629a0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ea308e2`](https://app.codecov.io/gh/apache/datafusion/commit/ea308e2a12d76db09401eb427d81ab1a163b8361?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 4 commits behind head on main.
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/24258?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...imizer/src/simplify\_expressions/expr\_simplifier.rs](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&filepath=datafusion%2Foptimizer%2Fsrc%2Fsimplify_expressions%2Fexpr_simplifier.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9vcHRpbWl6ZXIvc3JjL3NpbXBsaWZ5X2V4cHJlc3Npb25zL2V4cHJfc2ltcGxpZmllci5ycw==) | 92.22% | [3 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [datafusion/functions-nested/src/array\_has.rs](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&filepath=datafusion%2Ffunctions-nested%2Fsrc%2Farray_has.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mdW5jdGlvbnMtbmVzdGVkL3NyYy9hcnJheV9oYXMucnM=) | 94.52% | [3 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [datafusion/functions/src/math/log.rs](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&filepath=datafusion%2Ffunctions%2Fsrc%2Fmath%2Flog.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mdW5jdGlvbnMvc3JjL21hdGgvbG9nLnJz) | 85.00% | [1 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [datafusion/functions/src/math/power.rs](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&filepath=datafusion%2Ffunctions%2Fsrc%2Fmath%2Fpower.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mdW5jdGlvbnMvc3JjL21hdGgvcG93ZXIucnM=) | 90.90% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24258?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #24258 +/- ##
========================================
Coverage 81.01% 81.01%
========================================
Files 1106 1106
Lines 383974 384228 +254
Branches 383974 384228 +254
========================================
+ Hits 311085 311297 +212
- Misses 54554 54577 +23
- Partials 18335 18354 +19
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/24258?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "fzlzjerry (via GitHub)" <gi...@apache.org>.
fzlzjerry commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3765878111
##########
datafusion/sqllogictest/test_files/predicates.slt:
##########
@@ -976,14 +976,22 @@ create table t(x int) as values (1), (2), (3);
query TT
explain select x from t where x IN (1,2,3) AND x IN (4,5);
----
-logical_plan EmptyRelation: rows=0
-physical_plan EmptyExec
+logical_plan
+01)Filter: t.x IS NULL AND Boolean(NULL)
+02)--TableScan: t projection=[x]
+physical_plan
+01)FilterExec: x@0 IS NULL AND NULL
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
Review Comment:
Agreed that the filter plan should still optimize away. Rewriting this to `false` is only equivalent under filter semantics; in a projection, a nullable input must still produce NULL.
I kept the NULL-preserving expression rewrite and taught `EliminateFilter` to simplify positive `AND` / `OR` trees using filter truth semantics, so this case is `EmptyRelation: rows=0` again. I also added focused optimizer coverage for both operand orders and nested predicates in c2bdac8.
##########
datafusion/sqllogictest/test_files/predicates.slt:
##########
@@ -976,14 +976,22 @@ create table t(x int) as values (1), (2), (3);
query TT
explain select x from t where x IN (1,2,3) AND x IN (4,5);
----
-logical_plan EmptyRelation: rows=0
-physical_plan EmptyExec
+logical_plan
+01)Filter: t.x IS NULL AND Boolean(NULL)
+02)--TableScan: t projection=[x]
+physical_plan
+01)FilterExec: x@0 IS NULL AND NULL
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
query TT
explain select x from t where x NOT IN (1,2,3,4) OR x NOT IN (5,6,7,8);
----
-logical_plan TableScan: t projection=[x]
-physical_plan DataSourceExec: partitions=1, partition_sizes=[1]
+logical_plan
+01)Filter: t.x IS NOT NULL OR Boolean(NULL)
+02)--TableScan: t projection=[x]
+physical_plan
+01)FilterExec: x@0 IS NOT NULL OR NULL
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
Review Comment:
Fixed in c2bdac8. In filter context, `predicate OR NULL` can reduce to `predicate` because only TRUE rows survive, so the compound filter is gone.
For this nullable column the resulting plan is `Filter: t1.column1 IS NOT NULL`. A bare `TableScan` would keep NULL rows incorrectly: both `NOT IN` predicates evaluate to NULL for a NULL input, so the row must be rejected. I added runtime NULL coverage as well as filter-tree optimizer tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3915309468
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2304,6 +2332,39 @@ fn inlist_except(mut l1: InList, l2: &InList) -> Result<Expr> {
Ok(Expr::InList(l1))
}
+/// Set algebra on `IN` lists is only sound if nullable list items are not
+/// discarded. When the tested expression is nullable, preserve the NULL branch
+/// of an otherwise constant result explicitly.
+fn simplify_inlist_set_operation(
Review Comment:
How hard is it to make this function return `Result<Option<Expr>>`? discarding the error cases seems weird to me.
If its acceptable, might be worth documenting why.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3765170399
##########
datafusion/sqllogictest/test_files/predicates.slt:
##########
@@ -976,14 +976,22 @@ create table t(x int) as values (1), (2), (3);
query TT
explain select x from t where x IN (1,2,3) AND x IN (4,5);
----
-logical_plan EmptyRelation: rows=0
-physical_plan EmptyExec
+logical_plan
+01)Filter: t.x IS NULL AND Boolean(NULL)
+02)--TableScan: t projection=[x]
+physical_plan
+01)FilterExec: x@0 IS NULL AND NULL
+02)--DataSourceExec: partitions=1, partition_sizes=[1]
Review Comment:
This seems like a regression? The current state optimizes this query away which is the optimal behavior here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3915286140
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2304,6 +2332,39 @@ fn inlist_except(mut l1: InList, l2: &InList) -> Result<Expr> {
Ok(Expr::InList(l1))
}
+/// Set algebra on `IN` lists is only sound if nullable list items are not
+/// discarded. When the tested expression is nullable, preserve the NULL branch
+/// of an otherwise constant result explicitly.
+fn simplify_inlist_set_operation(
+ info: &SimplifyContext,
+ left: &InList,
+ right: &InList,
+ result: Expr,
+) -> Option<Expr> {
+ let list_items_are_non_nullable = left
+ .list
+ .iter()
+ .chain(&right.list)
+ .all(|item| matches!(info.nullable(item), Ok(false)));
+
+ if !list_items_are_non_nullable {
+ return None;
+ }
+
+ if !is_true(&result) && !is_false(&result) {
Review Comment:
nit - is this `!is_bool_lit(&result)`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS merged PR #24258:
URL: https://github.com/apache/datafusion/pull/24258
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5253507835
@neilconway thanks for the heads up, I'll try and do a pass on all three tonight/tomorrow morning (UK time).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "AdamGS (via GitHub)" <gi...@apache.org>.
AdamGS commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5264935766
I think the logical plans that this creates seem worse in some of these trivial cases, which ideally will keep optimizing work away while maintaining correctness in more complex cases.
I'm not sure if its because of the default nullability of stuff coming out the parser or something else.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5290089542
- https://github.com/apache/datafusion/pull/24247 and https://github.com/apache/datafusion/pull/24248 are merged now, could we rebase this now
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: preserve null semantics in expression simplification [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#issuecomment-5468935173
@AdamGS would you be able to help take another look at this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org