[fix](nereids)select base index if select mv fails (#25715)
This commit is contained in:
@ -21,6 +21,8 @@ import org.apache.doris.nereids.rules.RulePromise;
|
||||
import org.apache.doris.nereids.trees.plans.Plan;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -32,6 +34,7 @@ import java.util.function.Predicate;
|
||||
* It can support pattern generic type to MatchedAction.
|
||||
*/
|
||||
public class PatternDescriptor<INPUT_TYPE extends Plan> {
|
||||
private static final Logger LOG = LogManager.getLogger(PatternDescriptor.class);
|
||||
public final Pattern<INPUT_TYPE> pattern;
|
||||
public final RulePromise defaultPromise;
|
||||
|
||||
@ -63,6 +66,22 @@ public class PatternDescriptor<INPUT_TYPE extends Plan> {
|
||||
return new PatternMatcher<>(pattern, defaultPromise, matchedAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as thenApply, but catch all exception and return null
|
||||
*/
|
||||
public <OUTPUT_TYPE extends Plan> PatternMatcher<INPUT_TYPE, OUTPUT_TYPE> thenApplyNoThrow(
|
||||
MatchedAction<INPUT_TYPE, OUTPUT_TYPE> matchedAction) {
|
||||
MatchedAction<INPUT_TYPE, OUTPUT_TYPE> adaptMatchedAction = ctx -> {
|
||||
try {
|
||||
return matchedAction.apply(ctx);
|
||||
} catch (Exception ex) {
|
||||
LOG.warn("nereids apply rule failed, because {}", ex.getMessage(), ex);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return new PatternMatcher<>(pattern, defaultPromise, adaptMatchedAction);
|
||||
}
|
||||
|
||||
public <OUTPUT_TYPE extends Plan> PatternMatcher<INPUT_TYPE, OUTPUT_TYPE> thenMulti(
|
||||
Function<INPUT_TYPE, List<OUTPUT_TYPE>> matchedAction) {
|
||||
MatchedMultiAction<INPUT_TYPE, OUTPUT_TYPE> adaptMatchedAction = ctx -> matchedAction.apply(ctx.root);
|
||||
|
||||
@ -105,7 +105,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
return ImmutableList.of(
|
||||
// only agg above scan
|
||||
// Aggregate(Scan)
|
||||
logicalAggregate(logicalOlapScan().when(this::shouldSelectIndexWithAgg)).thenApply(ctx -> {
|
||||
logicalAggregate(logicalOlapScan().when(this::shouldSelectIndexWithAgg)).thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalOlapScan> agg = ctx.root;
|
||||
LogicalOlapScan scan = agg.child();
|
||||
SelectResult result = select(
|
||||
@ -140,7 +140,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// filter could push down scan.
|
||||
// Aggregate(Filter(Scan))
|
||||
logicalAggregate(logicalFilter(logicalOlapScan().when(this::shouldSelectIndexWithAgg)))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalFilter<LogicalOlapScan>> agg = ctx.root;
|
||||
LogicalFilter<LogicalOlapScan> filter = agg.child();
|
||||
LogicalOlapScan scan = filter.child();
|
||||
@ -191,7 +191,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// column pruning or other projections such as alias, etc.
|
||||
// Aggregate(Project(Scan))
|
||||
logicalAggregate(logicalProject(logicalOlapScan().when(this::shouldSelectIndexWithAgg)))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalProject<LogicalOlapScan>> agg = ctx.root;
|
||||
LogicalProject<LogicalOlapScan> project = agg.child();
|
||||
LogicalOlapScan scan = project.child();
|
||||
@ -240,7 +240,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// filter could push down and project.
|
||||
// Aggregate(Project(Filter(Scan)))
|
||||
logicalAggregate(logicalProject(logicalFilter(logicalOlapScan()
|
||||
.when(this::shouldSelectIndexWithAgg)))).thenApply(ctx -> {
|
||||
.when(this::shouldSelectIndexWithAgg)))).thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalProject<LogicalFilter<LogicalOlapScan>>> agg = ctx.root;
|
||||
LogicalProject<LogicalFilter<LogicalOlapScan>> project = agg.child();
|
||||
LogicalFilter<LogicalOlapScan> filter = project.child();
|
||||
@ -298,7 +298,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// filter can't push down
|
||||
// Aggregate(Filter(Project(Scan)))
|
||||
logicalAggregate(logicalFilter(logicalProject(logicalOlapScan()
|
||||
.when(this::shouldSelectIndexWithAgg)))).thenApply(ctx -> {
|
||||
.when(this::shouldSelectIndexWithAgg)))).thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalFilter<LogicalProject<LogicalOlapScan>>> agg = ctx.root;
|
||||
LogicalFilter<LogicalProject<LogicalOlapScan>> filter = agg.child();
|
||||
LogicalProject<LogicalOlapScan> project = filter.child();
|
||||
@ -354,7 +354,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// only agg above scan
|
||||
// Aggregate(Repeat(Scan))
|
||||
logicalAggregate(
|
||||
logicalRepeat(logicalOlapScan().when(this::shouldSelectIndexWithAgg))).thenApply(ctx -> {
|
||||
logicalRepeat(logicalOlapScan().when(this::shouldSelectIndexWithAgg))).thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalRepeat<LogicalOlapScan>> agg = ctx.root;
|
||||
LogicalRepeat<LogicalOlapScan> repeat = agg.child();
|
||||
LogicalOlapScan scan = repeat.child();
|
||||
@ -396,7 +396,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// filter could push down scan.
|
||||
// Aggregate(Repeat(Filter(Scan)))
|
||||
logicalAggregate(logicalRepeat(logicalFilter(logicalOlapScan().when(this::shouldSelectIndexWithAgg))))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalRepeat<LogicalFilter<LogicalOlapScan>>> agg = ctx.root;
|
||||
LogicalRepeat<LogicalFilter<LogicalOlapScan>> repeat = agg.child();
|
||||
LogicalFilter<LogicalOlapScan> filter = repeat.child();
|
||||
@ -454,7 +454,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// column pruning or other projections such as alias, etc.
|
||||
// Aggregate(Repeat(Project(Scan)))
|
||||
logicalAggregate(logicalRepeat(logicalProject(logicalOlapScan().when(this::shouldSelectIndexWithAgg))))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalRepeat<LogicalProject<LogicalOlapScan>>> agg = ctx.root;
|
||||
LogicalRepeat<LogicalProject<LogicalOlapScan>> repeat = agg.child();
|
||||
LogicalProject<LogicalOlapScan> project = repeat.child();
|
||||
@ -509,7 +509,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// filter could push down and project.
|
||||
// Aggregate(Repeat(Project(Filter(Scan))))
|
||||
logicalAggregate(logicalRepeat(logicalProject(logicalFilter(logicalOlapScan()
|
||||
.when(this::shouldSelectIndexWithAgg))))).thenApply(ctx -> {
|
||||
.when(this::shouldSelectIndexWithAgg))))).thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalRepeat<LogicalProject
|
||||
<LogicalFilter<LogicalOlapScan>>>> agg = ctx.root;
|
||||
LogicalRepeat<LogicalProject<LogicalFilter<LogicalOlapScan>>> repeat = agg.child();
|
||||
@ -576,7 +576,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
// filter can't push down
|
||||
// Aggregate(Repeat(Filter(Project(Scan))))
|
||||
logicalAggregate(logicalRepeat(logicalFilter(logicalProject(logicalOlapScan()
|
||||
.when(this::shouldSelectIndexWithAgg))))).thenApply(ctx -> {
|
||||
.when(this::shouldSelectIndexWithAgg))))).thenApplyNoThrow(ctx -> {
|
||||
LogicalAggregate<LogicalRepeat<LogicalFilter
|
||||
<LogicalProject<LogicalOlapScan>>>> agg = ctx.root;
|
||||
LogicalRepeat<LogicalFilter<LogicalProject<LogicalOlapScan>>> repeat = agg.child();
|
||||
|
||||
@ -62,7 +62,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
// project with pushdown filter.
|
||||
// Project(Filter(Scan))
|
||||
logicalProject(logicalFilter(logicalOlapScan().when(this::shouldSelectIndexWithoutAgg)))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalProject<LogicalFilter<LogicalOlapScan>> project = ctx.root;
|
||||
LogicalFilter<LogicalOlapScan> filter = project.child();
|
||||
LogicalOlapScan scan = filter.child();
|
||||
@ -82,7 +82,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
// project with filter that cannot be pushdown.
|
||||
// Filter(Project(Scan))
|
||||
logicalFilter(logicalProject(logicalOlapScan().when(this::shouldSelectIndexWithoutAgg)))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalFilter<LogicalProject<LogicalOlapScan>> filter = ctx.root;
|
||||
LogicalProject<LogicalOlapScan> project = filter.child();
|
||||
LogicalOlapScan scan = project.child();
|
||||
@ -101,7 +101,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
// scan with filters could be pushdown.
|
||||
// Filter(Scan)
|
||||
logicalFilter(logicalOlapScan().when(this::shouldSelectIndexWithoutAgg))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalFilter<LogicalOlapScan> filter = ctx.root;
|
||||
LogicalOlapScan scan = filter.child();
|
||||
LogicalOlapScan mvPlan = select(
|
||||
@ -120,7 +120,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
// project and scan.
|
||||
// Project(Scan)
|
||||
logicalProject(logicalOlapScan().when(this::shouldSelectIndexWithoutAgg))
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalProject<LogicalOlapScan> project = ctx.root;
|
||||
LogicalOlapScan scan = project.child();
|
||||
|
||||
@ -139,7 +139,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
// only scan.
|
||||
logicalOlapScan()
|
||||
.when(this::shouldSelectIndexWithoutAgg)
|
||||
.thenApply(ctx -> {
|
||||
.thenApplyNoThrow(ctx -> {
|
||||
LogicalOlapScan scan = ctx.root;
|
||||
|
||||
LogicalOlapScan mvPlan = select(
|
||||
|
||||
Reference in New Issue
Block a user