[Bug](materialized-view) SelectMaterializedIndexWithAggregate do not … (#26192)
SelectMaterializedIndexWithAggregate do not change plan when match base index
This commit is contained in:
@ -298,6 +298,9 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
if (tableRefList.size() != 1) {
|
||||
throw new AnalysisException("The materialized view only support one table in from clause.");
|
||||
}
|
||||
if (!isReplay && tableRefList.get(0).hasExplicitAlias()) {
|
||||
throw new AnalysisException("The materialized view not support table with alias.");
|
||||
}
|
||||
TableName tableName = tableRefList.get(0).getName();
|
||||
if (tableName == null) {
|
||||
throw new AnalysisException("table in from clause is invalid, please check if it's single table "
|
||||
|
||||
@ -116,6 +116,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
agg.getGroupByExpressions(),
|
||||
new HashSet<>(agg.getExpressions()));
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan = scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
|
||||
@ -162,6 +166,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
requiredExpr
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -207,6 +215,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
collectRequireExprWithAggAndProject(agg.getExpressions(), project.getProjects())
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -265,6 +277,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
requiredExpr
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -322,6 +338,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
requiredExpr
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -369,6 +389,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
nonVirtualGroupByExprs(agg),
|
||||
new HashSet<>(agg.getExpressions()));
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan = scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
|
||||
@ -422,6 +446,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
requiredExpr
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -474,6 +502,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
collectRequireExprWithAggAndProject(agg.getExpressions(), project.getProjects())
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -539,6 +571,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
requiredExpr
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
@ -605,6 +641,10 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
requiredExpr
|
||||
);
|
||||
|
||||
if (result.indexId == scan.getTable().getBaseIndexId()) {
|
||||
return ctx.root;
|
||||
}
|
||||
|
||||
LogicalOlapScan mvPlan =
|
||||
scan.withMaterializedIndexSelected(result.preAggStatus, result.indexId);
|
||||
SlotContext slotContext = generateBaseScanExprToMvExpr(mvPlan);
|
||||
|
||||
@ -178,12 +178,8 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Utils.toSqlString("LogicalOlapScan",
|
||||
"qualified", qualifiedName(),
|
||||
"indexName", getSelectedMaterializedIndexName().orElse("<index_not_selected>"),
|
||||
"selectedIndexId", selectedIndexId,
|
||||
"preAgg", preAggStatus
|
||||
);
|
||||
return Utils.toSqlString("LogicalOlapScan", "qualified", qualifiedName(), "indexName",
|
||||
getSelectedMaterializedIndexName(), "selectedIndexId", selectedIndexId, "preAgg", preAggStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -291,9 +287,8 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public Optional<String> getSelectedMaterializedIndexName() {
|
||||
return indexSelected ? Optional.ofNullable(((OlapTable) table).getIndexNameById(selectedIndexId))
|
||||
: Optional.empty();
|
||||
public String getSelectedMaterializedIndexName() {
|
||||
return ((OlapTable) table).getIndexNameById(selectedIndexId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user