Doris-Breakwater commented on issue #69368:
URL: https://github.com/apache/doris/issues/69368#issuecomment-6308666716

   Source-level triage supports a **Nereids FE constant-folding coverage defect 
affecting partition pruning**. The reported results remain correct; the 
demonstrated impact is unnecessary partition scans. Suggested ownership: 
FE/Nereids expression evaluation and partition pruning. The issue currently has 
no labels.
   
   I checked the exact reported 4.1.3 commit, 
`7126cf65d96ebc43fce0906f51e92c1a2ccf24a6`, in the local repository, and the 
relevant files at reported master commit 
`9e60fab4db00998d490d916c4bf304b15490c1b9` through GitHub.
   
   **Verified code path**
   
   1. `FoldConstantRuleOnFE.visitBoundFunction()` delegates eligible calls to 
`ExpressionEvaluator`. Its registry includes `DateTimeAcquire`; when no 
matching executable method exists, evaluation returns the original expression. 
`DateTimeAcquire` has `current_date` and `utc_timestamp` registrations but no 
`utc_date` or `utc_time` registration in either inspected revision. This 
explains the difference in the supplied `EXPLAIN` output. See [FE 
folding](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java#L554-L560),
 [evaluator dispatch and 
registry](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionEvaluator.java#L58-L211),
 and [master's executable 
functions](https://github.com/apache/doris/blob/9e60fab4db00998d490d916c4bf304b15490c1b9/fe/fe-core/src/main/java
 
/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java).
   2. Partition-predicate extraction explicitly performs FE folding. The range 
evaluator can derive the `>=` boundary when the comparison has a literal 
operand. With `CAST(utc_date() AS datetimev2(0))` unresolved, that boundary is 
unavailable; partitions cannot be excluded by this predicate. Keeping them is 
the conservative behavior that preserves results. See 
[extraction](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPruneExpressionExtractor.java#L77-L88)
 and [range 
evaluation](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java#L222-L244).
   3. `enable_fold_constant_by_be=true` does not supply a fallback for these 
calls: BE folding collects expressions satisfying `isConstant()`, whereas 
`UtcDate` and `UtcTime` implement `LeafExpression`, and nonliteral leaves 
return false from `Expression.isConstant()`. Their containing cast/arithmetic 
expression therefore also fails that test. This is a concrete eligibility 
restriction, independent of BE RPC availability. See [BE 
collection](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java#L203-L225)
 and [constant 
classification](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java#L301-L321).
   
   **Recommended next step**
   
   Add FE executable implementations for `utc_date()` and `utc_time()`, 
including `utc_time(precision)` with the existing integer argument signature 
and precision range 0–6. Return the corresponding DATEV2/TIMEV2 literals and 
use UTC explicitly. Preserve the functions' nondeterministic classification 
across statements.
   
   Account for the version difference when implementing/backporting: inspected 
master already obtains the statement's start instant through 
`currentInstant()`, while 4.1.3's existing FE acquisition functions use 
wall-clock time. The new implementation should preserve statement-time 
consistency with BE, especially around UTC midnight. BE's [UTC 
implementation](https://github.com/apache/doris/blob/7126cf65d96ebc43fce0906f51e92c1a2ccf24a6/be/src/exprs/function/function_date_or_datetime_computation.h#L1305-L1359)
 uses the runtime query timestamp and fixed `+00:00`.
   
   Validate literal folding and historical-partition exclusion for both `ts >= 
UTC_DATE()` and the interval variant, with BE folding enabled and disabled. 
Also cover non-UTC sessions, UTC-midnight boundaries, repeated statements at 
different instants, and `UTC_TIME()`/`UTC_TIME(0..6)` value and type parity 
with BE. These are proposed acceptance checks; no patch or test pass is claimed.
   
   The supplied version, DDL, data, session timezone, and plans are sufficient 
for initial triage; no additional logs or profile are needed at this stage. 
Independent runtime confirmation remains outstanding: the available local FE 
reports no live backends, so I could not rerun the reproduction. A healthy 
4.1.3/master test cluster is needed to confirm the scan-node partition lists 
and validate a candidate fix. No repository code was changed.
   
   The supplied workaround, `ts >= CAST(UTC_TIMESTAMP() AS DATE)`, follows the 
verified FE folding path. `CURRENT_DATE()` uses the session timezone, so it is 
an equivalent UTC-day boundary only when the session timezone is UTC.
   
   Breakwater-GitHub-Analysis-Slot: slot_db846cc3ba63
   


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