[Feature](materialized-view) support match logicalAggregate(logicalProject(logicalFilter(logicalOlapScan())) without agg (#28747)
support match logicalAggregate(logicalProject(logicalFilter(logicalOlapScan())) without agg
This commit is contained in:
@ -108,7 +108,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean containAllRequiredColumns(MaterializedIndex index, LogicalOlapScan scan,
|
||||
protected static boolean containAllRequiredColumns(MaterializedIndex index, LogicalOlapScan scan,
|
||||
Set<Slot> requiredScanOutput, Set<? extends Expression> requiredExpr, Set<Expression> predicateExpr) {
|
||||
OlapTable table = scan.getTable();
|
||||
MaterializedIndexMeta meta = table.getIndexMetaByIndexId(index.getId());
|
||||
@ -177,7 +177,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
* 1. find matching key prefix most.
|
||||
* 2. sort by row count, column count and index id.
|
||||
*/
|
||||
protected long selectBestIndex(
|
||||
protected static long selectBestIndex(
|
||||
List<MaterializedIndex> candidates,
|
||||
LogicalOlapScan scan,
|
||||
Set<Expression> predicates) {
|
||||
@ -212,7 +212,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
return CollectionUtils.isEmpty(sortedIndexIds) ? scan.getTable().getBaseIndexId() : sortedIndexIds.get(0);
|
||||
}
|
||||
|
||||
protected List<MaterializedIndex> matchPrefixMost(
|
||||
protected static List<MaterializedIndex> matchPrefixMost(
|
||||
LogicalOlapScan scan,
|
||||
List<MaterializedIndex> candidate,
|
||||
Set<Expression> predicates,
|
||||
@ -238,7 +238,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
* Filter the input conjuncts those can use prefix and split into 2 groups: is equal-to or non-equal-to predicate
|
||||
* when comparing the key column.
|
||||
*/
|
||||
private Map<Boolean, Set<String>> filterCanUsePrefixIndexAndSplitByEquality(
|
||||
private static Map<Boolean, Set<String>> filterCanUsePrefixIndexAndSplitByEquality(
|
||||
Set<Expression> conjuncts, Map<ExprId, String> exprIdToColName) {
|
||||
return conjuncts.stream()
|
||||
.map(expr -> PredicateChecker.canUsePrefixIndex(expr, exprIdToColName))
|
||||
@ -332,7 +332,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Matching key prefix
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
private List<MaterializedIndex> matchKeyPrefixMost(
|
||||
private static List<MaterializedIndex> matchKeyPrefixMost(
|
||||
OlapTable table,
|
||||
List<MaterializedIndex> indexes,
|
||||
Set<String> equalColumns,
|
||||
@ -350,7 +350,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
return collect.descendingMap().firstEntry().getValue();
|
||||
}
|
||||
|
||||
private int indexKeyPrefixMatchCount(
|
||||
private static int indexKeyPrefixMatchCount(
|
||||
OlapTable table,
|
||||
MaterializedIndex index,
|
||||
Set<String> equalColNames,
|
||||
@ -370,7 +370,7 @@ public abstract class AbstractSelectMaterializedIndexRule {
|
||||
return matchCount;
|
||||
}
|
||||
|
||||
protected boolean preAggEnabledByHint(LogicalOlapScan olapScan) {
|
||||
protected static boolean preAggEnabledByHint(LogicalOlapScan olapScan) {
|
||||
return olapScan.getHints().stream().anyMatch("PREAGGOPEN"::equalsIgnoreCase);
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ import org.apache.doris.nereids.parser.NereidsParser;
|
||||
import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.rules.RuleType;
|
||||
import org.apache.doris.nereids.rules.rewrite.RewriteRuleFactory;
|
||||
import org.apache.doris.nereids.rules.rewrite.mv.AbstractSelectMaterializedIndexRule.SlotContext;
|
||||
import org.apache.doris.nereids.trees.expressions.Alias;
|
||||
import org.apache.doris.nereids.trees.expressions.Cast;
|
||||
import org.apache.doris.nereids.trees.expressions.ExprId;
|
||||
@ -266,6 +267,20 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
|
||||
LogicalOlapScan mvPlan = createLogicalOlapScan(scan, result);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
LogicalOlapScan mvPlanWithoutAgg = SelectMaterializedIndexWithoutAggregate.select(scan,
|
||||
project::getInputSlots, filter::getConjuncts,
|
||||
Stream.concat(filter.getExpressions().stream(),
|
||||
project.getExpressions().stream())
|
||||
.collect(ImmutableSet.toImmutableSet()));
|
||||
SlotContext slotContextWithoutAgg = generateBaseScanExprToMvExpr(mvPlanWithoutAgg);
|
||||
|
||||
return agg.withChildren(new LogicalProject(
|
||||
generateProjectsAlias(project.getOutput(), slotContextWithoutAgg),
|
||||
new ReplaceExpressions(slotContextWithoutAgg).replace(
|
||||
project.withChildren(filter.withChildren(mvPlanWithoutAgg)),
|
||||
mvPlanWithoutAgg)));
|
||||
}
|
||||
|
||||
if (result.exprRewriteMap.isEmpty()) {
|
||||
return new LogicalProject<>(
|
||||
|
||||
@ -165,7 +165,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
* @param predicatesSupplier Supplier to get pushdown predicates.
|
||||
* @return Result scan node.
|
||||
*/
|
||||
private LogicalOlapScan select(
|
||||
public static LogicalOlapScan select(
|
||||
LogicalOlapScan scan,
|
||||
Supplier<Set<Slot>> requiredScanOutputSupplier,
|
||||
Supplier<Set<Expression>> predicatesSupplier,
|
||||
@ -237,7 +237,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSameDataType(LogicalOlapScan scan, long selectIndex, Set<Slot> slots) {
|
||||
private static boolean isSameDataType(LogicalOlapScan scan, long selectIndex, Set<Slot> slots) {
|
||||
if (selectIndex != scan.getTable().getBaseIndexId()) {
|
||||
Map<String, PrimitiveType> columnTypes =
|
||||
scan.getTable().getSchemaByIndexId(selectIndex).stream().collect(Collectors
|
||||
@ -252,7 +252,7 @@ public class SelectMaterializedIndexWithoutAggregate extends AbstractSelectMater
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean indexHasAggregate(MaterializedIndex index, LogicalOlapScan scan) {
|
||||
private static boolean indexHasAggregate(MaterializedIndex index, LogicalOlapScan scan) {
|
||||
return scan.getTable().getSchemaByIndexId(index.getId())
|
||||
.stream()
|
||||
.anyMatch(Column::isAggregated);
|
||||
|
||||
Reference in New Issue
Block a user