github-actions[bot] commented on code in PR #67919:
URL: https://github.com/apache/doris/pull/67919#discussion_r4013186189
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/InferPredicateByReplace.java:
##########
@@ -171,6 +175,27 @@ private static <T extends Expression> Set<Expression>
getEqualSetAndDoReplace(T
return res;
}
+ private static boolean canReplace(Expression source, Expression target,
Expression predicate) {
+ Expression comparison = predicate instanceof Not ? predicate.child(0)
: predicate;
+ // Direct comparisons observe comparison equality rather than a
value's type or representation.
+ // Do not descend through functions, casts or OR to apply this
exception.
+ if ((comparison instanceof ComparisonPredicate || comparison
instanceof InPredicate)
+ && comparison.child(0).equals(source)) {
+ return true;
+ }
+ DataType type = source.getDataType();
+ // Comparison equality across types does not preserve type-sensitive
expressions such as CAST to STRING.
+ if (!type.equals(target.getDataType())) {
+ return false;
+ }
+ // Only substitute types whose equality preserves the value observed
by enclosing expressions.
+ // In particular, FLOAT/DOUBLE equality cannot distinguish signed
zero, but SIGNBIT can.
+ // Comparisons can still be propagated separately by
UnequalPredicateInfer.
+ return type.isBooleanType() || type.isIntegralType() ||
type.isDecimalLikeType()
Review Comment:
[P1] Exclude NoneMovableFunction from replacement inference
This allowlist still treats every deterministic expression over equal
same-type values as movable, but `assert_true` is deterministic and implements
`NoneMovableFunction`. For the reduced plan `Join(a=b)` with left child
`Filter(assert_true(a > 0, 'bad') OR a > 10) -> Scan L(a={1})` and right child
`Scan R(b={-1,1})`, `visitOr` maps the sole slot `a` to the whole OR and this
branch infers `assert_true(b > 0, 'bad') OR b > 10`.
`InferPredicates.inferNewPredicate` installs that filter on the right child, so
the unmatched `b=-1` row raises even though the original plan returns the `1=1`
match. Please reject predicates containing `NoneMovableFunction` (as the other
movement rules do) before cloning them across an equality.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/UnequalPredicateInfer.java:
##########
@@ -448,7 +448,8 @@ public Set<Expression> chooseInputPredicates(Relation[][]
chosen) {
clear(chosen, left, right, type);
} else if (deduced[left][right] != type) {
keep[i] = true;
- set(deduced, left, right, Relation.EQ);
+ // Preserve the relation of the retained predicate; an
inequality is not an equality.
+ set(deduced, left, right, type);
Review Comment:
[P1] Preserve strict edges after recording the retained relation
This assignment creates a head-only weakening when equality and
strict/non-strict edges overlap. For the ordered filter `a = c AND c > a AND c
>= b AND b > c AND b = c`, selection starts with `a=b EQ`, `a=c EQ`, and `b>a
GT`. Here `c>=b` enters this branch. Recording it as `GTE` makes the closure
treat the later `b>c` input as redundant; generation then emits `a=b` and
`clear(..., EQ)` also removes the distinct reverse `b>a GT`. The result keeps
only equalities plus `c>=b`, so `a=b=c` passes although the input is
contradictory. With the base revision's `EQ` write, `b>c` is retained and the
contradiction remains. Please preserve simultaneous reverse relations (or make
EQ clearing relation-aware) and add this ordered case plus permutations to the
semantic oracle and a filter regression.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/InferPredicateByReplace.java:
##########
@@ -171,6 +175,27 @@ private static <T extends Expression> Set<Expression>
getEqualSetAndDoReplace(T
return res;
}
+ private static boolean canReplace(Expression source, Expression target,
Expression predicate) {
+ Expression comparison = predicate instanceof Not ? predicate.child(0)
: predicate;
+ // Direct comparisons observe comparison equality rather than a
value's type or representation.
+ // Do not descend through functions, casts or OR to apply this
exception.
+ if ((comparison instanceof ComparisonPredicate || comparison
instanceof InPredicate)
Review Comment:
[P1] Do not propagate through lossy TIMESTAMPTZ casts
This direct exception assumes the equality pair was extracted through
injective casts, but `PredicateInferUtils.validForInfer` currently peels any
`TIMESTAMPTZ -> DATETIMEV2` cast even though
`TimeStampTzType.isInjectiveCastTo` rejects that conversion. In
`America/New_York` fall-back, the reduced plan `InnerJoin(CAST(l.tz AS
DATETIMEV2(0)) = r.dt)` can join `l.tz=06:30Z` to `r.dt=01:30`; a left filter
`NOT(l.tz = 05:30Z)` is true, yet replacement produces `NOT(r.dt = 01:30)` and
pushes false to the right child because both UTC instants cast to local 01:30.
Scale reduction has the same problem (`.1236` rounds to `.124`). Please stop
exposing a raw equality through this cast unless
`childType.isInjectiveCastTo(targetType)` holds, and cover the production join
path; guarding only this branch would leave the same extracted pair available
to inequality inference.
--
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]