From b9912c904516163626a9ee2392b10a8310e9bb22 Mon Sep 17 00:00:00 2001 From: shuke <37901441+shuke987@users.noreply.github.com> Date: Sun, 12 Jul 2026 11:08:58 +0800 Subject: [PATCH 1/2] [fix](regression) Stabilize sync MV selection in MTMV test ### What problem does this PR solve? Issue Number: close #xxx Related PR: #37396 Problem Summary: The test verifies that an async MTMV can read a sync rollup and resolve its partition column back to the base table. After the old non-cost-based sync MV control was removed, TRY_IN_RBO could successfully generate the rollup candidate while cost-based planning still selected the base index. Add USE_MV to both the precondition query and the MTMV definition so the test deterministically exercises the intended sync-rollup path. ### Release note None ### Check List (For Author) - Test: Groovy parse and git diff --check - Regression test syntax validation - Behavior changed: No - Does this need documentation: No --- .../suites/rollup_p0/test_create_mv_and_mtmv.groovy | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy b/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy index b8c3639fb42841..1efa00f71be4ee 100644 --- a/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy +++ b/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy @@ -52,9 +52,10 @@ suite("test_create_mv_and_mtmv") { dt; """) + // The MTMV must read the sync MV to cover partition-column resolution through the rollup. explain { sql(""" - SELECT dt,advertiser, + SELECT /*+ use_mv(${tableName}.${mvName}) */ dt,advertiser, count(DISTINCT user_id) FROM ${tableName} GROUP BY dt,advertiser""") @@ -68,7 +69,7 @@ suite("test_create_mv_and_mtmv") { DISTRIBUTED BY RANDOM BUCKETS 1 PROPERTIES ('replication_num' = '1') AS - select dt, advertiser, count(distinct user_id) + select /*+ use_mv(${tableName}.${mvName}) */ dt, advertiser, count(distinct user_id) from ${tableName} group by dt, advertiser; """ @@ -109,4 +110,4 @@ AND RefreshMode = '${refreshMode}';""" sql """ DROP TABLE IF EXISTS ${tableName} """ sql """ DROP MATERIALIZED VIEW IF EXISTS ${mtmvName} """ -} \ No newline at end of file +} From d50254df0880e227ccb2c74440b88509dd49c06e Mon Sep 17 00:00:00 2001 From: shuke <37901441+shuke987@users.noreply.github.com> Date: Wed, 15 Jul 2026 17:53:16 +0800 Subject: [PATCH 2/2] test(regression): verify MTMV rewrite cache --- .../suites/rollup_p0/test_create_mv_and_mtmv.groovy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy b/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy index 1efa00f71be4ee..67fd5548b668ca 100644 --- a/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy +++ b/regression-test/suites/rollup_p0/test_create_mv_and_mtmv.groovy @@ -95,6 +95,14 @@ AND RefreshMode = '${refreshMode}';""" wait_mtmv_refresh_finish("COMPLETE") qt_mtmv_init """ SELECT * FROM ${mtmvName} ORDER BY dt, advertiser""" + // Verify that the MTMV definition can build a rewrite cache and produce a rewrite candidate. + // The final CBO choice is intentionally not asserted because either valid plan may be cheaper. + mv_rewrite_success_without_check_chosen(""" + SELECT dt, advertiser, count(distinct user_id) + FROM ${tableName} + GROUP BY dt, advertiser + """, mtmvName) + sql """INSERT INTO ${tableName} VALUES("2024-07-03",'b', "2024-07-03", 'b',2);""" refreshTime = (int) (System.currentTimeMillis() / 1000L) sql """REFRESH MATERIALIZED VIEW ${mtmvName} AUTO;"""