From 85d0a2196931841f78a17c1d76c4fb34bd35cbe4 Mon Sep 17 00:00:00 2001 From: seawinde Date: Thu, 11 Dec 2025 20:06:32 +0800 Subject: [PATCH 1/3] [fix](mtmv) Fix mv rewrite failed when mv is rewritten by LimitAggToTopNAgg but query is not --- .../rules/exploration/mv/PreMaterializedViewRewriter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java index 5eb4f82f0e3a8b..26880603219e9b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java @@ -69,6 +69,8 @@ public class PreMaterializedViewRewriter { NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.PROCESS_SCALAR_AGG_MUST_USE_MULTI_DISTINCT.ordinal()); NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.ELIMINATE_GROUP_BY_KEY_BY_UNIFORM.ordinal()); NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.SALT_JOIN.ordinal()); + // this would add extra order keys in topN, which may cause mv rewrite fail, so need pre rewrite + NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.LIMIT_AGG_TO_TOPN_AGG.ordinal()); } /** From 7f01f36ec5a22ebbf02243149ca289a5ff4d8dbb Mon Sep 17 00:00:00 2001 From: seawinde Date: Fri, 12 Dec 2025 11:31:48 +0800 Subject: [PATCH 2/3] fix fuzzy variable bigger to make test case stable --- .../rules/exploration/mv/PreMaterializedViewRewriter.java | 2 -- .../src/main/java/org/apache/doris/qe/SessionVariable.java | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java index 26880603219e9b..5eb4f82f0e3a8b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/PreMaterializedViewRewriter.java @@ -69,8 +69,6 @@ public class PreMaterializedViewRewriter { NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.PROCESS_SCALAR_AGG_MUST_USE_MULTI_DISTINCT.ordinal()); NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.ELIMINATE_GROUP_BY_KEY_BY_UNIFORM.ordinal()); NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.SALT_JOIN.ordinal()); - // this would add extra order keys in topN, which may cause mv rewrite fail, so need pre rewrite - NEED_PRE_REWRITE_RULE_TYPES.set(RuleType.LIMIT_AGG_TO_TOPN_AGG.ordinal()); } /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 5e51b0ee374277..16f39c116a4649 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -3285,8 +3285,11 @@ public void initFuzzyModeVariables() { } this.runtimeFilterWaitInfinitely = random.nextBoolean(); - // set random 1, 10, 100, 1000, 10000 - this.topnOptLimitThreshold = (int) Math.pow(10, random.nextInt(5)); + // set random 101, 100, 1000, 10000, should be greater than 100, because small limit may lead + // some test case failed, e.g. topN with limit 100 may not hit the LimitAggToTopNAgg rule + // optimization when fuzzy + int randomLimitThreshold = (int) Math.pow(10, random.nextInt(5)); + this.topnOptLimitThreshold = randomLimitThreshold <= 100 ? 101 : randomLimitThreshold; // for spill to disk if (Config.fuzzy_test_type.equals("p0")) { From 9d6d48cfa24b183c75773507aac862d3e58fcdce Mon Sep 17 00:00:00 2001 From: seawinde Date: Fri, 12 Dec 2025 14:29:11 +0800 Subject: [PATCH 3/3] add log to position problem --- .../agg_optimize_when_uniform.groovy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/regression-test/suites/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.groovy b/regression-test/suites/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.groovy index 462ddbeb04d9d5..4fe8242eebbc3b 100644 --- a/regression-test/suites/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.groovy @@ -379,6 +379,10 @@ suite("agg_optimize_when_uniform") { def plan_6 = sql """explain verbose ${query6_0}""" logger.info("plan_6 is " + plan_6) + // This line of code is modified to position the occasional error: "null value is not in not null slot". + def query_mv6 = sql """select sum(__bin_4 is null) from mv6_0""" + logger.info("query_mv6 is " + query_mv6) + order_qt_query6_0_after "${query6_0}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv6_0"""