Skip to content

fix: stop treating arithmetic negation as bitwise NOT - #24666

Closed
Amogh-2404 wants to merge 2 commits into
apache:mainfrom
Amogh-2404:codex/fix-arithmetic-negation-simplification
Closed

fix: stop treating arithmetic negation as bitwise NOT#24666
Amogh-2404 wants to merge 2 commits into
apache:mainfrom
Amogh-2404:codex/fix-arithmetic-negation-simplification

Conversation

@Amogh-2404

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Expr::Negative represents unary minus, but the simplifier applied identities for bitwise NOT. This produced wrong results in bitwise expressions and could hide signed-integer overflow when removing double negation.

What changes are included in this PR?

  • Remove the bitwise-complement and De Morgan rewrites for Expr::Negative.
  • Remove the helpers used only by those rewrites.
  • Replace the invalid unit expectations with preservation tests and add an end-to-end regression in scalar.slt.

Are these changes tested?

Yes. Unit tests cover both operand orders for AND, OR, and XOR, the two De Morgan shapes, and double negation. scalar.slt checks the resulting values end to end.

Are there any user-facing changes?

Yes. Unary minus in bitwise expressions now returns the correct results, and double negation preserves overflow behaviour. There are no API changes.

`Expr::Negative` represents unary minus, but these rules used bitwise-NOT identities. Remove the unsound rewrites and leave arithmetic negation unchanged.

Closes apache#24665

Signed-off-by: Amogh Ramesh <ramogh2404@gmail.com>
Signed-off-by: Amogh Ramesh <ramogh2404@gmail.com>
@github-actions github-actions Bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Aug 25, 2026
@Amogh-2404 Amogh-2404 closed this Aug 25, 2026
@Amogh-2404
Amogh-2404 deleted the codex/fix-arithmetic-negation-simplification branch August 25, 2026 13:56
@Amogh-2404

Copy link
Copy Markdown
Contributor Author

Continued in #24668 after renaming the branch.

@codecov-commenter

codecov-commenter commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.43%. Comparing base (63f5b55) to head (c37e666).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24666      +/-   ##
==========================================
- Coverage   81.44%   81.43%   -0.01%     
==========================================
  Files        1118     1118              
  Lines      399550   399478      -72     
  Branches   399550   399478      -72     
==========================================
- Hits       325398   325333      -65     
+ Misses      55154    55152       -2     
+ Partials    18998    18993       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Expression simplifier treats arithmetic negation as bitwise NOT

2 participants