morrySnow opened a new pull request, #67895:
URL: https://github.com/apache/doris/pull/67895
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
Problem: Comparisons whose left side divides a value by a constant could
return incorrect booleans or lose NULL results after expression simplification.
Root cause: The arithmetic comparison rule treated division as algebraically
invertible and rewrote `x / c op r` as `x op r * c`. That equivalence does not
hold under SQL numeric coercion, floating-point and decimal rounding, overflow,
or division-by-zero semantics.
Reproduction: Division by zero should yield NULL, but the rewrite changed `x
/ 0 > 1` into `x > 0`. Finite non-zero counterexamples also differ at rounding
boundaries, including DOUBLE `0.30000000000000004 / 3.0 > 0.1`,
integer-to-DOUBLE `-100 / 11 > -9.090909090909092`, and DECIMAL `1 / 3 >
0.333333`.
Fix: Remove division from the inverse-rearrangement allowlist so the
complete Divide expression remains on its original side of the comparison. Keep
the existing additive and supported date/time rearrangements unchanged.
Tests: Add expression-rule unit coverage for zero representations, folded
zero, NULL, non-finite values, finite rounding boundaries, negative divisors,
and nested arithmetic. Add end-to-end plan and result regression coverage with
the rule enabled and disabled.
### Release note
Fix incorrect comparison results and lost NULL values for division
expressions with constant divisors.
### Check List (For Author)
- Test:
- Unit Test
- Regression test
- Full FE build and checkstyle
- Behavior changed: Yes. Division comparisons are kept intact unless a
future rewrite can prove SQL-semantic equivalence.
- Does this need documentation: No
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]