foxtail463 commented on code in PR #65250:
URL: https://github.com/apache/doris/pull/65250#discussion_r3536431498
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java:
##########
@@ -752,62 +752,59 @@ private static boolean isNullOrFalse(Expression
expression) {
* infer notNulls slot from predicate
*/
public static Set<Slot> inferNotNullSlots(Set<Expression> predicates,
CascadesContext cascadesContext) {
- ImmutableSet.Builder<Slot> notNullSlots =
ImmutableSet.builderWithExpectedSize(predicates.size());
- for (Expression predicate :
filterCheapPredicatesForNotNull(predicates)) {
- for (Slot slot : predicate.getInputSlots()) {
- Map<Expression, Expression> replaceMap = new HashMap<>();
- Literal nullLiteral = new NullLiteral(slot.getDataType());
- replaceMap.put(slot, nullLiteral);
- Expression evalExpr = FoldConstantRule.evaluate(
- ExpressionUtils.replace(predicate, replaceMap),
- new ExpressionRewriteContext(cascadesContext));
- if (evalExpr.isNullLiteral() ||
BooleanLiteral.FALSE.equals(evalExpr)) {
- notNullSlots.add(slot);
- }
- }
- }
- return notNullSlots.build();
- }
-
- /**
- * Return whether all predicates are cheap enough for not-null inference.
- */
- public static boolean isCheapEnoughToInferNotNull(Collection<? extends
Expression> predicates) {
- Set<Slot> inputSlots = new HashSet<>();
+ Set<Slot> targetSlots = new HashSet<>();
for (Expression predicate : predicates) {
- Optional<Set<Slot>> mergedInputSlots =
mergeInputSlotsIfCheap(predicate, inputSlots);
- if (!mergedInputSlots.isPresent()) {
- return false;
- }
- inputSlots = mergedInputSlots.get();
+ targetSlots.addAll(predicate.getInputSlots());
}
- return true;
+ return inferNotNullSlots(predicates, targetSlots, cascadesContext);
}
/**
- * Filter predicates that are cheap enough for not-null inference.
+ * infer notNulls slot from predicate but these slots must be in the given
target slots.
*/
- public static Set<Expression> filterCheapPredicatesForNotNull(
- Collection<? extends Expression> predicates) {
+ public static Set<Slot> inferNotNullSlots(Set<Expression> predicates,
Set<Slot> targetSlots,
+ CascadesContext cascadesContext) {
+ ImmutableSet.Builder<Slot> notNullSlots =
ImmutableSet.builderWithExpectedSize(targetSlots.size());
Set<Slot> inputSlots = new HashSet<>();
- Set<Expression> cheapPredicates = Sets.newLinkedHashSet();
for (Expression predicate : predicates) {
- Optional<Set<Slot>> mergedInputSlots =
mergeInputSlotsIfCheap(predicate, inputSlots);
+ if (predicate.getWidth() > MAX_INFER_NOT_NULL_EXPR_WIDTH
+ || predicate.getDepth() > MAX_INFER_NOT_NULL_EXPR_DEPTH) {
+ continue;
+ }
+ Set<Slot> predicateInputSlots = predicate.getInputSlots();
+ Set<Slot> candidateSlots = Sets.intersection(predicateInputSlots,
targetSlots);
+ if (candidateSlots.isEmpty()) {
+ continue;
+ }
+ Optional<Set<Slot>> mergedInputSlots =
mergeInputSlotsWithinLimit(inputSlots, predicateInputSlots);
if (!mergedInputSlots.isPresent()) {
continue;
}
inputSlots = mergedInputSlots.get();
- cheapPredicates.add(predicate);
+ for (Slot slot : candidateSlots) {
+ // Mark slots are join outputs, not child-side not-null
inference targets.
+ if (slot instanceof MarkJoinSlotReference) {
+ continue;
+ }
Review Comment:
yes
--
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]