[Bug](materialized-view) SelectMaterializedIndexWithAggregate do not change plan when match ba… (#26145)

* SelectMaterializedIndexWithAggregate do not change plan when match base index

* forbid table withh alias
This commit is contained in:
Pxl
2023-10-31 14:11:08 +08:00
committed by GitHub
parent 7e6644b1ee
commit 8d7abf60f9
4 changed files with 68 additions and 0 deletions

View File

@ -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 "

View File

@ -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);