From a3b978fafa0f9b4907558a19b3b2ab24946eab4c Mon Sep 17 00:00:00 2001 From: seawinde Date: Thu, 21 Nov 2024 11:30:47 +0800 Subject: [PATCH] fix code cherry pick --- .../nereids/rules/analysis/BindRelation.java | 46 +++++++++++-------- .../mv/AsyncMaterializationContext.java | 1 + .../exploration/mv/MaterializedViewUtils.java | 22 +++++---- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java index 5e049a9d9b393f..d06647ee5153b1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java @@ -244,25 +244,7 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation, } else { // it's a duplicate, unique or hash distribution agg table // add delete sign filter on olap scan if needed - if (!Util.showHiddenColumns() && scan.getTable().hasDeleteSign() - && !ConnectContext.get().getSessionVariable().skipDeleteSign()) { - // table qualifier is catalog.db.table, we make db.table.column - Slot deleteSlot = null; - for (Slot slot : scan.getOutput()) { - if (slot.getName().equals(Column.DELETE_SIGN)) { - deleteSlot = slot; - break; - } - } - Preconditions.checkArgument(deleteSlot != null); - Expression conjunct = new EqualTo(new TinyIntLiteral((byte) 0), deleteSlot); - if (!((OlapTable) table).getEnableUniqueKeyMergeOnWrite()) { - scan = scan.withPreAggStatus( - PreAggStatus.off(Column.DELETE_SIGN + " is used as conjuncts.")); - } - return new LogicalFilter<>(Sets.newHashSet(conjunct), scan); - } - return scan; + return checkAndAddDeleteSignFilter(scan, ConnectContext.get(), (OlapTable) table); } } @@ -370,6 +352,32 @@ private Optional handleMetaTable(TableIf table, UnboundRelation unb return Optional.empty(); } + /** + * Add delete sign filter on olap scan if need. + */ + public static LogicalPlan checkAndAddDeleteSignFilter(LogicalOlapScan scan, ConnectContext connectContext, + OlapTable olapTable) { + if (!Util.showHiddenColumns() && scan.getTable().hasDeleteSign() + && !connectContext.getSessionVariable().skipDeleteSign()) { + // table qualifier is catalog.db.table, we make db.table.column + Slot deleteSlot = null; + for (Slot slot : scan.getOutput()) { + if (slot.getName().equals(Column.DELETE_SIGN)) { + deleteSlot = slot; + break; + } + } + Preconditions.checkArgument(deleteSlot != null); + Expression conjunct = new EqualTo(new TinyIntLiteral((byte) 0), deleteSlot); + if (!olapTable.getEnableUniqueKeyMergeOnWrite()) { + scan = scan.withPreAggStatus(PreAggStatus.off( + Column.DELETE_SIGN + " is used as conjuncts.")); + } + return new LogicalFilter<>(Sets.newHashSet(conjunct), scan); + } + return scan; + } + private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelation, List qualifiedTableName, CascadesContext cascadesContext) { // for create view stmt replace tableName to ctl.db.tableName diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AsyncMaterializationContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AsyncMaterializationContext.java index c148ea330d892e..96d37ad546a7b4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AsyncMaterializationContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AsyncMaterializationContext.java @@ -27,6 +27,7 @@ import org.apache.doris.nereids.rules.exploration.mv.mapping.ExpressionMapping; import org.apache.doris.nereids.trees.plans.ObjectId; import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.PreAggStatus; import org.apache.doris.nereids.trees.plans.RelationId; import org.apache.doris.nereids.trees.plans.algebra.Relation; import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java index 04e27d0e83b1ba..52d9afa48ea57f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java @@ -20,7 +20,7 @@ import org.apache.doris.analysis.Expr; import org.apache.doris.analysis.SlotRef; import org.apache.doris.catalog.Column; -import org.apache.doris.catalog.MTMV; +import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.PartitionType; import org.apache.doris.catalog.TableIf; import org.apache.doris.catalog.constraint.TableIdentifier; @@ -30,6 +30,7 @@ import org.apache.doris.nereids.memo.Group; import org.apache.doris.nereids.memo.StructInfoMap; import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.rules.analysis.BindRelation; import org.apache.doris.nereids.rules.expression.ExpressionNormalization; import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext; import org.apache.doris.nereids.trees.expressions.Alias; @@ -212,19 +213,24 @@ public static List extractStructInfo(Plan plan, Plan originalPlan, C * when query rewrite, because one plan may hit the materialized view repeatedly and the mv scan output * should be different */ - public static Plan generateMvScanPlan(MTMV materializedView, CascadesContext cascadesContext) { - return new LogicalOlapScan( + public static Plan generateMvScanPlan(OlapTable table, long indexId, + List partitionIds, + PreAggStatus preAggStatus, + CascadesContext cascadesContext) { + LogicalOlapScan olapScan = new LogicalOlapScan( cascadesContext.getStatementContext().getNextRelationId(), - materializedView, - materializedView.getFullQualifiers(), + table, + ImmutableList.of(table.getQualifiedDbName()), ImmutableList.of(), - materializedView.getPartitionIds(), - materializedView.getBaseIndexId(), - PreAggStatus.on(), + partitionIds, + indexId, + preAggStatus, ImmutableList.of(), // this must be empty, or it will be used to sample ImmutableList.of(), Optional.empty()); + return BindRelation.checkAndAddDeleteSignFilter(olapScan, cascadesContext.getConnectContext(), + olapScan.getTable()); } /**