diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java index 58ccaae34d01073..0e5f6f01b045a03 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java @@ -163,6 +163,8 @@ public class StatementContext implements Closeable { private ShortCircuitQueryContext shortCircuitQueryContext; + private boolean hasMvCandidates = false; + public StatementContext() { this(ConnectContext.get(), null, 0); } @@ -535,4 +537,12 @@ public TableId getTableId(TableIf tableIf) { this.tableIdMapping.put(tableIdentifier, tableId); return tableId; } + + public boolean isHasMvCandidates() { + return hasMvCandidates; + } + + public void setHasMvCandidates(boolean hasMvCandidates) { + this.hasMvCandidates = hasMvCandidates; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java index d10bd685703fc64..e154de0287b91a8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java @@ -140,7 +140,10 @@ private Set getColumnForRangePredicate(Set expressions) { @Override public Cost visitPhysicalFilter(PhysicalFilter filter, PlanContext context) { - double exprCost = expressionTreeCost(filter.getExpressions()); + double exprCost = 0; + if (context.getStatementContext().isHasMvCandidates()) { + exprCost = expressionTreeCost(filter.getExpressions()); + } double filterCostFactor = 0.0001; if (ConnectContext.get() != null) { filterCostFactor = ConnectContext.get().getSessionVariable().filterCostFactor; @@ -349,7 +352,7 @@ public Cost visitPhysicalHashJoin( double leftRowCount = probeStats.getRowCount(); double rightRowCount = buildStats.getRowCount(); - if (leftRowCount == rightRowCount) { + if ((long) leftRowCount == (long) rightRowCount) { // reorder by connectivity to be friendly to runtime filter. if (physicalHashJoin.getGroupExpression().isPresent() && physicalHashJoin.getGroupExpression().get().getOwnerGroup() != null diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java index 5d9f6f85689c831..d33eb8b68a5c1c7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java @@ -104,6 +104,7 @@ public void initMaterializationContext(CascadesContext cascadesContext) { mtmvCache.getLogicalPlan(), mtmvCache.getOriginalPlan(), ImmutableList.of(), ImmutableList.of(), cascadesContext, mtmvCache.getStructInfo().withTableBitSet(tableBitSetInCurrentCascadesContext))); + cascadesContext.getStatementContext().setHasMvCandidates(true); } catch (Exception e) { LOG.warn(String.format("MaterializationContext init mv cache generate fail, current queryId is %s", cascadesContext.getConnectContext().getQueryIdentifier()), e);