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 d005641881..e8fd815654 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 @@ -188,12 +188,13 @@ public class BindRelation extends OneAnalysisRuleFactory { LogicalOlapScan scan; List partIds = getPartitionIds(table, unboundRelation); List tabletIds = unboundRelation.getTabletIds(); - if (!CollectionUtils.isEmpty(partIds)) { + if (!CollectionUtils.isEmpty(partIds) && !unboundRelation.getIndexName().isPresent()) { scan = new LogicalOlapScan(unboundRelation.getRelationId(), (OlapTable) table, tableQualifier, partIds, tabletIds, unboundRelation.getHints(), unboundRelation.getTableSample()); } else { Optional indexName = unboundRelation.getIndexName(); + // For direct mv scan. if (indexName.isPresent()) { OlapTable olapTable = (OlapTable) table; Long indexId = olapTable.getIndexIdByName(indexName.get()); @@ -207,8 +208,10 @@ public class BindRelation extends OneAnalysisRuleFactory { : PreAggStatus.off("For direct index scan."); scan = new LogicalOlapScan(unboundRelation.getRelationId(), - (OlapTable) table, tableQualifier, tabletIds, indexId, - preAggStatus, unboundRelation.getHints(), unboundRelation.getTableSample()); + (OlapTable) table, tableQualifier, tabletIds, + CollectionUtils.isEmpty(partIds) ? ((OlapTable) table).getPartitionIds() : partIds, indexId, + preAggStatus, CollectionUtils.isEmpty(partIds) ? ImmutableList.of() : partIds, + unboundRelation.getHints(), unboundRelation.getTableSample()); } else { scan = new LogicalOlapScan(unboundRelation.getRelationId(), (OlapTable) table, tableQualifier, tabletIds, unboundRelation.getHints(), 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 2e45fa4483..53f775e217 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 @@ -200,8 +200,10 @@ public class MaterializedViewUtils { materializedView, materializedView.getFullQualifiers(), ImmutableList.of(), + materializedView.getPartitionIds(), materializedView.getBaseIndexId(), PreAggStatus.on(), + ImmutableList.of(), // this must be empty, or it will be used to sample ImmutableList.of(), Optional.empty()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java index 76d360ed53..2f0b3b0a76 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java @@ -146,12 +146,12 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan } public LogicalOlapScan(RelationId id, OlapTable table, List qualifier, List tabletIds, - long selectedIndexId, PreAggStatus preAggStatus, List hints, - Optional tableSample) { + List selectedPartitionIds, long selectedIndexId, PreAggStatus preAggStatus, + List specifiedPartitions, List hints, Optional tableSample) { this(id, table, qualifier, Optional.empty(), Optional.empty(), - table.getPartitionIds(), false, tabletIds, + selectedPartitionIds, false, tabletIds, selectedIndexId, true, preAggStatus, - ImmutableList.of(), hints, Maps.newHashMap(), tableSample, true, ImmutableMap.of()); + specifiedPartitions, hints, Maps.newHashMap(), tableSample, true, ImmutableMap.of()); } /**