From c67bbe77efdf7c390ce1ced2486630616df3c815 Mon Sep 17 00:00:00 2001 From: seawinde Date: Wed, 19 Mar 2025 17:42:00 +0800 Subject: [PATCH] [test](mtmv) Fix regression test not stable and add log for debug (#48483) (#49234) --- .../org/apache/doris/mtmv/MTMVPartitionUtil.java | 6 ++++++ .../mv/AbstractMaterializedViewRule.java | 11 +++++++++++ .../testSelectMVWithTableAlias.out | 4 +++- .../test_mv_useless/test_dup_mv_useless.groovy | 11 +++++++---- .../testSelectMVWithTableAlias.groovy | 5 +++-- .../mv/union_rewrite/usercase_union_rewrite.groovy | 13 +++++++++++++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java index 94cd34195a..5aa213b096 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java @@ -325,6 +325,12 @@ public class MTMVPartitionUtil { for (String relatedPartitionName : relatedPartitionNames) { MTMVSnapshotIf relatedPartitionCurrentSnapshot = relatedTable .getPartitionSnapshot(relatedPartitionName, context, Optional.empty()); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("isSyncWithPartitions mvName is %s\n, mtmvPartitionName is %s\n, " + + "mtmv refreshSnapshot is %s\n, relatedPartitionName is %s\n, " + + "relatedPartitionCurrentSnapshot is %s", mtmv.getName(), mtmvPartitionName, + mtmv.getRefreshSnapshot(), relatedPartitionName, relatedPartitionCurrentSnapshot)); + } if (!mtmv.getRefreshSnapshot() .equalsWithRelatedPartition(mtmvPartitionName, relatedPartitionName, relatedPartitionCurrentSnapshot)) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java index 8bff4ca0f0..33acf462fb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java @@ -495,6 +495,17 @@ public abstract class AbstractMaterializedViewRule implements ExplorationRuleFac // if mv can not offer any partition for query, query rewrite bail out return null; } + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("calcInvalidPartitions mv name is %s,\n mvValidBaseTablePartitionNameSet is %s,\n " + + "mvValidHasDataRelatedBaseTableNameSet is %s,\n" + + "queryUsedBaseTablePartitionNameSet is %s,\n " + + "partitionMapping is %s \n, sql hash is %s", + materializationContext.generateMaterializationIdentifier(), + mvValidBaseTablePartitionNameSet, + mvValidHasDataRelatedBaseTableNameSet, + queryUsedBaseTablePartitionNameSet, + partitionMapping, cascadesContext.getConnectContext().getSqlHash())); + } // Check when mv partition relates base table partition data change or delete partition Set rewrittenPlanUsePartitionNameSet = new HashSet<>(); List mvOlapScanList = rewrittenPlan.collectToList(node -> diff --git a/regression-test/data/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.out b/regression-test/data/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.out index 30b1f06fdf..c9a0b41ab7 100644 --- a/regression-test/data/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.out +++ b/regression-test/data/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.out @@ -2,8 +2,10 @@ -- !select_star -- 2020-01-01 1 a 1 2020-01-01 1 a 1 +2020-01-01 1 a 1 +2020-01-02 2 b 2 2020-01-02 2 b 2 -- !select_mv -- -3 +5 diff --git a/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy b/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy index 7640b6e180..99f2792384 100644 --- a/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy +++ b/regression-test/suites/mv_p0/test_mv_useless/test_dup_mv_useless.groovy @@ -16,6 +16,9 @@ // under the License. suite ("test_dup_mv_useless") { + + String db = context.config.getDbNameByFile(context.file) + sql "use ${db}" def testTable = "test_dup_mv_useless_table" def getJobState = { tableName -> def jobStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE TableName='${testTable}' ORDER BY CreateTime DESC LIMIT 1; """ @@ -43,9 +46,9 @@ suite ("test_dup_mv_useless") { exception "errCode = 2," } - createMV("create materialized view k1_u1 as select k1 from ${testTable} group by k1;") - createMV("create materialized view k1_k2_u12 as select k1,k2 from ${testTable} group by k1,k2;") - createMV("create materialized view k1_k2_u21 as select k2,k1 from ${testTable} group by k2,k1 order by k2,k1;") - createMV("create materialized view k1_k2_sumk3 as select k1,k2,sum(k3) from ${testTable} group by k1,k2;") + create_sync_mv(db, testTable, "k1_u1", "select k1 from ${testTable} group by k1;") + create_sync_mv(db, testTable, "k1_k2_u12", "select k1,k2 from ${testTable} group by k1,k2;") + create_sync_mv(db, testTable, "k1_k2_u21", "select k2,k1 from ${testTable} group by k2,k1 order by k2,k1;") + create_sync_mv(db, testTable, "k1_k2_sumk3", "select k1,k2,sum(k3) from ${testTable} group by k1,k2;") sql "insert into ${testTable} select 4,4,4;" } diff --git a/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy b/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy index 9e3bd886b3..dc1e41b9b2 100644 --- a/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy +++ b/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy @@ -29,9 +29,9 @@ suite ("testSelectMVWithTableAlias") { partition by range (time_col) (partition p1 values less than MAXVALUE) distributed by hash(time_col) buckets 3 properties('replication_num' = '1'); """ - sql """alter table user_tags modify column time_col set stats ('row_count'='3');""" - sql """insert into user_tags values("2020-01-01",1,"a",1);""" + sql """insert into user_tags values("2020-01-01",1,"a",1);""" + sql """insert into user_tags values("2020-01-02",2,"b",2);""" sql """insert into user_tags values("2020-01-02",2,"b",2);""" createMV("create materialized view user_tags_mv as select user_id, count(tag_id) from user_tags group by user_id;") @@ -39,6 +39,7 @@ suite ("testSelectMVWithTableAlias") { sql """insert into user_tags values("2020-01-01",1,"a",1);""" sql "analyze table user_tags with sync;" + sql """alter table user_tags modify column time_col set stats ('row_count'='5');""" mv_rewrite_all_fail("select * from user_tags order by time_col;", ["user_tags_mv"]) diff --git a/regression-test/suites/nereids_rules_p0/mv/union_rewrite/usercase_union_rewrite.groovy b/regression-test/suites/nereids_rules_p0/mv/union_rewrite/usercase_union_rewrite.groovy index dbbc6f929e..a90b7a9804 100644 --- a/regression-test/suites/nereids_rules_p0/mv/union_rewrite/usercase_union_rewrite.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/union_rewrite/usercase_union_rewrite.groovy @@ -76,8 +76,21 @@ suite ("usercase_union_rewrite") { insert into orders_user values (1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'), (1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'), + (1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'), + (1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'), + (1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'), + (1, 3, 'o', 99.5, 'a', 'b', null, 'yy', '2023-10-19'), (2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'), (2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'), + (2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'), + (2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'), + (2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'), + (2, 1, 'o', 109.2, 'c','d',2, null, '2023-10-18'), + (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), + (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), + (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), + (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), + (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), (3, 2, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-17'), (4, 5, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-19');