r33s3n6 opened a new issue, #68718: URL: https://github.com/apache/doris/issues/68718
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version 4.1.4 (doris-4.1.4-rc04-ad35a140c7f), single FE + single BE ### What's Wrong? `round(1e20, -25)` on a DOUBLE is 0 when FE folds the constant and `9.223372036854776e+19` when BE computes it from a column. FE folding: `0`. BE: `9.223372036854776e+19`. ``` SET enable_sql_cache = false SELECT round(CAST(1e20 AS DOUBLE), -25) AS fe, round(d1, -25) AS be FROM t +------+-----------------------+ | fe | be | +------+-----------------------+ | 0 | 9.223372036854776e+19 | +------+-----------------------+ SET debug_skip_fold_constant = true SELECT round(CAST(1e20 AS DOUBLE), -25) +----------------------------------+ | round(CAST(1e20 AS DOUBLE), -25) | +----------------------------------+ | 9.223372036854776e+19 | +----------------------------------+ ``` - **FE constant folding**: all arguments are literals, so Nereids folds the call during planning. Check: EXPLAIN shows the literal in place of the call: `final projections: 0, round(d1[#1], -25)` - **BE execution**: the arguments are columns (or `SET debug_skip_fold_constant = true`), so BE computes the call. Check: EXPLAIN keeps the call. ### What You Expected? Both give 0. ### How to Reproduce? Deployment: single FE + single BE, default session variables. ```sql CREATE TABLE t(id INT, d1 DOUBLE) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1'); INSERT INTO t VALUES (1, 1e20); SET enable_sql_cache = false; SELECT round(CAST(1e20 AS DOUBLE), -25) AS fe, round(d1, -25) AS be FROM t; SET debug_skip_fold_constant = true; SELECT round(CAST(1e20 AS DOUBLE), -25); ``` ### Anything Else? BE computes the scale with `int_exp10(-d)`, which saturates to `UINT64_MAX` for exponents above 19, so the value is rounded to a multiple of about 1.8e19; FE rounds the decimal value. - BE: [be/src/exec/common/int_exp.h#L56-L62](https://github.com/apache/doris/blob/4.1.4/be/src/exec/common/int_exp.h#L56-L62) — `int_exp10`: `UINT64_MAX` for `x > 19` (used at `round.h` L478) - FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L377-L381](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L377-L381) — `round(DoubleLiteral, IntegerLiteral)`: decimal rounding Found with AI assistance. ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
