Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -69,8 +68,15 @@
* The abstract class for all materialized view rules
*/
public abstract class AbstractMaterializedViewRule implements ExplorationRuleFactory {
public static final HashSet<JoinType> SUPPORTED_JOIN_TYPE_SET = Sets.newHashSet(JoinType.INNER_JOIN,
JoinType.LEFT_OUTER_JOIN);
public static final Set<JoinType> SUPPORTED_JOIN_TYPE_SET = ImmutableSet.of(
JoinType.INNER_JOIN,
JoinType.LEFT_OUTER_JOIN,
JoinType.RIGHT_OUTER_JOIN,
JoinType.FULL_OUTER_JOIN,
JoinType.LEFT_SEMI_JOIN,
JoinType.RIGHT_SEMI_JOIN,
JoinType.LEFT_ANTI_JOIN,
JoinType.RIGHT_ANTI_JOIN);

/**
* The abstract template method for query rewrite, it contains the main logic, try to rewrite query by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.doris.nereids.rules.exploration.mv;

import org.apache.doris.common.Pair;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Slot;

Expand All @@ -27,6 +28,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* comparison result of view and query
Expand Down Expand Up @@ -111,8 +113,14 @@ public Builder addViewExpressions(Collection<? extends Expression> expressions)
return this;
}

public Builder addViewNoNullableSlot(Set<Slot> viewNoNullableSlot) {
viewNoNullableSlotBuilder.add(ImmutableSet.copyOf(viewNoNullableSlot));
/**Add slots which should reject null slots in view*/
public Builder addViewNoNullableSlot(Pair<Set<Slot>, Set<Slot>> viewNoNullableSlotsPair) {
if (!viewNoNullableSlotsPair.first.isEmpty()) {
viewNoNullableSlotBuilder.add(viewNoNullableSlotsPair.first);
}
if (!viewNoNullableSlotsPair.second.isEmpty()) {
viewNoNullableSlotBuilder.add(viewNoNullableSlotsPair.second);
}
return this;
}

Expand All @@ -127,7 +135,9 @@ public boolean isInvalid() {

public ComparisonResult build() {
Preconditions.checkArgument(valid, "Comparison result must be valid");
return new ComparisonResult(queryBuilder.build(), queryAllPulledUpExpressionsBuilder.build(),
return new ComparisonResult(queryBuilder.build(),
queryAllPulledUpExpressionsBuilder.build().stream()
.filter(expr -> !expr.isInferred()).collect(Collectors.toList()),
viewBuilder.build(), viewNoNullableSlotBuilder.build(), valid, "");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public class HyperGraphComparator {
private final Map<Edge, List<? extends Expression>> pullUpQueryExprWithEdge = new HashMap<>();
private final Map<Edge, List<? extends Expression>> pullUpViewExprWithEdge = new HashMap<>();
private final LogicalCompatibilityContext logicalCompatibilityContext;
private final Map<JoinEdge, Pair<JoinType, Set<Slot>>> inferredViewEdgeWithCond = new HashMap<>();
// this records the slots which needs to reject null
// the key is the target join which should reject null, the value is a pair, the first value of the pair is the
// join type, the second value is also a pair which left represents the slots in the left of join that should
// reject null, right represents the slots in the right of join that should reject null.
private final Map<JoinEdge, Pair<JoinType, Pair<Set<Slot>, Set<Slot>>>> inferredViewEdgeWithCond = new HashMap<>();
private List<JoinEdge> viewJoinEdgesAfterInferring;
private List<FilterEdge> viewFilterEdgesAfterInferring;
private final long eliminateViewNodesMap;
Expand Down Expand Up @@ -263,7 +267,7 @@ private ComparisonResult buildComparisonRes() {
}
builder.addViewExpressions(rawFilter);
}
for (Pair<JoinType, Set<Slot>> inferredCond : inferredViewEdgeWithCond.values()) {
for (Pair<JoinType, Pair<Set<Slot>, Set<Slot>>> inferredCond : inferredViewEdgeWithCond.values()) {
builder.addViewNoNullableSlot(inferredCond.second);
}
builder.addQueryAllPulledUpExpressions(
Expand Down Expand Up @@ -485,11 +489,14 @@ private boolean tryInferEdge(JoinEdge query, JoinEdge view) {
if (noNullableChild == null) {
return false;
}
Set<Slot> noNullableSlot = Sets.union(
noNullableChild.first ? view.getJoin().left().getOutputSet() : ImmutableSet.of(),
noNullableChild.second ? view.getJoin().right().getOutputSet() : ImmutableSet.of()
);
inferredViewEdgeWithCond.put(view, Pair.of(query.getJoinType(), noNullableSlot));
Pair<Set<Slot>, Set<Slot>> noNullableSlotSetPair = Pair.of(ImmutableSet.of(), ImmutableSet.of());
if (noNullableChild.first) {
noNullableSlotSetPair.first = view.getJoin().left().getOutputSet();
}
if (noNullableChild.second) {
noNullableSlotSetPair.second = view.getJoin().right().getOutputSet();
}
inferredViewEdgeWithCond.put(view, Pair.of(query.getJoinType(), noNullableSlotSetPair));
}
return true;
}
Expand Down
Loading