LuciferYang commented on issue #64681:
URL: https://github.com/apache/doris/issues/64681#issuecomment-4766299764

   The root-cause analysis matches. One addition on reachability, plus a 
concrete repro.
   
   The DECIMALV2 overload `divideDecimal(DecimalLiteral, DecimalLiteral)` is 
only reached when decimal literals are parsed as DecimalV2, which is gated by 
the FE config `enable_decimal_conversion` (default `true`):
   
   - `LogicalPlanBuilder.visitDecimalLiteral` returns `DecimalV3Literal` when 
`enable_decimal_conversion = true` (the default) → constant folding dispatches 
to `divideDecimalV3`, which already guards on the denominator and is correct.
   - It returns `DecimalLiteral` (DecimalV2) only when 
`enable_decimal_conversion = false` → folding dispatches to the buggy 
`divideDecimal`.
   
   So the wrong result is observable only with the non-default legacy config. 
Minimal repro:
   
   ```sql
   ADMIN SET FRONTEND CONFIG ("enable_decimal_conversion" = "false");
   SELECT 0.0 / 5.0;   -- FE folds this to NULL; expected 0
   ADMIN SET FRONTEND CONFIG ("enable_decimal_conversion" = "true");
   ```
   
   On the remaining points:
   
   - `x / 0`: agreed — `ExpressionEvaluator.invoke` catches the 
`ArithmeticException` and returns the expression unfolded, so it is not an FE 
crash; the value still resolves to NULL (via BE), matching Doris/MySQL 
divide-by-zero semantics. The genuine defect is the `0 / x → NULL` wrong result.
   - Tests: PR #64675 adds direct unit tests on the executable helper for `0 / 
5` and `5 / 0`. I can also add a `FoldConstantRuleOnFE`-level test exercising 
the full dispatch with DecimalV2 literals if that coverage is preferred.
   - Backport: the same `divideDecimal` implementation exists on release 
branches; I'm happy to provide backports once a committer applies the 
appropriate branch-pick label.
   


-- 
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]

Reply via email to