OIiveirra commented on code in PR #69576:
URL: https://github.com/apache/doris/pull/69576#discussion_r4367547857
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterThroughProject.java:
##########
@@ -101,7 +101,7 @@ private static Plan pushDownFilterThroughLimitProject(
Map<Slot, Expression> childAlias = project.getAliasToProducer();
// split the conjuncts by child's output
Pair<Set<Expression>, Set<Expression>> splitConjuncts =
- splitConjunctsByChildOutput(filter.getConjuncts(),
childOutputs, childAlias);
+ splitConjunctsByChildOutput(filter.getConjuncts(),
childOutputs, childAlias, limit);
Review Comment:
Fixed in 3647eeb49cca154d09f43788a163895e373d022b.
The Limit/Project compensation now bypasses only the date-arithmetic
protection check: it restores `Project -> Filter -> Limit`, so both the
expanded predicate and the projection evaluate after the enclosing OFFSET and
all lower rejecting operators. Existing volatile-expression and Project-level
guards are retained; ordinary Filter/Project pushdown remains protected.
Reproduced the original overflow before the fix with OFFSET 1 and 100.
Planner coverage now checks offsets 0/1/100, with and without a lower Filter.
Native regression verifies empty results for offsets 1/100 and preserves the
real overflow at offset 0. Final branch validation passed: 17 FE unit tests, 3
targeted native P0 suites and 10 direct SQL checks, with no failures or skips.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java:
##########
@@ -136,6 +149,39 @@ public class ExpressionUtils {
// folding the conjunct). We restrict MAX_MARK_SLOT_COUNT to 4 to bound
this cost.
private static final int MAX_MARK_SLOT_COUNT = 4;
+ /**
+ * Date arithmetic can throw for values outside its valid range. Keep it
above a lower
+ * condition, join, limit, rejecting set operation, generate, or CTE
consumer so rejected
+ * rows are not evaluated early.
+ * A date add/subtract with literal zero is an identity and remains safe
to push through.
+ */
+ public static boolean requiresDateArithmeticProtection(Expression
expression, Plan input) {
+ return expression.anyMatch(expr -> isUnsafeDateArithmetic((Expression)
expr))
+ && input.anyMatch(plan -> plan instanceof Filter || plan
instanceof Join || plan instanceof Limit
+ || plan instanceof LogicalExcept || plan instanceof
PhysicalExcept
+ || plan instanceof LogicalIntersect || plan instanceof
PhysicalIntersect
+ || plan instanceof Generate || plan instanceof
LogicalCTEConsumer
+ || plan instanceof PhysicalCTEConsumer);
+ }
+
+ private static boolean isUnsafeDateArithmetic(Expression expression) {
+ if (expression instanceof DateCeilFloorMonotonic) {
+ return true;
+ }
+ if (!(expression instanceof DateAddSubMonotonic)) {
Review Comment:
Fixed in 3647eeb49cca154d09f43788a163895e373d022b.
The existing classifier now includes `TimestampArithmetic`, treating child 0
as the date operand and applying the same integer-zero exemption to its
interval operand. Logical and physical pushdown share this check; no parser,
backend or global expression-trait changes were added.
Reproduced the EXCEPT overflow before the fix for `dt + INTERVAL 5 WEEK` and
`dt - INTERVAL -5 WEEK`. Added logical/physical planner coverage and native
regression for interval addition/subtraction, both zero-interval spellings, and
participating-row overflow. Both former failures now return February 5; zero
offsets and real-overflow controls retain their expected behavior. Final branch
validation passed: 17 FE unit tests, 3 targeted native P0 suites and 10 direct
SQL checks, with no failures or skips.
--
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]