From fd4e9a82f0eb6303056df3d037317c3389d804ca Mon Sep 17 00:00:00 2001 From: seawinde <149132972+seawinde@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:39:56 +0800 Subject: [PATCH] Pick some pr from master to 3.0 (#40871) #41145 (#42303) ## Proposed changes pr: https://github.com/apache/doris/pull/40871 commitId: da6ac0c5 pr: https://github.com/apache/doris/pull/41145 commitId: 5e6e4bf6 --- .../trees/plans/logical/LogicalOlapScan.java | 33 +- .../agg_optimize_when_uniform.out | 4 +- .../data/nereids_syntax_p0/mv/ut/MVWithAs.out | 6 +- .../doris/regression/suite/Suite.groovy | 345 +++++++++++++++--- .../test_create_table_like_nereids.groovy | 7 +- .../suites/mtmv_p0/test_create_mv_mtmv.groovy | 4 +- .../mtmv_p0/test_create_rollup_mtmv.groovy | 4 +- .../agg_have_dup_base.groovy | 43 +-- .../diffrent_serialize.groovy | 25 +- .../agg_state/test_agg_state_max_by.groovy | 40 +- .../mv_p0/case_ignore/case_ignore.groovy | 20 +- .../suites/mv_p0/count_star/count_star.groovy | 43 +-- .../suites/mv_p0/k1ap2spa/k1ap2spa.groovy | 11 +- .../k1s2m3_auto_inc/k1s2m3_auto_inc.groovy | 10 +- .../multi_agg_with_same_slot.groovy | 44 +-- .../multi_slot_k123p/multi_slot_k123p.groovy | 10 +- .../multi_slot_k1a2p2ap3p.groovy | 11 +- .../multi_slot_k1a2p2ap3ps.groovy | 21 +- .../multi_slot_k1p2ap3p.groovy | 10 +- .../multi_slot_k1p2ap3ps.groovy | 10 +- .../multi_slot_multi_mv.groovy | 10 +- .../mv_p0/mv_with_view/mv_with_view.groovy | 30 +- .../mv_p0/null_insert/null_insert.groovy | 14 +- .../routine_load_hll/routine_load_hll.groovy | 10 +- .../multiple_no_where.groovy | 9 +- .../ssb/multiple_ssb/multiple_ssb.groovy | 83 ++--- .../suites/mv_p0/ssb/q_2_1/q_2_1.groovy | 7 +- .../suites/mv_p0/ssb/q_4_1/q_4_1.groovy | 7 +- .../suites/mv_p0/ssb/q_4_1_r1/q_4_1_r1.groovy | 16 +- .../suites/mv_p0/sum_count/sum_count.groovy | 2 +- .../sum_divede_count/sum_devide_count.groovy | 40 +- .../suites/mv_p0/test_28741/test_28741.groovy | 10 +- .../test_approx_count_distinct.groovy | 30 +- .../suites/mv_p0/test_base/test_base.groovy | 20 +- .../mv_p0/test_casewhen/test_casewhen.groovy | 10 +- .../mv_p0/test_doc_e4/test_doc_e4.groovy | 46 +-- .../test_dup_group_by_mv_abs.groovy | 21 +- .../test_dup_group_by_mv_plus.groovy | 20 +- .../test_dup_mv_abs/test_dup_mv_abs.groovy | 70 +--- .../test_dup_mv_bin/test_dup_mv_bin.groovy | 70 +--- .../test_dup_mv_bitmap_hash.groovy | 20 +- .../test_dup_mv_expr_priority.groovy | 14 +- .../test_dup_mv_plus/test_dup_mv_plus.groovy | 95 ++--- .../test_dup_mv_repeat.groovy | 12 +- .../test_dup_mv_year/test_dup_mv_year.groovy | 20 +- .../test_insert_multi.groovy | 11 +- .../suites/mv_p0/test_mv_dp/test_mv_dp.groovy | 14 +- .../mv_p0/test_mv_mor/test_mv_mor.groovy | 5 +- .../mv_p0/test_mv_mow/test_mv_mow.groovy | 10 +- .../suites/mv_p0/test_ndv/test_ndv.groovy | 31 +- .../suites/mv_p0/test_nvl/test_nvl.groovy | 42 +-- .../suites/mv_p0/test_o2/test_o2.groovy | 12 +- .../mv_p0/test_substr/test_substr.groovy | 12 +- .../mv_p0/test_tbl_name/test_tbl_name.groovy | 28 +- .../test_upper_alias/test_upper_alias.groovy | 32 +- .../test_user_activity.groovy | 12 +- .../suites/mv_p0/unique/unique.groovy | 10 +- .../testAggQueryOnAggMV1.groovy | 4 +- .../testAggQueryOnAggMV10.groovy | 22 +- .../testAggQueryOnAggMV11.groovy | 21 +- .../testAggQueryOnAggMV2.groovy | 22 +- .../testAggQueryOnAggMV3.groovy | 37 +- .../testAggQuqeryOnAggMV5.groovy | 22 +- .../testAggQuqeryOnAggMV6.groovy | 22 +- .../testAggQuqeryOnAggMV7.groovy | 20 +- ...testAggregateMVCalcAggFunctionQuery.groovy | 22 +- .../testBitmapUnionInQuery.groovy | 34 +- .../testCountDistinctToBitmap.groovy | 46 +-- .../testIncorrectMVRewriteInSubquery.groovy | 24 +- .../testIncorrectRewriteCountDistinct.groovy | 22 +- .../testJoinOnLeftProjectToJoin.groovy | 15 +- .../mv_p0/ut/testNDVToHll/testNDVToHll.groovy | 31 +- .../testOrderByQueryOnProjectView.groovy | 22 +- .../testProjectionMV1.groovy | 46 +-- .../testProjectionMV2.groovy | 32 +- .../testProjectionMV3.groovy | 32 +- .../testProjectionMV4.groovy | 21 +- .../testSelectMVWithTableAlias.groovy | 2 +- .../testSingleMVMultiUsage.groovy | 11 +- .../mv_p0/ut/testSubQuery/testSubQuery.groovy | 10 +- .../testUnionDistinct.groovy | 12 +- .../suites/mv_p0/where/k123/k123.groovy | 83 ++--- .../where/k123_nereids/k123_nereids.groovy | 12 +- .../suites/mv_p0/where/mvljc/mvljc.groovy | 24 +- .../mv/agg_on_none_agg/agg_on_none_agg.groovy | 9 - .../agg_optimize_when_uniform.groovy | 9 - .../mv/agg_variety/agg_variety.groovy | 9 - .../aggregate_with_roll_up.groovy | 33 +- .../aggregate_without_roll_up.groovy | 10 - .../mv/availability/grace_period.groovy | 123 +++---- .../materialized_view_switch.groovy | 9 - .../mv/dimension/dimension_1.groovy | 242 +++--------- .../mv/dimension/dimension_2_3.groovy | 89 +---- .../mv/dimension/dimension_2_4.groovy | 120 ++---- .../mv/dimension/dimension_2_5.groovy | 67 +--- .../mv/dimension/dimension_2_6.groovy | 76 +--- .../mv/dimension/dimension_2_full_join.groovy | 164 ++------- .../dimension/dimension_2_inner_join.groovy | 154 ++------ .../dimension_2_left_anti_join.groovy | 94 +---- .../mv/dimension/dimension_2_left_join.groovy | 154 ++------ .../dimension_2_left_semi_join.groovy | 94 +---- .../dimension_2_right_anti_join.groovy | 94 +---- .../dimension/dimension_2_right_join.groovy | 154 ++------ .../dimension_2_right_semi_join.groovy | 94 +---- .../mv/dimension/dimension_self_conn.groovy | 161 ++------ .../dimension_2_join_agg.groovy | 52 +-- .../dimension_join_agg_negative.groovy | 24 +- .../filter_equal_or_notequal.groovy | 198 ++-------- .../full_join_filter.groovy | 119 ++---- .../inner_join_filter.groovy | 120 ++---- .../left_anti_join_filter.groovy | 114 +----- .../left_join_filter.groovy | 134 ++----- .../left_semi_join_filter.groovy | 114 +----- .../right_anti_join_filter.groovy | 114 +----- .../right_join_filter.groovy | 134 ++----- .../right_semi_join_filter.groovy | 112 +----- .../mv/direct_query/direct_query.groovy | 2 - .../dml_query_has_external_table.groovy | 32 +- .../insert/dml_insert_and_overwrite.groovy | 50 +-- .../mv/dml/outfile/dml_into_outfile.groovy | 31 +- .../mv_contain_external_table.groovy | 30 +- .../part_partition_invalid.groovy | 117 ++---- .../single_external_table.groovy | 4 +- .../mv/grouping_sets/grouping_sets.groovy | 9 - .../join/dphyp_inner/inner_join_dphyp.groovy | 2 - .../join/dphyp_outer/outer_join_dphyp.groovy | 2 - .../mv/join/inner/inner_join.groovy | 2 - .../mv/join/left_outer/outer_join.groovy | 3 - .../inner_join_infer_and_derive.groovy | 47 +-- .../left_join_infer_and_derive.groovy | 26 +- .../right_join_infer_and_derive.groovy | 27 +- .../mv/negative/negative_test.groovy | 218 +++-------- .../mv/nested/nested_materialized_view.groovy | 65 +--- .../mv/nested_mtmv/nested_mtmv.groovy | 78 +--- .../mv/partition_mv_rewrite.groovy | 134 +++---- .../mv/same_name/sync_async_same_name.groovy | 56 +-- .../mv/scan/scan_table.groovy | 2 - .../single_table_without_aggregate.groovy | 5 +- .../union_all_compensate.groovy | 31 +- .../partition_curd_union_rewrite.groovy | 13 +- .../usercase_union_rewrite.groovy | 19 +- .../unsafe_equals/null_un_safe_equals.groovy | 5 - .../with_auth/with_select_table_auth.groovy | 22 +- .../mv/aggregate/agg_sync_mv.groovy | 9 +- .../mv/newMv/case_ignore.groovy | 20 +- .../mv/newMv/dup_gb_mv_abs.groovy | 20 +- .../mv/newMv/dup_gb_mv_plus.groovy | 20 +- .../mv/newMv/dup_mv_abs.groovy | 70 +--- .../mv/newMv/dup_mv_bin.groovy | 70 +--- .../mv/newMv/dup_mv_bm_hash.groovy | 20 +- .../mv/newMv/dup_mv_plus.groovy | 60 +-- .../mv/newMv/dup_mv_year.groovy | 20 +- .../mv/newMv/multi_slot1.groovy | 10 +- .../mv/newMv/multi_slot2.groovy | 23 +- .../mv/newMv/multi_slot3.groovy | 10 +- .../mv/newMv/multi_slot4.groovy | 10 +- .../mv/newMv/multi_slot5.groovy | 10 +- .../mv/newMv/multi_slot6.groovy | 10 +- .../mv/newMv/mv_with_view.groovy | 30 +- .../mv/newMv/single_slot.groovy | 6 +- .../mv/newMv/sum_devide_count.groovy | 46 +-- .../mv/newMv/unique_mv.groovy | 11 +- .../mv/ut/MVMultiUsage.groovy | 10 +- .../nereids_syntax_p0/mv/ut/MVWithAs.groovy | 25 +- .../mv/ut/aggMVCalcAggFun.groovy | 22 +- .../mv/ut/aggOnAggMV1.groovy | 21 +- .../mv/ut/aggOnAggMV10.groovy | 22 +- .../mv/ut/aggOnAggMV11.groovy | 22 +- .../mv/ut/aggOnAggMV2.groovy | 21 +- .../mv/ut/aggOnAggMV3.groovy | 24 +- .../mv/ut/aggOnAggMV5.groovy | 2 +- .../mv/ut/aggOnAggMV6.groovy | 22 +- .../mv/ut/aggOnAggMV7.groovy | 22 +- .../mv/ut/bitmapUnionIn.groovy | 22 +- .../mv/ut/incMVReInSub.groovy | 23 +- .../mv/ut/incRewriteCD.groovy | 20 +- .../mv/ut/joinOnCalcToJoin.groovy | 14 +- .../mv/ut/joinOnLeftPToJoin.groovy | 15 +- .../mv/ut/onlyGroupBy.groovy | 10 +- .../mv/ut/orderByOnPView.groovy | 22 +- .../nereids_syntax_p0/mv/ut/projectMV1.groovy | 21 +- .../nereids_syntax_p0/mv/ut/projectMV2.groovy | 31 +- .../nereids_syntax_p0/mv/ut/projectMV3.groovy | 32 +- .../nereids_syntax_p0/mv/ut/projectMV4.groovy | 31 +- .../nereids_syntax_p0/mv/ut/subQuery.groovy | 10 +- .../nereids_syntax_p0/mv/ut/unionDis.groovy | 11 +- .../nereids_syntax_p0/rollup/agg.groovy | 13 +- .../nereids_syntax_p0/rollup/agg_date.groovy | 12 +- .../nereids_syntax_p0/rollup/date.groovy | 46 +-- .../nereids_syntax_p0/rollup/hll/hll.groovy | 8 +- .../hll_with_light_sc.groovy | 12 +- .../mv/aggregate/agg_sync_mv.groovy | 251 +++---------- 192 files changed, 1881 insertions(+), 5914 deletions(-) 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 ac986cbe77b6fd..90ceb24231340c 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 @@ -48,6 +48,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.json.JSONObject; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -502,7 +503,8 @@ AGGREGATE KEY (siteid,citycode,username) if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -528,7 +530,8 @@ public void computeUniform(DataTrait.Builder builder) { if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -542,7 +545,8 @@ public void computeEqualSet(DataTrait.Builder builder) { if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -556,7 +560,8 @@ public void computeFd(DataTrait.Builder builder) { if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -567,9 +572,23 @@ public void computeFd(DataTrait.Builder builder) { Map constructReplaceMap(MTMV mtmv) { Map replaceMap = new HashMap<>(); - List originOutputs = mtmv.getCache().getOriginalPlan().getOutput(); - for (int i = 0; i < getOutput().size(); i++) { - replaceMap.put(originOutputs.get(i), getOutput().get(i)); + // Need remove invisible column, and then mapping them + List originOutputs = new ArrayList<>(); + for (Slot originSlot : mtmv.getCache().getOriginalPlan().getOutput()) { + if (!(originSlot instanceof SlotReference) || (((SlotReference) originSlot).isVisible())) { + originOutputs.add(originSlot); + } + } + List targetOutputs = new ArrayList<>(); + for (Slot targeSlot : getOutput()) { + if (!(targeSlot instanceof SlotReference) || (((SlotReference) targeSlot).isVisible())) { + targetOutputs.add(targeSlot); + } + } + Preconditions.checkArgument(originOutputs.size() == targetOutputs.size(), + "constructReplaceMap, the size of originOutputs and targetOutputs should be same"); + for (int i = 0; i < targetOutputs.size(); i++) { + replaceMap.put(originOutputs.get(i), targetOutputs.get(i)); } return replaceMap; } diff --git a/regression-test/data/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.out b/regression-test/data/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.out index 298d8191964393..63f0bacf5d4185 100644 --- a/regression-test/data/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.out +++ b/regression-test/data/nereids_rules_p0/mv/agg_optimize_when_uniform/agg_optimize_when_uniform.out @@ -102,10 +102,10 @@ PhysicalResultSink --hashAgg[GLOBAL] ----hashAgg[LOCAL] ------hashJoin[INNER_JOIN] hashCondition=((t1.l_orderkey = orders.o_orderkey) and (t1.l_shipdate = orders.o_orderdate)) otherCondition=() ---------filter((t1.l_shipdate = '2023-12-09')) -----------PhysicalOlapScan[lineitem] --------filter((orders.o_orderdate = '2023-12-09') and (orders.o_shippriority = 1) and (orders.o_totalprice = 11.50)) ----------PhysicalOlapScan[orders] +--------filter((t1.l_shipdate = '2023-12-09')) +----------PhysicalOlapScan[lineitem] -- !query7_1_after -- yy 4 11.50 11.50 11.50 1 diff --git a/regression-test/data/nereids_syntax_p0/mv/ut/MVWithAs.out b/regression-test/data/nereids_syntax_p0/mv/ut/MVWithAs.out index 30b1f06fdff17f..af53059c4a62c3 100644 --- a/regression-test/data/nereids_syntax_p0/mv/ut/MVWithAs.out +++ b/regression-test/data/nereids_syntax_p0/mv/ut/MVWithAs.out @@ -2,8 +2,12 @@ -- !select_star -- 2020-01-01 1 a 1 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 2020-01-02 2 b 2 -- !select_mv -- -3 +7 diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy index e9e8fc258d8a73..b66c78a95077a5 100644 --- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy +++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy @@ -1369,6 +1369,9 @@ class Suite implements GroovyInterceptable { logger.info("status is not success") assertTrue(result.toString().contains("same table")) } + // Need to analyze materialized view for cbo to choose the materialized view accurately + logger.info("waitingMTMVTaskFinished analyze mv name is " + result.last().get(5)) + sql "analyze table ${result.last().get(6)}.${mvName} with sync;" } void waitingPartitionIsExpected(String tableName, String partitionName, boolean expectedStatus) { @@ -1440,29 +1443,26 @@ class Suite implements GroovyInterceptable { } } - def getMVJobState = { tableName, limit -> - def jobStateResult = sql """ SHOW ALTER TABLE ROLLUP WHERE TableName='${tableName}' ORDER BY CreateTime DESC limit ${limit}""" - if (jobStateResult.size() != limit) { + def getMVJobState = { tableName, rollUpName -> + def jobStateResult = sql """ SHOW ALTER TABLE ROLLUP WHERE TableName='${tableName}' and IndexName = '${rollUpName}' ORDER BY CreateTime DESC limit 1""" + if (jobStateResult == null || jobStateResult.isEmpty()) { logger.info("show alter table roll is empty" + jobStateResult) return "NOT_READY" } - for (int i = 0; i < jobStateResult.size(); i++) { - logger.info("getMVJobState is " + jobStateResult[i][8]) - if (!jobStateResult[i][8].equals("FINISHED")) { - return "NOT_READY" - } + logger.info("getMVJobState jobStateResult is " + jobStateResult.toString()) + if (!jobStateResult[0][8].equals("FINISHED")) { + return "NOT_READY" } return "FINISHED"; } - def waitForRollUpJob = (tbName, timeoutMillisecond, limit) -> { + def waitForRollUpJob = (tbName, rollUpName, timeoutMillisecond) -> { long startTime = System.currentTimeMillis() long timeoutTimestamp = startTime + timeoutMillisecond String result - // time out or has run exceed 10 minute, then break - while (timeoutTimestamp > System.currentTimeMillis() && System.currentTimeMillis() - startTime < 600000){ - result = getMVJobState(tbName, limit) + while (timeoutTimestamp > System.currentTimeMillis()){ + result = getMVJobState(tbName, rollUpName) if (result == "FINISHED") { sleep(200) return @@ -1679,11 +1679,42 @@ class Suite implements GroovyInterceptable { return result.values().toList() } + // Given tables to decide whether the table partition row count statistic is ready or not + boolean is_partition_statistics_ready(db, tables) { + boolean isReady = true; + for (String table : tables) { + if (!isReady) { + logger.info("is_partition_statistics_ready " + db + " " + table + " " + isReady) + return false; + } + String showPartitions = "show partitions from ${db}.${table}" + String showData = "show data from ${db}.${table}" + + List> partitions = sql(showPartitions) + logger.info("is_partition_statistics_ready partitions = " + partitions) + if (partitions.size() == 1) { + // If only one partition, the table row count is same with partition row count, so is ready + continue + } + + List> data = sql(showData) + logger.info("is_partition_statistics_ready data = " + data) + for (List row : data) { + if (row.size() >= 2 && Objects.equals(row.get(1), table)) { + isReady = isReady && Double.parseDouble(row.get(4)) > 0 + break + } + } + } + logger.info("is_partition_statistics_ready " + db + " " + tables + " " + isReady) + return isReady + } + def create_async_mv = { db, mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" + sql """DROP MATERIALIZED VIEW IF EXISTS ${db}.${mv_name}""" sql""" - CREATE MATERIALIZED VIEW ${mv_name} + CREATE MATERIALIZED VIEW ${db}.${mv_name} BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ('replication_num' = '1') @@ -1691,26 +1722,204 @@ class Suite implements GroovyInterceptable { """ def job_name = getJobName(db, mv_name); waitingMTMVTaskFinished(job_name) - sql "analyze table ${mv_name} with sync;" + sql "analyze table ${db}.${mv_name} with sync;" } + // mv not part in rewrite process def mv_not_part_in = { query_sql, mv_name -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_name) explain { sql(" memo plan ${query_sql}") - notContains("${mv_name} chose") - notContains("${mv_name} not chose") - notContains("${mv_name} fail") + check { result -> + boolean success = !result.contains("${mv_name} chose") && !result.contains("${mv_name} not chose") + && !result.contains("${mv_name} fail") + Assert.assertEquals(true, success) + } } } - def mv_rewrite_success = { query_sql, mv_name -> + // multi mv all not part in rewrite process + def mv_all_not_part_in = { query_sql, mv_names -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names) + explain { + sql(" memo plan ${query_sql}") + check { result -> + boolean success = true; + for (String mv_name : mv_names) { + success = !result.contains("${mv_name} chose") && !result.contains("${mv_name} not chose") + && !result.contains("${mv_name} fail") + } + Assert.assertEquals(true, success) + } + } + } + + // mv part in rewrite process, rewrte success and chosen by cbo + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + // is_partition_statistics_ready is the bool value which identifying if partition row count is valid or not + // if true, check if chosen by cbo or doesn't check + def mv_rewrite_success = { query_sql, mv_name, sync_cbo_rewrite = true, is_partition_statistics_ready = true -> + logger.info("query_sql = " + query_sql + ", mv_name = " + mv_name + ", sync_cbo_rewrite = " +sync_cbo_rewrite + + ", is_partition_statistics_ready = " + is_partition_statistics_ready) + if (!is_partition_statistics_ready) { + // If partition statistics is no ready, degrade to without check cbo chosen + return mv_rewrite_success_without_check_chosen(query_sql, mv_name, sync_cbo_rewrite) + } + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + contains("(${mv_name})") + } + return + } explain { sql(" memo plan ${query_sql}") contains("${mv_name} chose") } } - def mv_rewrite_success_without_check_chosen = { query_sql, mv_name -> + // multi mv part in rewrite process, all rewrte success and chosen by cbo + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + // is_partition_statistics_ready is the bool value which identifying if partition row count is valid or not + // if true, check if chosen by cbo or doesn't check + def mv_rewrite_all_success = { query_sql, mv_names, sync_cbo_rewrite = true, is_partition_statistics_ready = true -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names + ", sync_cbo_rewrite = " +sync_cbo_rewrite + + ", is_partition_statistics_ready = " + is_partition_statistics_ready) + if (!is_partition_statistics_ready) { + // If partition statistics is no ready, degrade to without check cbo chosen + return mv_rewrite_all_success_without_check_chosen(query_sql, mv_names, sync_cbo_rewrite) + } + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + check { result -> + boolean success = true; + for (String mv_name : mv_names) { + success = success && result.contains("(${mv_name})") + } + Assert.assertEquals(true, success) + } + } + return + } + explain { + sql(" memo plan ${query_sql}") + check { result -> + boolean success = true; + for (String mv_name : mv_names) { + success = success && result.contains("${mv_name} chose") + } + Assert.assertEquals(true, success) + } + } + } + + // multi mv part in rewrite process, any of them rewrte success and chosen by cbo + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + // is_partition_statistics_ready is the bool value which identifying if partition row count is valid or not + // if true, check if chosen by cbo or doesn't check + def mv_rewrite_any_success = { query_sql, mv_names, sync_cbo_rewrite = true, is_partition_statistics_ready = true -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names + ", sync_cbo_rewrite = " +sync_cbo_rewrite + + ", is_partition_statistics_ready = " + is_partition_statistics_ready) + if (!is_partition_statistics_ready) { + // If partition statistics is no ready, degrade to without check cbo chosen + return mv_rewrite_any_success_without_check_chosen(query_sql, mv_names, sync_cbo_rewrite) + } + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + check { result -> + boolean success = false; + for (String mv_name : mv_names) { + success = success || result.contains("(${mv_name})") + } + Assert.assertEquals(true, success) + } + } + return + } + explain { + sql(" memo plan ${query_sql}") + check { result -> + boolean success = false; + for (String mv_name : mv_names) { + success = success || result.contains("${mv_name} chose") + } + Assert.assertEquals(true, success) + } + } + } + + // multi mv part in rewrite process, all rewrte success without check if chosen by cbo + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + def mv_rewrite_all_success_without_check_chosen = { query_sql, mv_names, sync_cbo_rewrite = true -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names) + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + check { result -> + boolean success = true; + for (String mv_name : mv_names) { + success = success && result.contains("(${mv_name})") + } + Assert.assertEquals(true, success) + } + } + return + } + explain { + sql(" memo plan ${query_sql}") + check {result -> + boolean success = true + for (String mv_name : mv_names) { + boolean stepSuccess = result.contains("${mv_name} chose") || result.contains("${mv_name} not chose") + success = success && stepSuccess + } + Assert.assertEquals(true, success) + } + } + } + + // multi mv part in rewrite process, any of them rewrte success without check if chosen by cbo or not + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + def mv_rewrite_any_success_without_check_chosen = { query_sql, mv_names, sync_cbo_rewrite = true -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names) + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + check { result -> + boolean success = false; + for (String mv_name : mv_names) { + success = success || result.contains("(${mv_name})") + } + Assert.assertEquals(true, success) + } + } + return + } + explain { + sql(" memo plan ${query_sql}") + check {result -> + boolean success = false + for (String mv_name : mv_names) { + success = success || result.contains("${mv_name} chose") || result.contains("${mv_name} not chose") + } + Assert.assertEquals(true, success) + } + } + } + + // multi mv part in rewrite process, rewrte success without check if chosen by cbo or not + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + def mv_rewrite_success_without_check_chosen = { query_sql, mv_name, sync_cbo_rewrite = true -> + logger.info("query_sql = " + query_sql + ", mv_name = " + mv_name) + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + contains("(${mv_name})") + } + return + } explain { sql(" memo plan ${query_sql}") check { result -> @@ -1719,18 +1928,80 @@ class Suite implements GroovyInterceptable { } } - def mv_rewrite_fail = { query_sql, mv_name -> + // single mv part in rewrite process, rewrte fail + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + def mv_rewrite_fail = { query_sql, mv_name, sync_cbo_rewrite = true -> + logger.info("query_sql = " + query_sql + ", mv_name = " + mv_name) + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + nonContains("(${mv_name})") + } + return + } explain { sql(" memo plan ${query_sql}") contains("${mv_name} fail") } } - def mv_rewrite_all_fail = {query_sql -> + // multi mv part in rewrite process, all rewrte fail + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + def mv_rewrite_all_fail = {query_sql, mv_names, sync_cbo_rewrite = true -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names) + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + check { result -> + boolean fail = true + for (String mv_name : mv_names) { + boolean stepFail = !result.contains("(${mv_name})") + fail = fail && stepFail + } + Assert.assertEquals(true, fail) + } + } + return + } + explain { + sql(" memo plan ${query_sql}") + check {result -> + boolean fail = true + for (String mv_name : mv_names) { + boolean stepFail = result.contains("${mv_name} fail") + fail = fail && stepFail + } + Assert.assertEquals(true, fail) + } + } + } + + // multi mv part in rewrite process, any rewrte fail + // sync_cbo_rewrite is the bool value which control sync mv is use cbo based mv rewrite + def mv_rewrite_any_fail = {query_sql, mv_names, sync_cbo_rewrite = true -> + logger.info("query_sql = " + query_sql + ", mv_names = " + mv_names) + if (!sync_cbo_rewrite) { + explain { + sql("${query_sql}") + check { result -> + boolean fail = false + for (String mv_name : mv_names) { + fail = fail || !result.contains("(${mv_name})") + } + Assert.assertEquals(true, fail) + } + } + return + } explain { sql(" memo plan ${query_sql}") - contains("chose: none") - contains("not chose: none") + check { result -> + boolean fail = false + for (String mv_name : mv_names) { + fail = fail || result.contains("${mv_name} fail") + } + Assert.assertEquals(true, fail) + } } } @@ -1746,13 +2017,7 @@ class Suite implements GroovyInterceptable { """ def job_name = getJobName(db, mv_name); waitingMTMVTaskFinished(job_name) - - sql "analyze table ${mv_name} with sync;" - - explain { - sql(" memo plan ${query_sql}") - contains("${mv_name} chose") - } + mv_rewrite_success(query_sql, mv_name) } def async_mv_rewrite_success_without_check_chosen = { db, mv_sql, query_sql, mv_name -> @@ -1768,15 +2033,7 @@ class Suite implements GroovyInterceptable { def job_name = getJobName(db, mv_name); waitingMTMVTaskFinished(job_name) - - sql "analyze table ${mv_name} with sync;" - - explain { - sql(" memo plan ${query_sql}") - check { result -> - result.contains("${mv_name} chose") || result.contains("${mv_name} not chose") - } - } + mv_rewrite_success_without_check_chosen(query_sql, mv_name) } @@ -1793,13 +2050,7 @@ class Suite implements GroovyInterceptable { def job_name = getJobName(db, mv_name); waitingMTMVTaskFinished(job_name) - - sql "analyze table ${mv_name} with sync;" - - explain { - sql(" memo plan ${query_sql}") - contains("${mv_name} fail") - } + mv_rewrite_fail(query_sql, mv_name) } def token = context.config.metaServiceToken diff --git a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy index e6ca0b696ffb88..a371f5ac051ea8 100644 --- a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy +++ b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy @@ -46,7 +46,8 @@ suite("test_create_table_like_nereids") { // with all rollup sql "drop table if exists table_like_with_roll_up" sql "CREATE TABLE table_like_with_roll_up LIKE mal_test_create_table_like with rollup;" - waitForRollUpJob("mal_test_create_table_like", 5000, 2) + waitForRollUpJob("mal_test_create_table_like", "r1", 60000) + waitForRollUpJob("mal_test_create_table_like", "r2", 60000) explain { sql ("select sum(a) from table_like_with_roll_up group by a") contains "ru1" @@ -59,7 +60,7 @@ suite("test_create_table_like_nereids") { // with partial rollup sql "drop table if exists table_like_with_partial_roll_up;" sql "CREATE TABLE table_like_with_partial_roll_up LIKE mal_test_create_table_like with rollup (ru1);" - waitForRollUpJob("mal_test_create_table_like", 5000, 2) + waitForRollUpJob("mal_test_create_table_like", "r1", 60000) sql "select * from table_like_with_partial_roll_up order by pk, a, b" explain { sql("select sum(a) from table_like_with_partial_roll_up group by a") @@ -78,7 +79,7 @@ suite("test_create_table_like_nereids") { sql "drop table if exists table_like_with_partial_roll_up_exists" sql """CREATE TABLE if not exists table_like_with_partial_roll_up_exists LIKE mal_test_create_table_like with rollup (ru1);""" - waitForRollUpJob("mal_test_create_table_like", 5000, 2) + waitForRollUpJob("mal_test_create_table_like", "r1", 60000) sql "drop table if exists test_create_table_like_char_255" sql """ diff --git a/regression-test/suites/mtmv_p0/test_create_mv_mtmv.groovy b/regression-test/suites/mtmv_p0/test_create_mv_mtmv.groovy index d866d625704833..c6b6b4386d5075 100644 --- a/regression-test/suites/mtmv_p0/test_create_mv_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_create_mv_mtmv.groovy @@ -77,9 +77,7 @@ suite("test_create_mv_mtmv","mtmv") { order_qt_refresh_mv "SELECT * FROM ${mvName}" order_qt_sync_mv "SELECT k2 FROM ${mvName}" - def explainResult = sql """explain SELECT k2 FROM ${mvName}""" - logger.info("explainResult: " + explainResult.toString()) - assertTrue(explainResult.toString().contains('mv_mtmv1')) + mv_rewrite_success_without_check_chosen("""SELECT k2 FROM ${mvName}""", "mv_mtmv1") sql """DROP MATERIALIZED VIEW mv_mtmv1 ON ${mvName};""" diff --git a/regression-test/suites/mtmv_p0/test_create_rollup_mtmv.groovy b/regression-test/suites/mtmv_p0/test_create_rollup_mtmv.groovy index 0d47200a81971b..df4040d9a9e605 100644 --- a/regression-test/suites/mtmv_p0/test_create_rollup_mtmv.groovy +++ b/regression-test/suites/mtmv_p0/test_create_rollup_mtmv.groovy @@ -78,9 +78,7 @@ suite("test_create_rollup_mtmv","mtmv") { order_qt_refresh_mv "SELECT * FROM ${mvName}" order_qt_sync_mv "SELECT k3 FROM ${mvName}" - def explainResult = sql """explain SELECT k3 FROM ${mvName}""" - logger.info("explainResult: " + explainResult.toString()) - assertTrue(explainResult.toString().contains('rollup1')) + mv_rewrite_success_without_check_chosen("""SELECT k3 FROM ${mvName}""", "rollup1") sql """alter table ${mvName} drop ROLLUP rollup1;""" diff --git a/regression-test/suites/mv_p0/agg_have_dup_base/agg_have_dup_base.groovy b/regression-test/suites/mv_p0/agg_have_dup_base/agg_have_dup_base.groovy index dfc818303e6678..8f3ec4171e32b0 100644 --- a/regression-test/suites/mv_p0/agg_have_dup_base/agg_have_dup_base.groovy +++ b/regression-test/suites/mv_p0/agg_have_dup_base/agg_have_dup_base.groovy @@ -47,45 +47,24 @@ suite ("agg_have_dup_base") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,sum(k2),max(k2) from d_table group by k1;") - contains "(k12s3m)" - } + mv_rewrite_success("select k1,sum(k2),max(k2) from d_table group by k1;", "k12s3m") qt_select_mv "select k1,sum(k2),max(k2) from d_table group by k1 order by k1;" - explain { - sql("select k1,sum(k2) from d_table group by k1;") - contains "(k12s3m)" - } + mv_rewrite_success("select k1,sum(k2) from d_table group by k1;", "k12s3m") qt_select_mv "select k1,sum(k2) from d_table group by k1 order by k1;" - explain { - sql("select k1,max(k2) from d_table group by k1;") - contains "(k12s3m)" - } + mv_rewrite_success("select k1,max(k2) from d_table group by k1;", "k12s3m") qt_select_mv "select k1,max(k2) from d_table group by k1 order by k1;" - explain { - sql("select unix_timestamp(k1) tmp,sum(k2) from d_table group by tmp;") - contains "(k12s3m)" - } + mv_rewrite_success("select unix_timestamp(k1) tmp,sum(k2) from d_table group by tmp;", "k12s3m") qt_select_mv "select unix_timestamp(k1) tmp,sum(k2) from d_table group by tmp order by tmp;" sql """set enable_stats=true;""" - explain { - sql("select k1,sum(k2),max(k2) from d_table group by k1;") - contains "(k12s3m)" - } - explain { - sql("select k1,sum(k2) from d_table group by k1;") - contains "(k12s3m)" - } - explain { - sql("select k1,max(k2) from d_table group by k1;") - contains "(k12s3m)" - } - explain { - sql("select unix_timestamp(k1) tmp,sum(k2) from d_table group by tmp;") - contains "(k12s3m)" - } + mv_rewrite_success("select k1,sum(k2),max(k2) from d_table group by k1;", "k12s3m") + + mv_rewrite_success("select k1,sum(k2) from d_table group by k1;", "k12s3m") + + mv_rewrite_success("select k1,max(k2) from d_table group by k1;", "k12s3m") + + mv_rewrite_success("select unix_timestamp(k1) tmp,sum(k2) from d_table group by tmp;", "k12s3m") } diff --git a/regression-test/suites/mv_p0/agg_state/diffrent_serialize/diffrent_serialize.groovy b/regression-test/suites/mv_p0/agg_state/diffrent_serialize/diffrent_serialize.groovy index 36bec9d30e2126..78d26f476fa7a8 100644 --- a/regression-test/suites/mv_p0/agg_state/diffrent_serialize/diffrent_serialize.groovy +++ b/regression-test/suites/mv_p0/agg_state/diffrent_serialize/diffrent_serialize.groovy @@ -53,37 +53,22 @@ suite ("diffrent_serialize") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,bitmap_to_string(bitmap_agg(k2)) from d_table group by k1 order by 1;") - contains "(mv1)" - } + mv_rewrite_success("select k1,bitmap_to_string(bitmap_agg(k2)) from d_table group by k1 order by 1;", "mv1") qt_select_mv "select k1,bitmap_to_string(bitmap_agg(k2)) from d_table group by k1 order by 1;" - explain { - sql("select k1,bitmap_to_string(bitmap_intersect(to_bitmap(k2))) from d_table group by k1 order by 1;") - contains "(mv1_1)" - } + mv_rewrite_success("select k1,bitmap_to_string(bitmap_intersect(to_bitmap(k2))) from d_table group by k1 order by 1;", "mv1_1") qt_select_mv "select k1,bitmap_to_string(bitmap_intersect(to_bitmap(k2))) from d_table group by k1 order by 1;" sql "insert into d_table select 1,1,1,'a';" sql "insert into d_table select 1,2,1,'a';" - explain { - sql("select k1,bitmap_count(bitmap_agg(k2)) from d_table group by k1 order by 1;") - contains "(mv1)" - } + mv_rewrite_success("select k1,bitmap_count(bitmap_agg(k2)) from d_table group by k1 order by 1;", "mv1") qt_select_mv "select k1,bitmap_count(bitmap_agg(k2)) from d_table group by k1 order by 1;" - explain { - sql("select k1, multi_distinct_sum(k3) from d_table group by k1 order by k1;") - contains "(mv1_3)" - } + mv_rewrite_success("select k1, multi_distinct_sum(k3) from d_table group by k1 order by k1;", "mv1_3") qt_select_mv "select k1, multi_distinct_sum(k3) from d_table group by k1 order by k1;" - explain { - sql("select k1, multi_distinct_group_concat(k4) from d_table group by k1 order by k1;") - contains "(mv1_2)" - } + mv_rewrite_success("select k1, multi_distinct_group_concat(k4) from d_table group by k1 order by k1;", "mv1_2") qt_select_mv "select k1, multi_distinct_group_concat(k4) from d_table group by k1 order by k1;" diff --git a/regression-test/suites/mv_p0/agg_state/test_agg_state_max_by.groovy b/regression-test/suites/mv_p0/agg_state/test_agg_state_max_by.groovy index 3581971bb6ec31..1e34c70ccec900 100644 --- a/regression-test/suites/mv_p0/agg_state/test_agg_state_max_by.groovy +++ b/regression-test/suites/mv_p0/agg_state/test_agg_state_max_by.groovy @@ -67,15 +67,9 @@ suite ("test_agg_state_max_by") { sql """set enable_stats=false;""" qt_select_star "select * from d_table order by 1,2;" - explain { - sql("select k1,max_by(k2,k3) from d_table group by k1 order by 1,2;") - contains "(k1mb)" - } + mv_rewrite_success("select k1,max_by(k2,k3) from d_table group by k1 order by 1,2;", "k1mb") sql """set enable_stats=true;""" - explain { - sql("select k1,max_by(k2,k3) from d_table group by k1 order by 1,2;") - contains "(k1mb)" - } + mv_rewrite_success("select k1,max_by(k2,k3) from d_table group by k1 order by 1,2;", "k1mb") qt_select_mv "select k1,max_by(k2,k3) from d_table group by k1 order by 1,2;" createMV("create materialized view k1mbcp1 as select k1,max_by(k2+k3,abs(k3)) from d_table group by k1;") @@ -110,35 +104,17 @@ suite ("test_agg_state_max_by") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("select k1,max_by(k2+k3,abs(k3)) from d_table group by k1 order by 1,2;") - contains "(k1mbcp1)" - } + mv_rewrite_success("select k1,max_by(k2+k3,abs(k3)) from d_table group by k1 order by 1,2;", "k1mbcp1") qt_select_mv "select k1,max_by(k2+k3,k3) from d_table group by k1 order by 1,2;" - explain { - sql("select k1,max_by(k2+k3,k3) from d_table group by k1 order by 1,2;") - contains "(k1mbcp2)" - } + mv_rewrite_success("select k1,max_by(k2+k3,k3) from d_table group by k1 order by 1,2;", "k1mbcp2") qt_select_mv "select k1,max_by(k2+k3,k3) from d_table group by k1 order by 1,2;" - explain { - sql("select k1,max_by(k2,abs(k3)) from d_table group by k1 order by 1,2;") - contains "(k1mbcp3)" - } + mv_rewrite_success("select k1,max_by(k2,abs(k3)) from d_table group by k1 order by 1,2;", "k1mbcp3") qt_select_mv "select k1,max_by(k2,abs(k3)) from d_table group by k1 order by 1,2;" sql """set enable_stats=true;""" - explain { - sql("select k1,max_by(k2+k3,abs(k3)) from d_table group by k1 order by 1,2;") - contains "(k1mbcp1)" - } - explain { - sql("select k1,max_by(k2+k3,k3) from d_table group by k1 order by 1,2;") - contains "(k1mbcp2)" - } - explain { - sql("select k1,max_by(k2,abs(k3)) from d_table group by k1 order by 1,2;") - contains "(k1mbcp3)" - } + mv_rewrite_success("select k1,max_by(k2+k3,abs(k3)) from d_table group by k1 order by 1,2;", "k1mbcp1") + mv_rewrite_success("select k1,max_by(k2+k3,k3) from d_table group by k1 order by 1,2;", "k1mbcp2") + mv_rewrite_success("select k1,max_by(k2,abs(k3)) from d_table group by k1 order by 1,2;", "k1mbcp3") } diff --git a/regression-test/suites/mv_p0/case_ignore/case_ignore.groovy b/regression-test/suites/mv_p0/case_ignore/case_ignore.groovy index 0111bd4d6f78fe..1134d930185b9a 100644 --- a/regression-test/suites/mv_p0/case_ignore/case_ignore.groovy +++ b/regression-test/suites/mv_p0/case_ignore/case_ignore.groovy @@ -46,26 +46,14 @@ suite ("case_ignore") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,abs(k2) from d_table order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select k1,abs(k2) from d_table order by k1;", "k12a") qt_select_mv "select k1,abs(k2) from d_table order by k1;" - explain { - sql("select K1,abs(K2) from d_table order by K1;") - contains "(k12a)" - } + mv_rewrite_success("select K1,abs(K2) from d_table order by K1;", "k12a") qt_select_mv "select K1,abs(K2) from d_table order by K1;" sql """set enable_stats=true;""" - explain { - sql("select k1,abs(k2) from d_table order by k1;") - contains "(k12a)" - } - explain { - sql("select K1,abs(K2) from d_table order by K1;") - contains "(k12a)" - } + mv_rewrite_success("select k1,abs(k2) from d_table order by k1;", "k12a") + mv_rewrite_success("select K1,abs(K2) from d_table order by K1;", "k12a") } diff --git a/regression-test/suites/mv_p0/count_star/count_star.groovy b/regression-test/suites/mv_p0/count_star/count_star.groovy index d16aa212bed25e..52edda58276ef6 100644 --- a/regression-test/suites/mv_p0/count_star/count_star.groovy +++ b/regression-test/suites/mv_p0/count_star/count_star.groovy @@ -49,50 +49,23 @@ suite ("count_star") { qt_select_star "select * from d_table order by k1,k2,k3,k4;" - explain { - sql("select k1,k4,count(*) from d_table group by k1,k4;") - contains "(kstar)" - } + mv_rewrite_success("select k1,k4,count(*) from d_table group by k1,k4;", "kstar") qt_select_mv "select k1,k4,count(*) from d_table group by k1,k4 order by 1,2;" - explain { - sql("select k1,k4,count(*) from d_table where k1=1 group by k1,k4;") - contains "(kstar)" - } + mv_rewrite_success("select k1,k4,count(*) from d_table where k1=1 group by k1,k4;", "kstar") qt_select_mv "select k1,k4,count(*) from d_table where k1=1 group by k1,k4 order by 1,2;" - explain { - sql("select k1,k4,count(*) from d_table where k3=1 group by k1,k4;") - contains "(d_table)" - } + mv_rewrite_fail("select k1,k4,count(*) from d_table where k3=1 group by k1,k4;", "kstar") qt_select_mv "select k1,k4,count(*) from d_table where k3=1 group by k1,k4 order by 1,2;" qt_select_mv "select count(*) from d_table;" - explain { - sql("select count(*) from d_table where k3=1;") - contains "(d_table)" - } + mv_rewrite_fail("select count(*) from d_table where k3=1;", "kstar") qt_select_mv "select count(*) from d_table where k3=1;" sql """set enable_stats=true;""" - explain { - sql("select k1,k4,count(*) from d_table group by k1,k4;") - contains "(kstar)" - } - - explain { - sql("select k1,k4,count(*) from d_table where k1=1 group by k1,k4;") - contains "(kstar)" - } - - explain { - sql("select k1,k4,count(*) from d_table where k3=1 group by k1,k4;") - contains "(d_table)" - } - - explain { - sql("select count(*) from d_table where k3=1;") - contains "(d_table)" - } + mv_rewrite_success("select k1,k4,count(*) from d_table group by k1,k4;", "kstar") + mv_rewrite_success("select k1,k4,count(*) from d_table where k1=1 group by k1,k4;", "kstar") + mv_rewrite_fail("select k1,k4,count(*) from d_table where k3=1 group by k1,k4;", "kstar") + mv_rewrite_fail("select count(*) from d_table where k3=1;", "kstar") } diff --git a/regression-test/suites/mv_p0/k1ap2spa/k1ap2spa.groovy b/regression-test/suites/mv_p0/k1ap2spa/k1ap2spa.groovy index f136a256f56ab9..cfe2a5307d7ed4 100644 --- a/regression-test/suites/mv_p0/k1ap2spa/k1ap2spa.groovy +++ b/regression-test/suites/mv_p0/k1ap2spa/k1ap2spa.groovy @@ -47,16 +47,11 @@ suite ("k1ap2spa") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("select abs(k1)+1 t,sum(abs(k2+1)) from d_table group by t order by t;") - contains "(k1ap2spa)" - } + mv_rewrite_success("select abs(k1)+1 t,sum(abs(k2+1)) from d_table group by t order by t;", "k1ap2spa") qt_select_mv "select abs(k1)+1 t,sum(abs(k2+1)) from d_table group by t order by t;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+1 t,sum(abs(k2+1)) from d_table group by t order by t;") - contains "(k1ap2spa)" - } + mv_rewrite_success("select abs(k1)+1 t,sum(abs(k2+1)) from d_table group by t order by t;", "k1ap2spa") + } diff --git a/regression-test/suites/mv_p0/k1s2m3_auto_inc/k1s2m3_auto_inc.groovy b/regression-test/suites/mv_p0/k1s2m3_auto_inc/k1s2m3_auto_inc.groovy index 317fe2079c6129..367cd9863c1e3e 100644 --- a/regression-test/suites/mv_p0/k1s2m3_auto_inc/k1s2m3_auto_inc.groovy +++ b/regression-test/suites/mv_p0/k1s2m3_auto_inc/k1s2m3_auto_inc.groovy @@ -53,15 +53,9 @@ suite ("k1s2m3_auto_inc") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("select k3,sum(abs(k2+1)) from d_table group by k3 order by 1;") - contains "(k3ap2spa)" - } + mv_rewrite_success("select k3,sum(abs(k2+1)) from d_table group by k3 order by 1;", "k3ap2spa") qt_select_mv "select k3,sum(abs(k2+1)) from d_table group by k3 order by 1;" sql """set enable_stats=true;""" - explain { - sql("select k3,sum(abs(k2+1)) from d_table group by k3 order by 1;") - contains "(k3ap2spa)" - } + mv_rewrite_success("select k3,sum(abs(k2+1)) from d_table group by k3 order by 1;", "k3ap2spa") } diff --git a/regression-test/suites/mv_p0/multi_agg_with_same_slot/multi_agg_with_same_slot.groovy b/regression-test/suites/mv_p0/multi_agg_with_same_slot/multi_agg_with_same_slot.groovy index 9809205ccc2dc9..a1d254b333e211 100644 --- a/regression-test/suites/mv_p0/multi_agg_with_same_slot/multi_agg_with_same_slot.groovy +++ b/regression-test/suites/mv_p0/multi_agg_with_same_slot/multi_agg_with_same_slot.groovy @@ -50,49 +50,23 @@ suite ("multi_agg_with_same_slot") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,k2,avg(k3),max(k3) from d_table group by k1,k2 order by 1,2;") - contains "(kmv)" - } + mv_rewrite_success("select k1,k2,avg(k3),max(k3) from d_table group by k1,k2 order by 1,2;", "kmv") qt_select_mv "select k1,k2,avg(k3),max(k3) from d_table group by k1,k2 order by 1,2;" - explain { - sql("select k1,k2,avg(k3)+max(k3) from d_table group by k1,k2 order by 1,2;") - contains "(kmv)" - } + mv_rewrite_success("select k1,k2,avg(k3)+max(k3) from d_table group by k1,k2 order by 1,2;", "kmv") qt_select_mv "select k1,k2,avg(k3),max(k3) from d_table group by k1,k2 order by 1,2;" - explain { - sql("select k1,k2,avg(k3)+max(k3) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;") - contains "(kmv)" - } + mv_rewrite_success("select k1,k2,avg(k3)+max(k3) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;", "kmv") qt_select_mv "select k1,k2,avg(k3),max(k3) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2,3;" - explain { - sql("select k1,k2,max(k5) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;") - contains "(kmv2)" - } + mv_rewrite_success("select k1,k2,max(k5) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;", "kmv2") qt_select_mv "select k1,k2,avg(k5),max(k5) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2,3;" sql """set enable_stats=true;""" - explain { - sql("select k1,k2,avg(k3),max(k3) from d_table group by k1,k2 order by 1,2;") - contains "(kmv)" - } - - explain { - sql("select k1,k2,avg(k3)+max(k3) from d_table group by k1,k2 order by 1,2;") - contains "(kmv)" - } - - explain { - sql("select k1,k2,avg(k3)+max(k3) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;") - contains "(kmv)" - } - - explain { - sql("select k1,k2,max(k5) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;") - contains "(kmv2)" - } + mv_rewrite_success("select k1,k2,avg(k3),max(k3) from d_table group by k1,k2 order by 1,2;", "kmv") + mv_rewrite_success("select k1,k2,avg(k3)+max(k3) from d_table group by k1,k2 order by 1,2;", "kmv") + mv_rewrite_success("select k1,k2,avg(k3)+max(k3) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;", "kmv") + mv_rewrite_success("select k1,k2,max(k5) from d_table group by grouping sets((k1),(k1,k2),()) order by 1,2;", "kmv2") + } diff --git a/regression-test/suites/mv_p0/multi_slot_k123p/multi_slot_k123p.groovy b/regression-test/suites/mv_p0/multi_slot_k123p/multi_slot_k123p.groovy index f6567446a75756..a4a0be3ca8df65 100644 --- a/regression-test/suites/mv_p0/multi_slot_k123p/multi_slot_k123p.groovy +++ b/regression-test/suites/mv_p0/multi_slot_k123p/multi_slot_k123p.groovy @@ -55,10 +55,7 @@ suite ("multi_slot_k123p") { sql """set enable_stats=false;""" qt_select_star "select * from d_table order by k1,k4;" - explain { - sql("select k1,k2+k3 from d_table order by k1;") - contains "(k123p)" - } + mv_rewrite_success("select k1,k2+k3 from d_table order by k1;", "k123p") qt_select_mv "select k1,k2+k3 from d_table order by k1;" qt_select_mv "select lhs.k1,rhs.k2 from d_table as lhs right join d_table as rhs on lhs.k1=rhs.k1 order by lhs.k1;" @@ -66,8 +63,5 @@ suite ("multi_slot_k123p") { qt_select_mv "select k1,version() from d_table order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,k2+k3 from d_table order by k1;") - contains "(k123p)" - } + mv_rewrite_success("select k1,k2+k3 from d_table order by k1;", "k123p") } diff --git a/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3p/multi_slot_k1a2p2ap3p.groovy b/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3p/multi_slot_k1a2p2ap3p.groovy index c262b95a904f69..e64adbb06b2988 100644 --- a/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3p/multi_slot_k1a2p2ap3p.groovy +++ b/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3p/multi_slot_k1a2p2ap3p.groovy @@ -47,15 +47,10 @@ suite ("multi_slot_k1a2p2ap3p") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") qt_select_mv "select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") + } diff --git a/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3ps/multi_slot_k1a2p2ap3ps.groovy b/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3ps/multi_slot_k1a2p2ap3ps.groovy index 7c2eb3420851b0..3a2f58f38d65a9 100644 --- a/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3ps/multi_slot_k1a2p2ap3ps.groovy +++ b/regression-test/suites/mv_p0/multi_slot_k1a2p2ap3ps/multi_slot_k1a2p2ap3ps.groovy @@ -54,26 +54,15 @@ suite ("multi_slot_k1a2p2ap3ps") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by abs(k1)+k2+1") - contains "(k1a2p2ap3ps)" - } + mv_rewrite_success("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by abs(k1)+k2+1", "k1a2p2ap3ps") qt_select_mv "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by abs(k1)+k2+1;" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2 order by abs(k1)+k2") - contains "(d_table)" - } + mv_rewrite_fail("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2 order by abs(k1)+k2", "k1a2p2ap3ps") qt_select_base "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2 order by abs(k1)+k2;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by abs(k1)+k2+1") - contains "(k1a2p2ap3ps)" - } + mv_rewrite_success("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by abs(k1)+k2+1", "k1a2p2ap3ps") + + mv_rewrite_fail("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2 order by abs(k1)+k2", "k1a2p2ap3ps") - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2 order by abs(k1)+k2") - contains "(d_table)" - } } diff --git a/regression-test/suites/mv_p0/multi_slot_k1p2ap3p/multi_slot_k1p2ap3p.groovy b/regression-test/suites/mv_p0/multi_slot_k1p2ap3p/multi_slot_k1p2ap3p.groovy index f70b3e56cd1f95..fa67fd3889d93e 100644 --- a/regression-test/suites/mv_p0/multi_slot_k1p2ap3p/multi_slot_k1p2ap3p.groovy +++ b/regression-test/suites/mv_p0/multi_slot_k1p2ap3p/multi_slot_k1p2ap3p.groovy @@ -46,15 +46,9 @@ suite ("multi_slot_k1p2ap3p") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1+1,abs(k2+2)+k3+3 from d_table order by k1+1;") - contains "(k1p2ap3p)" - } + mv_rewrite_success("select k1+1,abs(k2+2)+k3+3 from d_table order by k1+1;", "k1p2ap3p") qt_select_mv "select k1+1,abs(k2+2)+k3+3 from d_table order by k1+1;" sql """set enable_stats=true;""" - explain { - sql("select k1+1,abs(k2+2)+k3+3 from d_table order by k1+1;") - contains "(k1p2ap3p)" - } + mv_rewrite_success("select k1+1,abs(k2+2)+k3+3 from d_table order by k1+1;", "k1p2ap3p") } diff --git a/regression-test/suites/mv_p0/multi_slot_k1p2ap3ps/multi_slot_k1p2ap3ps.groovy b/regression-test/suites/mv_p0/multi_slot_k1p2ap3ps/multi_slot_k1p2ap3ps.groovy index 1f10286d80cfb2..9895bc6872e740 100644 --- a/regression-test/suites/mv_p0/multi_slot_k1p2ap3ps/multi_slot_k1p2ap3ps.groovy +++ b/regression-test/suites/mv_p0/multi_slot_k1p2ap3ps/multi_slot_k1p2ap3ps.groovy @@ -46,15 +46,9 @@ suite ("multi_slot_k1p2ap3ps") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1+1,sum(abs(k2+2)+k3+3) from d_table group by k1+1 order by k1+1;") - contains "(k1p2ap3ps)" - } + mv_rewrite_success("select k1+1,sum(abs(k2+2)+k3+3) from d_table group by k1+1 order by k1+1;", "k1p2ap3ps") qt_select_mv "select k1+1,sum(abs(k2+2)+k3+3) from d_table group by k1+1 order by k1+1;" sql """set enable_stats=true;""" - explain { - sql("select k1+1,sum(abs(k2+2)+k3+3) from d_table group by k1+1 order by k1+1;") - contains "(k1p2ap3ps)" - } + mv_rewrite_success("select k1+1,sum(abs(k2+2)+k3+3) from d_table group by k1+1 order by k1+1;", "k1p2ap3ps") } diff --git a/regression-test/suites/mv_p0/multi_slot_multi_mv/multi_slot_multi_mv.groovy b/regression-test/suites/mv_p0/multi_slot_multi_mv/multi_slot_multi_mv.groovy index 7100d240624906..5527a511e9df2a 100644 --- a/regression-test/suites/mv_p0/multi_slot_multi_mv/multi_slot_multi_mv.groovy +++ b/regression-test/suites/mv_p0/multi_slot_multi_mv/multi_slot_multi_mv.groovy @@ -78,10 +78,7 @@ suite ("multi_slot_multi_mv") { } qt_select_mv "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by abs(k1)+k2+1;" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") qt_select_mv "select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3;" sql """set enable_stats=true;""" @@ -114,9 +111,6 @@ suite ("multi_slot_multi_mv") { sleep(1000) } - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from d_table order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") } diff --git a/regression-test/suites/mv_p0/mv_with_view/mv_with_view.groovy b/regression-test/suites/mv_p0/mv_with_view/mv_with_view.groovy index c48c770cfba8e2..236bde3bf6c828 100644 --- a/regression-test/suites/mv_p0/mv_with_view/mv_with_view.groovy +++ b/regression-test/suites/mv_p0/mv_with_view/mv_with_view.groovy @@ -43,10 +43,7 @@ suite ("mv_with_view") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from d_table order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from d_table order by k1;", "k312") qt_select_star "select * from d_table order by k1;" sql """ @@ -56,10 +53,7 @@ suite ("mv_with_view") { sql """ create view v_k312 as select k1,k3,k2 from d_table where k3 = 1; """ - explain { - sql("select * from v_k312 order by k1;") - contains "(k312)" - } + mv_rewrite_success("select * from v_k312 order by k1;", "k312") qt_select_mv "select * from v_k312 order by k1;" sql """ @@ -69,17 +63,11 @@ suite ("mv_with_view") { sql """ create view v_k124 as select k1,k2,k4 from d_table where k1 = 1; """ - explain { - sql("select * from v_k124 order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from v_k124 order by k1;", "k312") qt_select_mv "select * from v_k124 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select * from d_table order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from d_table order by k1;", "k312") sql """ drop view if exists v_k312; @@ -88,10 +76,7 @@ suite ("mv_with_view") { sql """ create view v_k312 as select k1,k3,k2 from d_table where k3 = 1; """ - explain { - sql("select * from v_k312 order by k1;") - contains "(k312)" - } + mv_rewrite_success("select * from v_k312 order by k1;", "k312") sql """ drop view if exists v_k124; @@ -100,8 +85,5 @@ suite ("mv_with_view") { sql """ create view v_k124 as select k1,k2,k4 from d_table where k1 = 1; """ - explain { - sql("select * from v_k124 order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from v_k124 order by k1;", "k312") } diff --git a/regression-test/suites/mv_p0/null_insert/null_insert.groovy b/regression-test/suites/mv_p0/null_insert/null_insert.groovy index 5632c1fc181bcb..015406d80a3796 100644 --- a/regression-test/suites/mv_p0/null_insert/null_insert.groovy +++ b/regression-test/suites/mv_p0/null_insert/null_insert.groovy @@ -67,22 +67,16 @@ suite ("null_insert") { sql "analyze table test with sync;" sql """set enable_stats=false;""" - explain { - sql("""SELECT date, vid, os, ver, ip_country, hll_union(hll_hash(uid)) + mv_rewrite_success("""SELECT date, vid, os, ver, ip_country, hll_union(hll_hash(uid)) FROM test - GROUP BY date,vid,os,ver,ip_country;""") - contains "(mv_test)" - } + GROUP BY date,vid,os,ver,ip_country;""", "mv_test") qt_select_mv """SELECT date, vid, os, ver, ip_country, hll_union(hll_hash(uid)) FROM test GROUP BY date,vid,os,ver,ip_country;""" sql """set enable_stats=true;""" - explain { - sql("""SELECT date, vid, os, ver, ip_country, hll_union(hll_hash(uid)) + mv_rewrite_success("""SELECT date, vid, os, ver, ip_country, hll_union(hll_hash(uid)) FROM test - GROUP BY date,vid,os,ver,ip_country;""") - contains "(mv_test)" - } + GROUP BY date,vid,os,ver,ip_country;""", "mv_test") } diff --git a/regression-test/suites/mv_p0/routine_load_hll/routine_load_hll.groovy b/regression-test/suites/mv_p0/routine_load_hll/routine_load_hll.groovy index 3ca80b3d07d516..a872e23efc4cce 100644 --- a/regression-test/suites/mv_p0/routine_load_hll/routine_load_hll.groovy +++ b/regression-test/suites/mv_p0/routine_load_hll/routine_load_hll.groovy @@ -54,15 +54,9 @@ suite ("routine_load_hll") { sql "analyze table test with sync;" sql """set enable_stats=false;""" - explain { - sql("select time_stamp, hll_union_agg(device_id) from test group by time_stamp order by 1;") - contains "(m_view)" - } + mv_rewrite_success("select time_stamp, hll_union_agg(device_id) from test group by time_stamp order by 1;", "m_view") qt_select_mv "select time_stamp, hll_union_agg(device_id) from test group by time_stamp order by 1;" sql """set enable_stats=true;""" - explain { - sql("select time_stamp, hll_union_agg(device_id) from test group by time_stamp order by 1;") - contains "(m_view)" - } + mv_rewrite_success("select time_stamp, hll_union_agg(device_id) from test group by time_stamp order by 1;", "m_view") } diff --git a/regression-test/suites/mv_p0/ssb/multiple_no_where/multiple_no_where.groovy b/regression-test/suites/mv_p0/ssb/multiple_no_where/multiple_no_where.groovy index ae7f58196f94b7..a02cd4861554d6 100644 --- a/regression-test/suites/mv_p0/ssb/multiple_no_where/multiple_no_where.groovy +++ b/regression-test/suites/mv_p0/ssb/multiple_no_where/multiple_no_where.groovy @@ -108,16 +108,13 @@ suite ("multiple_no_where") { sql """analyze table lineorder_flat with sync;""" sql """set enable_stats=false;""" - - explain { - sql("""SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue + + mv_rewrite_success("""SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue FROM lineorder_flat WHERE LO_ORDERDATE >= 19930101 AND LO_ORDERDATE <= 19931231 AND LO_DISCOUNT >= 1 AND LO_DISCOUNT <= 3 - AND LO_QUANTITY < 25;""") - contains "(lineorder_q_1_1)" - } + AND LO_QUANTITY < 25;""", "lineorder_q_1_1") } diff --git a/regression-test/suites/mv_p0/ssb/multiple_ssb/multiple_ssb.groovy b/regression-test/suites/mv_p0/ssb/multiple_ssb/multiple_ssb.groovy index 56f29b8dc68143..eb8cfd1618fea3 100644 --- a/regression-test/suites/mv_p0/ssb/multiple_ssb/multiple_ssb.groovy +++ b/regression-test/suites/mv_p0/ssb/multiple_ssb/multiple_ssb.groovy @@ -154,17 +154,14 @@ suite ("multiple_ssb") { sql """analyze table lineorder_flat with sync;""" sql """set enable_stats=false;""" - - explain { - sql("""SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue + + mv_rewrite_success("""SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue FROM lineorder_flat WHERE LO_ORDERDATE >= 19930101 AND LO_ORDERDATE <= 19931231 AND LO_DISCOUNT >= 1 AND LO_DISCOUNT <= 3 - AND LO_QUANTITY < 25;""") - contains "(lineorder_q_1_1)" - } + AND LO_QUANTITY < 25;""", "lineorder_q_1_1") qt_select_q_1_1 """SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue FROM lineorder_flat WHERE @@ -173,16 +170,13 @@ suite ("multiple_ssb") { AND LO_DISCOUNT >= 1 AND LO_DISCOUNT <= 3 AND LO_QUANTITY < 25;""" - explain { - sql("""SELECT + mv_rewrite_success("""SELECT SUM(LO_REVENUE), (LO_ORDERDATE DIV 10000) AS YEAR, P_BRAND FROM lineorder_flat WHERE P_CATEGORY = 'MFGR#12' AND S_REGION = 'AMERICA' GROUP BY (LO_ORDERDATE DIV 10000), P_BRAND - ORDER BY YEAR, P_BRAND;""") - contains "(lineorder_q_2_1)" - } + ORDER BY YEAR, P_BRAND;""", "lineorder_q_2_1") qt_select_q_2_1 """SELECT SUM(LO_REVENUE), (LO_ORDERDATE DIV 10000) AS YEAR, P_BRAND @@ -191,8 +185,7 @@ suite ("multiple_ssb") { GROUP BY YEAR, P_BRAND ORDER BY YEAR, P_BRAND;""" - explain { - sql("""SELECT + mv_rewrite_success("""SELECT C_NATION, S_NATION, (LO_ORDERDATE DIV 10000) AS YEAR, SUM(LO_REVENUE) AS revenue @@ -203,9 +196,7 @@ suite ("multiple_ssb") { AND LO_ORDERDATE >= 19920101 AND LO_ORDERDATE <= 19971231 GROUP BY C_NATION, S_NATION, YEAR - ORDER BY YEAR ASC, revenue DESC;""") - contains "(lineorder_q_3_1)" - } + ORDER BY YEAR ASC, revenue DESC;""", "lineorder_q_3_1") qt_select_q_3_1 """SELECT C_NATION, S_NATION, (LO_ORDERDATE DIV 10000) AS YEAR, @@ -219,8 +210,7 @@ suite ("multiple_ssb") { GROUP BY C_NATION, S_NATION, YEAR ORDER BY YEAR ASC, revenue DESC;""" - explain { - sql("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, + mv_rewrite_success("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit FROM lineorder_flat @@ -229,9 +219,7 @@ suite ("multiple_ssb") { AND S_REGION = 'AMERICA' AND P_MFGR IN ('MFGR#1', 'MFGR#2') GROUP BY YEAR, C_NATION - ORDER BY YEAR ASC, C_NATION ASC;""") - contains "(lineorder_q_4_1)" - } + ORDER BY YEAR ASC, C_NATION ASC;""", "lineorder_q_4_1") qt_select_q_4_1 """SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit @@ -243,43 +231,32 @@ suite ("multiple_ssb") { GROUP BY YEAR, C_NATION ORDER BY YEAR ASC, C_NATION ASC;""" - explain { - sql("""select LO_ORDERDATE, sum(LO_ORDERDATE) from lineorder_flat where LO_ORDERDATE in (1,2,3) group by LO_ORDERDATE;""") - contains "(count_LO_ORDERPRIORITY_1)" - } + mv_rewrite_success("""select LO_ORDERDATE, sum(LO_ORDERDATE) from lineorder_flat where LO_ORDERDATE in (1,2,3) group by LO_ORDERDATE;""", + "count_LO_ORDERPRIORITY_1") qt_select_count_1 "select LO_ORDERDATE, sum(LO_ORDERDATE) from lineorder_flat where LO_ORDERDATE in (1,2,3) group by LO_ORDERDATE order by 1,2;" - explain { - sql("""select LO_ORDERPRIORITY, count(1) from lineorder_flat where LO_ORDERPRIORITY in ('1','2','3') group by LO_ORDERPRIORITY;""") - contains "(count_LO_ORDERPRIORITY_3)" - } + mv_rewrite_success("""select LO_ORDERPRIORITY, count(1) from lineorder_flat where LO_ORDERPRIORITY in ('1','2','3') group by LO_ORDERPRIORITY;""", + "count_LO_ORDERPRIORITY_3") qt_select_count_3 "select LO_ORDERPRIORITY, count(1) from lineorder_flat where LO_ORDERPRIORITY in ('1','2','3') group by LO_ORDERPRIORITY order by 1,2;" sql """set enable_stats=true;""" - explain { - sql("""SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue + mv_rewrite_success("""SELECT SUM(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue FROM lineorder_flat WHERE LO_ORDERDATE >= 19930101 AND LO_ORDERDATE <= 19931231 AND LO_DISCOUNT >= 1 AND LO_DISCOUNT <= 3 - AND LO_QUANTITY < 25;""") - contains "(lineorder_q_1_1)" - } + AND LO_QUANTITY < 25;""", "lineorder_q_1_1") - explain { - sql("""SELECT + mv_rewrite_success("""SELECT SUM(LO_REVENUE), (LO_ORDERDATE DIV 10000) AS YEAR, P_BRAND FROM lineorder_flat WHERE P_CATEGORY = 'MFGR#12' AND S_REGION = 'AMERICA' GROUP BY (LO_ORDERDATE DIV 10000), P_BRAND - ORDER BY YEAR, P_BRAND;""") - contains "(lineorder_q_2_1)" - } + ORDER BY YEAR, P_BRAND;""", "lineorder_q_2_1") - explain { - sql("""SELECT + mv_rewrite_success("""SELECT C_NATION, S_NATION, (LO_ORDERDATE DIV 10000) AS YEAR, SUM(LO_REVENUE) AS revenue @@ -290,12 +267,9 @@ suite ("multiple_ssb") { AND LO_ORDERDATE >= 19920101 AND LO_ORDERDATE <= 19971231 GROUP BY C_NATION, S_NATION, YEAR - ORDER BY YEAR ASC, revenue DESC;""") - contains "(lineorder_q_3_1)" - } + ORDER BY YEAR ASC, revenue DESC;""", "lineorder_q_3_1") - explain { - sql("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, + mv_rewrite_success("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit FROM lineorder_flat @@ -304,17 +278,10 @@ suite ("multiple_ssb") { AND S_REGION = 'AMERICA' AND P_MFGR IN ('MFGR#1', 'MFGR#2') GROUP BY YEAR, C_NATION - ORDER BY YEAR ASC, C_NATION ASC;""") - contains "(lineorder_q_4_1)" - } + ORDER BY YEAR ASC, C_NATION ASC;""", "lineorder_q_4_1") - explain { - sql("""select LO_ORDERDATE, sum(LO_ORDERDATE) from lineorder_flat where LO_ORDERDATE in (1,2,3) group by LO_ORDERDATE;""") - contains "(count_LO_ORDERPRIORITY_1)" - } - - explain { - sql("""select LO_ORDERPRIORITY, count(1) from lineorder_flat where LO_ORDERPRIORITY in ('1','2','3') group by LO_ORDERPRIORITY;""") - contains "(count_LO_ORDERPRIORITY_3)" - } + mv_rewrite_success("""select LO_ORDERDATE, sum(LO_ORDERDATE) from lineorder_flat where LO_ORDERDATE in (1,2,3) group by LO_ORDERDATE;""", + "count_LO_ORDERPRIORITY_1") + mv_rewrite_success("""select LO_ORDERPRIORITY, count(1) from lineorder_flat where LO_ORDERPRIORITY in ('1','2','3') group by LO_ORDERPRIORITY;""", + "count_LO_ORDERPRIORITY_3") } diff --git a/regression-test/suites/mv_p0/ssb/q_2_1/q_2_1.groovy b/regression-test/suites/mv_p0/ssb/q_2_1/q_2_1.groovy index 718e87e2a1189e..6ead8380eed59b 100644 --- a/regression-test/suites/mv_p0/ssb/q_2_1/q_2_1.groovy +++ b/regression-test/suites/mv_p0/ssb/q_2_1/q_2_1.groovy @@ -93,16 +93,13 @@ suite ("mv_ssb_q_2_1") { qt_select_star "select * from lineorder_flat order by 1,2,P_MFGR;" - explain { - sql("""SELECT + mv_rewrite_success("""SELECT SUM(LO_REVENUE), (LO_ORDERDATE DIV 10000) AS YEAR, P_BRAND FROM lineorder_flat WHERE P_CATEGORY = 'MFGR#12' AND S_REGION = 'AMERICA' GROUP BY YEAR, P_BRAND - ORDER BY YEAR, P_BRAND;""") - contains "(lineorder_q_2_1)" - } + ORDER BY YEAR, P_BRAND;""", "lineorder_q_2_1") qt_select_mv """SELECT SUM(LO_REVENUE), (LO_ORDERDATE DIV 10000) AS YEAR, diff --git a/regression-test/suites/mv_p0/ssb/q_4_1/q_4_1.groovy b/regression-test/suites/mv_p0/ssb/q_4_1/q_4_1.groovy index b10476922c25d7..c094e8e00c9eaf 100644 --- a/regression-test/suites/mv_p0/ssb/q_4_1/q_4_1.groovy +++ b/regression-test/suites/mv_p0/ssb/q_4_1/q_4_1.groovy @@ -92,8 +92,7 @@ suite ("mv_ssb_q_4_1") { sql """analyze table lineorder_flat with sync;""" - explain { - sql("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, + mv_rewrite_success("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit FROM lineorder_flat @@ -102,9 +101,7 @@ suite ("mv_ssb_q_4_1") { AND S_REGION = 'AMERICA' AND P_MFGR IN ('MFGR#1', 'MFGR#2') GROUP BY YEAR, C_NATION - ORDER BY YEAR ASC, C_NATION ASC;""") - contains "(lineorder_q_4_1)" - } + ORDER BY YEAR ASC, C_NATION ASC;""", "lineorder_q_4_1") qt_select_mv """SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit diff --git a/regression-test/suites/mv_p0/ssb/q_4_1_r1/q_4_1_r1.groovy b/regression-test/suites/mv_p0/ssb/q_4_1_r1/q_4_1_r1.groovy index 70fe1c433797ad..1baf21b547f062 100644 --- a/regression-test/suites/mv_p0/ssb/q_4_1_r1/q_4_1_r1.groovy +++ b/regression-test/suites/mv_p0/ssb/q_4_1_r1/q_4_1_r1.groovy @@ -96,9 +96,8 @@ suite ("q_4_1_r1") { sql """analyze table lineorder_flat with sync;""" sql """set enable_stats=false;""" - - explain { - sql("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, + + mv_rewrite_success("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit FROM lineorder_flat @@ -107,9 +106,7 @@ suite ("q_4_1_r1") { AND S_REGION = 'AMERICA' AND P_MFGR IN ('MFGR#1', 'MFGR#2') GROUP BY YEAR, C_NATION - ORDER BY YEAR ASC, C_NATION ASC;""") - contains "(lineorder_mv)" - } + ORDER BY YEAR ASC, C_NATION ASC;""", "lineorder_mv") qt_select_mv """SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, @@ -122,8 +119,7 @@ suite ("q_4_1_r1") { GROUP BY YEAR, C_NATION ORDER BY YEAR ASC, C_NATION ASC;""" sql """set enable_stats=true;""" - explain { - sql("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, + mv_rewrite_success("""SELECT (LO_ORDERDATE DIV 10000) AS YEAR, C_NATION, SUM(LO_REVENUE - LO_SUPPLYCOST) AS profit FROM lineorder_flat @@ -132,7 +128,5 @@ suite ("q_4_1_r1") { AND S_REGION = 'AMERICA' AND P_MFGR IN ('MFGR#1', 'MFGR#2') GROUP BY YEAR, C_NATION - ORDER BY YEAR ASC, C_NATION ASC;""") - contains "(lineorder_mv)" - } + ORDER BY YEAR ASC, C_NATION ASC;""", "lineorder_mv") } diff --git a/regression-test/suites/mv_p0/sum_count/sum_count.groovy b/regression-test/suites/mv_p0/sum_count/sum_count.groovy index e60c8d5dda1d1c..b47e51999b7c42 100644 --- a/regression-test/suites/mv_p0/sum_count/sum_count.groovy +++ b/regression-test/suites/mv_p0/sum_count/sum_count.groovy @@ -67,7 +67,7 @@ suite ("sum_count") { qt_select_mv "select k1,k4,sum(2) from d_table group by k1,k4 order by 1,2;" - mv_rewrite_all_fail("select k1,k4,sum(3) from d_table group by k1,k4;") + mv_rewrite_all_fail("select k1,k4,sum(3) from d_table group by k1,k4;", ["kavg", "kavg_const1", "kavg_key", "kavg_const1", "kavg_const2"]) qt_select_mv "select k1,k4,sum(3) from d_table group by k1,k4 order by 1,2;" diff --git a/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy b/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy index c8f4681d991f7d..4e6374e300b09e 100644 --- a/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy +++ b/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy @@ -46,48 +46,24 @@ suite ("sum_devide_count") { sql """analyze table d_table with sync;""" sql """set enable_stats=false;""" - explain { - sql("select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;") - contains "(kavg)" - } + mv_rewrite_success("select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;", "kavg") qt_select_mv "select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;" - explain { - sql("select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;") - contains "(kavg)" - } + mv_rewrite_success("select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;", "kavg") qt_select_mv "select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;" - explain { - sql("select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;") - contains "(kavg)" - } + mv_rewrite_success("select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;", "kavg") qt_select_mv "select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;" - explain { - sql("select sum(k2)/count(k2) from d_table;") - contains "(kavg)" - } + mv_rewrite_success("select sum(k2)/count(k2) from d_table;", "kavg") qt_select_mv "select sum(k2)/count(k2) from d_table;" sql """set enable_stats=true;""" - explain { - sql("select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;") - contains "(kavg)" - } + mv_rewrite_success("select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;", "kavg") - explain { - sql("select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;") - contains "(kavg)" - } + mv_rewrite_success("select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;", "kavg") - explain { - sql("select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;") - contains "(kavg)" - } + mv_rewrite_success("select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;", "kavg") - explain { - sql("select sum(k2)/count(k2) from d_table;") - contains "(kavg)" - } + mv_rewrite_success("select sum(k2)/count(k2) from d_table;", "kavg") } diff --git a/regression-test/suites/mv_p0/test_28741/test_28741.groovy b/regression-test/suites/mv_p0/test_28741/test_28741.groovy index 171c2705d01350..9fabca41b943fc 100644 --- a/regression-test/suites/mv_p0/test_28741/test_28741.groovy +++ b/regression-test/suites/mv_p0/test_28741/test_28741.groovy @@ -68,15 +68,9 @@ suite ("test_28741") { sql """analyze table test with sync;""" sql """set enable_stats=false;""" - explain { - sql("select b1 from test where t >= '2023-12-20 17:21:00'") - contains "(test)" - } + mv_rewrite_fail("select b1 from test where t >= '2023-12-20 17:21:00'", "mv_test") qt_select "select b1 from test where t >= '2023-12-20 17:21:00'" sql """set enable_stats=true;""" - explain { - sql("select b1 from test where t >= '2023-12-20 17:21:00'") - contains "(test)" - } + mv_rewrite_fail("select b1 from test where t >= '2023-12-20 17:21:00'", "mv_test") } diff --git a/regression-test/suites/mv_p0/test_approx_count_distinct/test_approx_count_distinct.groovy b/regression-test/suites/mv_p0/test_approx_count_distinct/test_approx_count_distinct.groovy index 8ca1746e4c9a8f..752cf40d9e5f6a 100644 --- a/regression-test/suites/mv_p0/test_approx_count_distinct/test_approx_count_distinct.groovy +++ b/regression-test/suites/mv_p0/test_approx_count_distinct/test_approx_count_distinct.groovy @@ -40,37 +40,19 @@ suite ("test_approx_count_distinct") { sql """analyze table user_tags with sync;""" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col,tag_id;" - explain { - sql("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") qt_select_mv "select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;" - explain { - sql("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") qt_select_mv "select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") - explain { - sql("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") - explain { - sql("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") } diff --git a/regression-test/suites/mv_p0/test_base/test_base.groovy b/regression-test/suites/mv_p0/test_base/test_base.groovy index 26ae552e8f743e..d2c018febd5ada 100644 --- a/regression-test/suites/mv_p0/test_base/test_base.groovy +++ b/regression-test/suites/mv_p0/test_base/test_base.groovy @@ -46,26 +46,14 @@ suite ("test_base") { sql "analyze table dwd with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT created_at, id FROM dwd where created_at = '2020-09-09 00:00:00' order by 1, 2;") - contains "(dwd_mv)" - } + mv_rewrite_success("SELECT created_at, id FROM dwd where created_at = '2020-09-09 00:00:00' order by 1, 2;", "dwd_mv") qt_select_mv "SELECT created_at, id FROM dwd order by 1, 2;" - explain { - sql("SELECT id,created_at FROM dwd where id is not null order by 1, 2;") - contains "(dwd)" - } + mv_rewrite_success("SELECT id,created_at FROM dwd where id is not null order by 1, 2;", "dwd_mv") qt_select_mv "SELECT id,created_at FROM dwd order by 1, 2;" sql """set enable_stats=true;""" - explain { - sql("SELECT created_at, id FROM dwd where created_at = '2020-09-09 00:00:00' order by 1, 2;") - contains "(dwd_mv)" - } + mv_rewrite_success("SELECT created_at, id FROM dwd where created_at = '2020-09-09 00:00:00' order by 1, 2;", "dwd_mv") - explain { - sql("SELECT id,created_at FROM dwd where id is not null order by 1, 2;") - contains "(dwd)" - } + mv_rewrite_success("SELECT id,created_at FROM dwd where id is not null order by 1, 2;", "dwd_mv") } diff --git a/regression-test/suites/mv_p0/test_casewhen/test_casewhen.groovy b/regression-test/suites/mv_p0/test_casewhen/test_casewhen.groovy index 3f0ebd807d333f..eac65eeef22adf 100644 --- a/regression-test/suites/mv_p0/test_casewhen/test_casewhen.groovy +++ b/regression-test/suites/mv_p0/test_casewhen/test_casewhen.groovy @@ -36,15 +36,9 @@ suite ("test_casewhen") { qt_select_star "select * from sales_records order by 1,2;" - explain { - sql("select store_id, sum(case when sale_amt>10 then 1 else 2 end) from sales_records group by store_id order by 1;") - contains "(store_amt)" - } + mv_rewrite_success("select store_id, sum(case when sale_amt>10 then 1 else 2 end) from sales_records group by store_id order by 1;", "store_amt") qt_select_mv "select store_id, sum(case when sale_amt>10 then 1 else 2 end) from sales_records group by store_id order by 1;" sql """set enable_stats=true;""" - explain { - sql("select store_id, sum(case when sale_amt>10 then 1 else 2 end) from sales_records group by store_id order by 1;") - contains "(store_amt)" - } + mv_rewrite_success("select store_id, sum(case when sale_amt>10 then 1 else 2 end) from sales_records group by store_id order by 1;", "store_amt") } diff --git a/regression-test/suites/mv_p0/test_doc_e4/test_doc_e4.groovy b/regression-test/suites/mv_p0/test_doc_e4/test_doc_e4.groovy index cace1c2183744c..5e99464018e8d7 100644 --- a/regression-test/suites/mv_p0/test_doc_e4/test_doc_e4.groovy +++ b/regression-test/suites/mv_p0/test_doc_e4/test_doc_e4.groovy @@ -44,48 +44,24 @@ suite ("test_doc_e4") { sql """analyze table d_table with sync;""" sql """set enable_stats=false;""" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by 1,2;") - contains "(k1a2p2ap3ps)" - } + mv_rewrite_success("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by 1,2;", "k1a2p2ap3ps") qt_select_mv "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by 1,2;" - explain { - sql("select bin(abs(k1)+k2+1),sum(abs(k2+2)+k3+3) from d_table group by bin(abs(k1)+k2+1);") - contains "(k1a2p2ap3ps)" - } + mv_rewrite_success("select bin(abs(k1)+k2+1),sum(abs(k2+2)+k3+3) from d_table group by bin(abs(k1)+k2+1);", "k1a2p2ap3ps") qt_select_mv "select bin(abs(k1)+k2+1),sum(abs(k2+2)+k3+3) from d_table group by bin(abs(k1)+k2+1) order by 1,2;" - explain { - sql("select year(k4),month(k4) from d_table;") - contains "(d_table)" - } + mv_rewrite_all_fail("select year(k4),month(k4) from d_table;", ["k1a2p2ap3ps", "kymd"]) qt_select_mv "select year(k4),month(k4) from d_table order by 1,2;" - explain { - sql("select year(k4)+month(k4) from d_table where year(k4) = 2020;") - contains "(kymd)" - } + mv_rewrite_success("select year(k4)+month(k4) from d_table where year(k4) = 2020;", "kymd") qt_select_mv "select year(k4)+month(k4) from d_table where year(k4) = 2020 order by 1;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by 1,2;") - contains "(k1a2p2ap3ps)" - } - - explain { - sql("select bin(abs(k1)+k2+1),sum(abs(k2+2)+k3+3) from d_table group by bin(abs(k1)+k2+1);") - contains "(k1a2p2ap3ps)" - } - - explain { - sql("select year(k4),month(k4) from d_table;") - contains "(d_table)" - } - - explain { - sql("select year(k4)+month(k4) from d_table where year(k4) = 2020;") - contains "(kymd)" - } + mv_rewrite_success("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from d_table group by abs(k1)+k2+1 order by 1,2;", "k1a2p2ap3ps") + + mv_rewrite_success("select bin(abs(k1)+k2+1),sum(abs(k2+2)+k3+3) from d_table group by bin(abs(k1)+k2+1);", "k1a2p2ap3ps") + + mv_rewrite_all_fail("select year(k4),month(k4) from d_table;", ["k1a2p2ap3ps", "kymd"]) + + mv_rewrite_success("select year(k4)+month(k4) from d_table where year(k4) = 2020;", "kymd") } diff --git a/regression-test/suites/mv_p0/test_dup_group_by_mv_abs/test_dup_group_by_mv_abs.groovy b/regression-test/suites/mv_p0/test_dup_group_by_mv_abs/test_dup_group_by_mv_abs.groovy index c087a96657363d..5e917e9b0f5bd0 100644 --- a/regression-test/suites/mv_p0/test_dup_group_by_mv_abs/test_dup_group_by_mv_abs.groovy +++ b/regression-test/suites/mv_p0/test_dup_group_by_mv_abs/test_dup_group_by_mv_abs.groovy @@ -46,26 +46,13 @@ suite ("test_dup_group_by_mv_abs") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,sum(abs(k2)) from d_table group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select k1,sum(abs(k2)) from d_table group by k1;", "k12sa") qt_select_mv "select k1,sum(abs(k2)) from d_table group by k1 order by k1;" - explain { - sql("select sum(abs(k2)) from d_table group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select sum(abs(k2)) from d_table group by k1;", "k12sa") qt_select_mv_sub "select sum(abs(k2)) from d_table group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,sum(abs(k2)) from d_table group by k1;") - contains "(k12sa)" - } - - explain { - sql("select sum(abs(k2)) from d_table group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select k1,sum(abs(k2)) from d_table group by k1;", "k12sa") + mv_rewrite_success("select sum(abs(k2)) from d_table group by k1;", "k12sa") } diff --git a/regression-test/suites/mv_p0/test_dup_group_by_mv_plus/test_dup_group_by_mv_plus.groovy b/regression-test/suites/mv_p0/test_dup_group_by_mv_plus/test_dup_group_by_mv_plus.groovy index a868e796a309ca..ba9f60f6df5026 100644 --- a/regression-test/suites/mv_p0/test_dup_group_by_mv_plus/test_dup_group_by_mv_plus.groovy +++ b/regression-test/suites/mv_p0/test_dup_group_by_mv_plus/test_dup_group_by_mv_plus.groovy @@ -46,26 +46,14 @@ suite ("test_dup_group_by_mv_plus") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,sum(k2+1) from d_table group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select k1,sum(k2+1) from d_table group by k1;", "k12sp") qt_select_mv "select k1,sum(k2+1) from d_table group by k1 order by k1;" - explain { - sql("select sum(k2+1) from d_table group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select sum(k2+1) from d_table group by k1;", "k12sp") qt_select_mv_sub "select sum(k2+1) from d_table group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,sum(k2+1) from d_table group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select k1,sum(k2+1) from d_table group by k1;", "k12sp") + mv_rewrite_success("select sum(k2+1) from d_table group by k1;", "k12sp") - explain { - sql("select sum(k2+1) from d_table group by k1;") - contains "(k12sp)" - } } diff --git a/regression-test/suites/mv_p0/test_dup_mv_abs/test_dup_mv_abs.groovy b/regression-test/suites/mv_p0/test_dup_mv_abs/test_dup_mv_abs.groovy index 58d2d4429e1b37..89088ffb9ea317 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_abs/test_dup_mv_abs.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_abs/test_dup_mv_abs.groovy @@ -46,70 +46,34 @@ suite ("test_dup_mv_abs") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,abs(k2) from d_table order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select k1,abs(k2) from d_table order by k1;", "k12a") qt_select_mv "select k1,abs(k2) from d_table order by k1;" - explain { - sql("select abs(k2) from d_table order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select abs(k2) from d_table order by k1;", "k12a") qt_select_mv_sub "select abs(k2) from d_table order by k1;" - explain { - sql("select abs(k2)+1 from d_table order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select abs(k2)+1 from d_table order by k1;", "k12a") qt_select_mv_sub_add "select abs(k2)+1 from d_table order by k1;" - explain { - sql("select sum(abs(k2)) from d_table group by k1 order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select sum(abs(k2)) from d_table group by k1 order by k1;", "k12a") qt_select_group_mv "select sum(abs(k2)) from d_table group by k1 order by k1;" - explain { - sql("select sum(abs(k2)+1) from d_table group by k1 order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select sum(abs(k2)+1) from d_table group by k1 order by k1;", "k12a") qt_select_group_mv_add "select sum(abs(k2)+1) from d_table group by k1 order by k1;" - explain { - sql("select sum(abs(k2)) from d_table group by k3;") - contains "(d_table)" - } + mv_rewrite_fail("select sum(abs(k2)) from d_table group by k3;", "k12a") qt_select_group_mv_not "select sum(abs(k2)) from d_table group by k3 order by k3;" sql """set enable_stats=true;""" - explain { - sql("select k1,abs(k2) from d_table order by k1;") - contains "(k12a)" - } - - explain { - sql("select abs(k2) from d_table order by k1;") - contains "(k12a)" - } - - explain { - sql("select abs(k2)+1 from d_table order by k1;") - contains "(k12a)" - } - - explain { - sql("select sum(abs(k2)) from d_table group by k1 order by k1;") - contains "(k12a)" - } - - explain { - sql("select sum(abs(k2)+1) from d_table group by k1 order by k1;") - contains "(k12a)" - } - - explain { - sql("select sum(abs(k2)) from d_table group by k3;") - contains "(d_table)" - } + mv_rewrite_success("select k1,abs(k2) from d_table order by k1;", "k12a") + + mv_rewrite_success("select abs(k2) from d_table order by k1;", "k12a") + + mv_rewrite_success("select abs(k2)+1 from d_table order by k1;", "k12a") + + mv_rewrite_success("select sum(abs(k2)) from d_table group by k1 order by k1;", "k12a") + + mv_rewrite_success("select sum(abs(k2)+1) from d_table group by k1 order by k1;", "k12a") + + mv_rewrite_fail("select sum(abs(k2)) from d_table group by k3;", "k12a") } diff --git a/regression-test/suites/mv_p0/test_dup_mv_bin/test_dup_mv_bin.groovy b/regression-test/suites/mv_p0/test_dup_mv_bin/test_dup_mv_bin.groovy index 1a4b0d7400e49a..a7db2617fe6067 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_bin/test_dup_mv_bin.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_bin/test_dup_mv_bin.groovy @@ -45,70 +45,34 @@ suite ("test_dup_mv_bin") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,bin(k2) from d_table order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select k1,bin(k2) from d_table order by k1;", "k12b") qt_select_mv "select k1,bin(k2) from d_table order by k1;" - explain { - sql("select bin(k2) from d_table order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select bin(k2) from d_table order by k1;", "k12b") qt_select_mv_sub "select bin(k2) from d_table order by k1;" - explain { - sql("select bin(k2)+1 from d_table order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select bin(k2)+1 from d_table order by k1;", "k12b") qt_select_mv_sub_add "select concat(bin(k2),'a') from d_table order by k1;" - explain { - sql("select group_concat(bin(k2)) from d_table group by k1 order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select group_concat(bin(k2)) from d_table group by k1 order by k1;", "k12b") qt_select_group_mv "select group_concat(bin(k2)) from d_table group by k1 order by k1;" - explain { - sql("select group_concat(concat(bin(k2),'a')) from d_table group by k1 order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select group_concat(concat(bin(k2),'a')) from d_table group by k1 order by k1;", "k12b") qt_select_group_mv_add "select group_concat(concat(bin(k2),'a')) from d_table group by k1 order by k1;" - explain { - sql("select group_concat(bin(k2)) from d_table group by k3;") - contains "(d_table)" - } + mv_rewrite_fail("select group_concat(bin(k2)) from d_table group by k3;", "k12b") qt_select_group_mv_not "select group_concat(bin(k2)) from d_table group by k3 order by k3;" sql """set enable_stats=true;""" - explain { - sql("select k1,bin(k2) from d_table order by k1;") - contains "(k12b)" - } - - explain { - sql("select bin(k2) from d_table order by k1;") - contains "(k12b)" - } - - explain { - sql("select bin(k2)+1 from d_table order by k1;") - contains "(k12b)" - } - - explain { - sql("select group_concat(bin(k2)) from d_table group by k1 order by k1;") - contains "(k12b)" - } - - explain { - sql("select group_concat(concat(bin(k2),'a')) from d_table group by k1 order by k1;") - contains "(k12b)" - } - - explain { - sql("select group_concat(bin(k2)) from d_table group by k3;") - contains "(d_table)" - } + mv_rewrite_success("select k1,bin(k2) from d_table order by k1;", "k12b") + + mv_rewrite_success("select bin(k2) from d_table order by k1;", "k12b") + + mv_rewrite_success("select bin(k2)+1 from d_table order by k1;", "k12b") + + mv_rewrite_success("select group_concat(bin(k2)) from d_table group by k1 order by k1;", "k12b") + + mv_rewrite_success("select group_concat(concat(bin(k2),'a')) from d_table group by k1 order by k1;", "k12b") + + mv_rewrite_fail("select group_concat(bin(k2)) from d_table group by k3;", "k12b") } diff --git a/regression-test/suites/mv_p0/test_dup_mv_bitmap_hash/test_dup_mv_bitmap_hash.groovy b/regression-test/suites/mv_p0/test_dup_mv_bitmap_hash/test_dup_mv_bitmap_hash.groovy index 9ccba0b7c1456c..659f44de1e93c4 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_bitmap_hash/test_dup_mv_bitmap_hash.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_bitmap_hash/test_dup_mv_bitmap_hash.groovy @@ -43,16 +43,10 @@ suite ("test_dup_mv_bitmap_hash") { sql """analyze table d_table with sync;""" sql """set enable_stats=false;""" - explain { - sql("select bitmap_union_count(to_bitmap(k2)) from d_table group by k1 order by k1;") - contains "(k1g2bm)" - } + mv_rewrite_success("select bitmap_union_count(to_bitmap(k2)) from d_table group by k1 order by k1;", "k1g2bm") qt_select_mv "select bitmap_union_count(to_bitmap(k2)) from d_table group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select bitmap_union_count(to_bitmap(k2)) from d_table group by k1 order by k1;") - contains "(k1g2bm)" - } + mv_rewrite_success("select bitmap_union_count(to_bitmap(k2)) from d_table group by k1 order by k1;", "k1g2bm") createMV "create materialized view k1g3bm as select k1,bitmap_union(bitmap_hash(k3)) from d_table group by k1;" @@ -67,14 +61,8 @@ suite ("test_dup_mv_bitmap_hash") { sql """analyze table d_table with sync;""" sql """set enable_stats=false;""" - explain { - sql("select k1,bitmap_union_count(bitmap_hash(k3)) from d_table group by k1;") - contains "(k1g3bm)" - } + mv_rewrite_success("select k1,bitmap_union_count(bitmap_hash(k3)) from d_table group by k1;", "k1g3bm") qt_select_mv_sub "select k1,bitmap_union_count(bitmap_hash(k3)) from d_table group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,bitmap_union_count(bitmap_hash(k3)) from d_table group by k1;") - contains "(k1g3bm)" - } + mv_rewrite_success("select k1,bitmap_union_count(bitmap_hash(k3)) from d_table group by k1;", "k1g3bm") } diff --git a/regression-test/suites/mv_p0/test_dup_mv_expr_priority/test_dup_mv_expr_priority.groovy b/regression-test/suites/mv_p0/test_dup_mv_expr_priority/test_dup_mv_expr_priority.groovy index 9724937430365e..a78ed6ec878bf2 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_expr_priority/test_dup_mv_expr_priority.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_expr_priority/test_dup_mv_expr_priority.groovy @@ -41,16 +41,14 @@ suite ("test_dup_mv_expr_priority") { sql """analyze table table_ngrambf with sync;""" sql """set enable_stats=false;""" - explain { - sql("""select element_at(split_by_string(username,"_"),1) ,element_at(split_by_string(username,"_"),2) ,element_at(split_by_string(username,"_"),3) ,siteid,citycode from table_ngrambf order by citycode;""") - contains "(test_mv_1)" - } + mv_rewrite_success("""select element_at(split_by_string(username,"_"),1) ,element_at(split_by_string(username,"_"),2) ,element_at(split_by_string(username,"_"),3) ,siteid,citycode from table_ngrambf order by citycode;""", + "test_mv_1") + qt_select_mv """select element_at(split_by_string(username,"_"),1) ,element_at(split_by_string(username,"_"),2) ,element_at(split_by_string(username,"_"),3) ,siteid,citycode from table_ngrambf order by citycode;""" sql """set enable_stats=true;""" - explain { - sql("""select element_at(split_by_string(username,"_"),1) ,element_at(split_by_string(username,"_"),2) ,element_at(split_by_string(username,"_"),3) ,siteid,citycode from table_ngrambf order by citycode;""") - contains "(test_mv_1)" - } + mv_rewrite_success("""select element_at(split_by_string(username,"_"),1) ,element_at(split_by_string(username,"_"),2) ,element_at(split_by_string(username,"_"),3) ,siteid,citycode from table_ngrambf order by citycode;""", + "test_mv_1") + } diff --git a/regression-test/suites/mv_p0/test_dup_mv_plus/test_dup_mv_plus.groovy b/regression-test/suites/mv_p0/test_dup_mv_plus/test_dup_mv_plus.groovy index 0d277a744d84a1..5abe03e736b641 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_plus/test_dup_mv_plus.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_plus/test_dup_mv_plus.groovy @@ -45,93 +45,46 @@ suite ("test_dup_mv_plus") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,k2+1 from d_table order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select k1,k2+1 from d_table order by k1;", "k12p") qt_select_mv "select k1,k2+1 from d_table order by k1;" - explain { - sql("select k2+1 from d_table order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select k2+1 from d_table order by k1;", "k12p") qt_select_mv_sub "select k2+1 from d_table order by k1;" - explain { - sql("select k2+1 from d_table order by k1+1-1;") - contains "(k12p)" - } + mv_rewrite_success("select k2+1 from d_table order by k1+1-1;", "k12p") qt_select_mv_sub_add "select k2+1-1 from d_table order by k1+1-1;" - explain { - sql("select sum(k2+1) from d_table group by k1 order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k2+1) from d_table group by k1 order by k1;", "k12p") qt_select_group_mv "select sum(k2+1) from d_table group by k1 order by k1;" - explain { - sql("select sum(k1) from d_table group by k2+1 order by k2+1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k1) from d_table group by k2+1 order by k2+1;", "k12p") qt_select_group_mv "select sum(k1) from d_table group by k2+1 order by k2+1;" - explain { - sql("select sum(k1+1-1) from d_table group by k2+1 order by k2+1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k1+1-1) from d_table group by k2+1 order by k2+1;", "k12p") qt_select_group_mv_add "select sum(k1+1-1) from d_table group by k2+1 order by k2+1;" - explain { - sql("select sum(k2) from d_table group by k3;") - contains "(d_table)" - } + mv_rewrite_fail("select sum(k2) from d_table group by k3;", "k12p") qt_select_group_mv_not "select sum(k2) from d_table group by k3 order by k3;" - explain { - sql("select k1,k2+1 from d_table order by k2;") - contains "(d_table)" - } + mv_rewrite_fail("select k1,k2+1 from d_table order by k2;", "k12p") qt_select_mv "select k1,k2+1 from d_table order by k2;" sql """set enable_stats=true;""" - explain { - sql("select k1,k2+1 from d_table order by k1;") - contains "(k12p)" - } - - explain { - sql("select k2+1 from d_table order by k1;") - contains "(k12p)" - } - - explain { - sql("select k2+1 from d_table order by k1+1-1;") - contains "(k12p)" - } - - explain { - sql("select sum(k2+1) from d_table group by k1 order by k1;") - contains "(k12p)" - } - - explain { - sql("select sum(k1) from d_table group by k2+1 order by k2+1;") - contains "(k12p)" - } - - explain { - sql("select sum(k1+1-1) from d_table group by k2+1 order by k2+1;") - contains "(k12p)" - } - - explain { - sql("select sum(k2) from d_table group by k3;") - contains "(d_table)" - } - - explain { - sql("select k1,k2+1 from d_table order by k2;") - contains "(d_table)" - } + mv_rewrite_success("select k1,k2+1 from d_table order by k1;", "k12p") + + mv_rewrite_success("select k2+1 from d_table order by k1;", "k12p") + + mv_rewrite_success("select k2+1 from d_table order by k1+1-1;", "k12p") + + mv_rewrite_success("select sum(k2+1) from d_table group by k1 order by k1;", "k12p") + + mv_rewrite_success("select sum(k1) from d_table group by k2+1 order by k2+1;", "k12p") + + mv_rewrite_success("select sum(k1+1-1) from d_table group by k2+1 order by k2+1;", "k12p") + + mv_rewrite_fail("select sum(k2) from d_table group by k3;", "k12p") + + mv_rewrite_fail("select k1,k2+1 from d_table order by k2;", "k12p") + } diff --git a/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy b/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy index b25468dce623d9..562fba25b2e8a9 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_repeat/test_dup_mv_repeat.groovy @@ -42,15 +42,11 @@ suite ("test_dup_mv_repeat") { sql "analyze table db1 with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;") - contains "(dbviwe)" - } + mv_rewrite_success("SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;", + "dbviwe") qt_select_mv "SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;" sql """set enable_stats=true;""" - explain { - sql("SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;") - contains "(dbviwe)" - } + mv_rewrite_success("SELECT s AS s, sum(n) / count(DISTINCT dt) AS n FROM db1 GROUP BY GROUPING SETS((s)) order by 1;", + "dbviwe") } diff --git a/regression-test/suites/mv_p0/test_dup_mv_year/test_dup_mv_year.groovy b/regression-test/suites/mv_p0/test_dup_mv_year/test_dup_mv_year.groovy index 3e0b3b79666493..92a8d6520f3122 100644 --- a/regression-test/suites/mv_p0/test_dup_mv_year/test_dup_mv_year.groovy +++ b/regression-test/suites/mv_p0/test_dup_mv_year/test_dup_mv_year.groovy @@ -41,17 +41,11 @@ suite ("test_dup_mv_year") { sql """analyze table d_table with sync;""" sql """set enable_stats=false;""" - explain { - sql("select k1,year(k2) from d_table order by k1;") - contains "(k12y)" - } + mv_rewrite_success("select k1,year(k2) from d_table order by k1;", "k12y") qt_select_mv "select k1,year(k2) from d_table order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,year(k2) from d_table order by k1;") - contains "(k12y)" - } + mv_rewrite_success("select k1,year(k2) from d_table order by k1;", "k12y") createMV "create materialized view k13y as select k1,year(k3) from d_table;" @@ -59,15 +53,9 @@ suite ("test_dup_mv_year") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select year(k3) from d_table order by k1;") - contains "(k13y)" - } + mv_rewrite_success("select year(k3) from d_table order by k1;", "k13y") qt_select_mv_sub "select year(k3) from d_table order by k1;" sql """set enable_stats=false;""" - explain { - sql("select year(k3) from d_table order by k1;") - contains "(k13y)" - } + mv_rewrite_success("select year(k3) from d_table order by k1;", "k13y") } diff --git a/regression-test/suites/mv_p0/test_insert_multi/test_insert_multi.groovy b/regression-test/suites/mv_p0/test_insert_multi/test_insert_multi.groovy index b2e5a4e6ee934e..cb68765a55d9c2 100644 --- a/regression-test/suites/mv_p0/test_insert_multi/test_insert_multi.groovy +++ b/regression-test/suites/mv_p0/test_insert_multi/test_insert_multi.groovy @@ -34,15 +34,10 @@ suite ("test_insert_multi") { sql """analyze table sales_records with sync;""" sql """set enable_stats=false;""" - explain { - sql(" SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id order by 1;") - contains "(store_amt)" - } + mv_rewrite_success(" SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id order by 1;", "store_amt") qt_select_mv " SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id order by 1;" sql """set enable_stats=true;""" - explain { - sql(" SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id order by 1;") - contains "(store_amt)" - } + mv_rewrite_success(" SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id order by 1;", "store_amt") + } diff --git a/regression-test/suites/mv_p0/test_mv_dp/test_mv_dp.groovy b/regression-test/suites/mv_p0/test_mv_dp/test_mv_dp.groovy index 40c713578a11f7..50f1fd61806f2e 100644 --- a/regression-test/suites/mv_p0/test_mv_dp/test_mv_dp.groovy +++ b/regression-test/suites/mv_p0/test_mv_dp/test_mv_dp.groovy @@ -56,14 +56,11 @@ suite ("test_mv_dp") { time 10000 // limit inflight 10s } */ - explain { - sql("""select d, + mv_rewrite_success("""select d, bitmap_union_count(bitmap_from_array(cast(uid_list as array))), bitmap_union_count(bitmap_from_array(if(status='success', cast(uid_list as array), array()))) from dp - group by d;""") - contains "(view_2)" - } + group by d;""", "view_2") qt_select_mv """select d, bitmap_union_count(bitmap_from_array(cast(uid_list as array))), @@ -71,12 +68,9 @@ suite ("test_mv_dp") { from dp group by d order by 1;""" sql """set enable_stats=true;""" - explain { - sql("""select d, + mv_rewrite_success("""select d, bitmap_union_count(bitmap_from_array(cast(uid_list as array))), bitmap_union_count(bitmap_from_array(if(status='success', cast(uid_list as array), array()))) from dp - group by d;""") - contains "(view_2)" - } + group by d;""", "view_2") } diff --git a/regression-test/suites/mv_p0/test_mv_mor/test_mv_mor.groovy b/regression-test/suites/mv_p0/test_mv_mor/test_mv_mor.groovy index e88647dbbe71e5..b7f95123f5f9dd 100644 --- a/regression-test/suites/mv_p0/test_mv_mor/test_mv_mor.groovy +++ b/regression-test/suites/mv_p0/test_mv_mor/test_mv_mor.groovy @@ -40,10 +40,7 @@ suite ("test_mv_mor") { sql "insert into u_table select 1,2,1,2;" // do not match mv coz preagg is off, mv need contains all key column to make row count correct - explain { - sql("select k1,k2+k3 from u_table order by k1;") - contains "(u_table)" - } + mv_rewrite_success("select k1,k2+k3 from u_table order by k1;", "k123p") qt_select_mv "select k1,k2+k3 from u_table order by k1;" qt_select_mv "select * from `u_table` index `k123p` order by 1,2;" diff --git a/regression-test/suites/mv_p0/test_mv_mow/test_mv_mow.groovy b/regression-test/suites/mv_p0/test_mv_mow/test_mv_mow.groovy index a11efd874a8610..f584730ad1fca3 100644 --- a/regression-test/suites/mv_p0/test_mv_mow/test_mv_mow.groovy +++ b/regression-test/suites/mv_p0/test_mv_mow/test_mv_mow.groovy @@ -43,18 +43,12 @@ suite ("test_mv_mow") { sql """set enable_stats=false;""" - explain { - sql("select k1,k2+k3 from u_table order by k1;") - contains "(k123p)" - } + mv_rewrite_success("select k1,k2+k3 from u_table order by k1;", "k123p") qt_select_mv "select k1,k2+k3 from u_table order by k1;" qt_select_mv "select * from `u_table` index `k123p` order by 1,2;" qt_select_mv "select mv_k1 from `u_table` index `k123p` order by 1;" qt_select_mv "select `mv_(k2 + k3)` from `u_table` index `k123p` order by 1;" sql """set enable_stats=true;""" - explain { - sql("select k1,k2+k3 from u_table order by k1;") - contains "(k123p)" - } + mv_rewrite_success("select k1,k2+k3 from u_table order by k1;", "k123p") } diff --git a/regression-test/suites/mv_p0/test_ndv/test_ndv.groovy b/regression-test/suites/mv_p0/test_ndv/test_ndv.groovy index 1ffbdb864e3543..d2c9921edefe7a 100644 --- a/regression-test/suites/mv_p0/test_ndv/test_ndv.groovy +++ b/regression-test/suites/mv_p0/test_ndv/test_ndv.groovy @@ -40,37 +40,20 @@ suite ("test_ndv") { sql """analyze table user_tags with sync;""" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col,tag_id;" - explain { - sql("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") qt_select_mv "select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;" - explain { - sql("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") qt_select_mv "select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") - explain { - sql("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") + + mv_rewrite_success("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") - explain { - sql("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } } diff --git a/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy b/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy index 3395d7e14ee408..c6b1dd2d8a9b1c 100644 --- a/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy +++ b/regression-test/suites/mv_p0/test_nvl/test_nvl.groovy @@ -44,28 +44,17 @@ suite ("test_nvl") { sql """analyze table dwd with sync;""" sql """set enable_stats=false;""" - explain { - sql("select nvl(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } + mv_rewrite_success("select nvl(id,0) from dwd order by 1;", "dwd_mv") qt_select_mv "select nvl(id,0) from dwd order by 1;" - explain { - sql("select ifnull(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } + mv_rewrite_success("select ifnull(id,0) from dwd order by 1;", "dwd_mv") qt_select_mv "select ifnull(id,0) from dwd order by 1;" sql """set enable_stats=true;""" - explain { - sql("select nvl(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } + mv_rewrite_success("select nvl(id,0) from dwd order by 1;", "dwd_mv") + + mv_rewrite_success("select ifnull(id,0) from dwd order by 1;", "dwd_mv") - explain { - sql("select ifnull(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } sql """ drop materialized view dwd_mv on dwd; """ @@ -74,27 +63,14 @@ suite ("test_nvl") { create materialized view dwd_mv as select ifnull(id,0) from dwd; """) - explain { - sql("select nvl(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } + mv_rewrite_success("select nvl(id,0) from dwd order by 1;", "dwd_mv") qt_select_mv "select nvl(id,0) from dwd order by 1;" - explain { - sql("select ifnull(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } + mv_rewrite_success("select ifnull(id,0) from dwd order by 1;", "dwd_mv") qt_select_mv "select ifnull(id,0) from dwd order by 1;" sql """set enable_stats=false;""" - explain { - sql("select nvl(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } - - explain { - sql("select ifnull(id,0) from dwd order by 1;") - contains "(dwd_mv)" - } + mv_rewrite_success("select nvl(id,0) from dwd order by 1;", "dwd_mv") + mv_rewrite_success("select ifnull(id,0) from dwd order by 1;", "dwd_mv") } diff --git a/regression-test/suites/mv_p0/test_o2/test_o2.groovy b/regression-test/suites/mv_p0/test_o2/test_o2.groovy index dafa73327d16aa..665156056c0096 100644 --- a/regression-test/suites/mv_p0/test_o2/test_o2.groovy +++ b/regression-test/suites/mv_p0/test_o2/test_o2.groovy @@ -55,15 +55,11 @@ suite ("test_o2") { sql """analyze table o2_order_events with sync;""" sql """set enable_stats=false;""" - explain { - sql("select ts,metric_name,platform,sum(count_value) from o2_order_events group by ts,metric_name,platform;") - contains "(o2_order_events_mv)" - } + mv_rewrite_success("select ts,metric_name,platform,sum(count_value) from o2_order_events group by ts,metric_name,platform;", + "o2_order_events_mv") qt_select_mv "select ts,metric_name,platform,sum(count_value) from o2_order_events group by ts,metric_name,platform;" sql """set enable_stats=true;""" - explain { - sql("select ts,metric_name,platform,sum(count_value) from o2_order_events group by ts,metric_name,platform;") - contains "(o2_order_events_mv)" - } + mv_rewrite_success("select ts,metric_name,platform,sum(count_value) from o2_order_events group by ts,metric_name,platform;", + "o2_order_events_mv") } diff --git a/regression-test/suites/mv_p0/test_substr/test_substr.groovy b/regression-test/suites/mv_p0/test_substr/test_substr.groovy index 1bae7c181c5afe..c43c3ae6483acd 100644 --- a/regression-test/suites/mv_p0/test_substr/test_substr.groovy +++ b/regression-test/suites/mv_p0/test_substr/test_substr.groovy @@ -51,15 +51,11 @@ suite ("test_substr") { sql """analyze table dwd with sync;""" sql """set enable_stats=false;""" - explain { - sql("SELECT substr(created_at,1,10) as statistic_date, max(dt) as dt FROM dwd group by substr(created_at,1,10);") - contains "(dwd_mv)" - } + mv_rewrite_success("SELECT substr(created_at,1,10) as statistic_date, max(dt) as dt FROM dwd group by substr(created_at,1,10);", + "dwd_mv") qt_select_mv "SELECT substr(created_at,1,10) as statistic_date, max(dt) as dt FROM dwd group by substr(created_at,1,10);" sql """set enable_stats=true;""" - explain { - sql("SELECT substr(created_at,1,10) as statistic_date, max(dt) as dt FROM dwd group by substr(created_at,1,10);") - contains "(dwd_mv)" - } + mv_rewrite_success("SELECT substr(created_at,1,10) as statistic_date, max(dt) as dt FROM dwd group by substr(created_at,1,10);", + "dwd_mv") } diff --git a/regression-test/suites/mv_p0/test_tbl_name/test_tbl_name.groovy b/regression-test/suites/mv_p0/test_tbl_name/test_tbl_name.groovy index b609277ecd923f..f65e36484e7de9 100644 --- a/regression-test/suites/mv_p0/test_tbl_name/test_tbl_name.groovy +++ b/regression-test/suites/mv_p0/test_tbl_name/test_tbl_name.groovy @@ -42,29 +42,23 @@ suite ("test_tbl_name") { sql """analyze table functionality_olap with sync;""" sql """set enable_stats=false;""" - explain { - sql("""select + mv_rewrite_success("""select functionality_olap.id as id, sum(functionality_olap.score) as score_max from functionality_olap - group by functionality_olap.id order by 1,2; """) - contains "(MV_OLAP_SUM)" - } + group by functionality_olap.id order by 1,2; """, "MV_OLAP_SUM") qt_select_mv """select functionality_olap.id as id, sum(functionality_olap.score) as score_max from functionality_olap group by functionality_olap.id order by 1,2;""" - explain { - sql("""select + mv_rewrite_success("""select id, sum(score) as score_max from functionality_olap group by id order by 1,2; - """) - contains "(MV_OLAP_SUM)" - } + """, "MV_OLAP_SUM") qt_select_mv """select id, sum(score) as score_max @@ -72,22 +66,16 @@ suite ("test_tbl_name") { group by id order by 1,2; """ sql """set enable_stats=true;""" - explain { - sql("""select + mv_rewrite_success("""select functionality_olap.id as id, sum(functionality_olap.score) as score_max from functionality_olap - group by functionality_olap.id order by 1,2; """) - contains "(MV_OLAP_SUM)" - } + group by functionality_olap.id order by 1,2; """, "MV_OLAP_SUM") - explain { - sql("""select + mv_rewrite_success("""select id, sum(score) as score_max from functionality_olap group by id order by 1,2; - """) - contains "(MV_OLAP_SUM)" - } + """, "MV_OLAP_SUM") } diff --git a/regression-test/suites/mv_p0/test_upper_alias/test_upper_alias.groovy b/regression-test/suites/mv_p0/test_upper_alias/test_upper_alias.groovy index dc8c187f215e57..b62ec696224197 100644 --- a/regression-test/suites/mv_p0/test_upper_alias/test_upper_alias.groovy +++ b/regression-test/suites/mv_p0/test_upper_alias/test_upper_alias.groovy @@ -52,37 +52,21 @@ suite ("test_upper_alias") { sql "analyze table test_0401 with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;") - contains "(test_0401_mv)" - } + mv_rewrite_success("SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;", "test_0401_mv"); qt_select_mv "SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;" - explain { - sql("SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;") - contains "(test_0401_mv)" - } + mv_rewrite_success("SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;", "test_0401_mv") qt_select_mv "SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;" - explain { - sql("SELECT d_a AS d_b FROM test_0401 where d_a = 'xx' order by 1;") - contains "(test_0401_mv2)" - } + mv_rewrite_success("SELECT d_a AS d_b FROM test_0401 where d_a = 'xx' order by 1;", "test_0401_mv2") qt_select_mv "SELECT d_a AS d_b FROM test_0401 order by 1;" sql """set enable_stats=true;""" - explain { - sql("SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;") - contains "(test_0401_mv)" - } + mv_rewrite_any_success("SELECT upper(d_b) AS d_b FROM test_0401 GROUP BY upper(d_b) order by 1;", + ["test_0401_mv", "test_0401_mv2"]) - explain { - sql("SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;") - contains "(test_0401_mv)" - } + mv_rewrite_any_success("SELECT upper(d_b) AS d_bb FROM test_0401 GROUP BY upper(d_b) order by 1;", + ["test_0401_mv", "test_0401_mv2"]) - explain { - sql("SELECT d_a AS d_b FROM test_0401 where d_a = 'xx' order by 1;") - contains "(test_0401_mv2)" - } + mv_rewrite_success("SELECT d_a AS d_b FROM test_0401 where d_a = 'xx' order by 1;", "test_0401_mv2") } diff --git a/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy b/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy index 4d5c3f8336df83..3d139cbc01bbe7 100644 --- a/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy +++ b/regression-test/suites/mv_p0/test_user_activity/test_user_activity.groovy @@ -48,15 +48,11 @@ suite ("test_user_activity") { sql """analyze table u_axx with sync;""" sql """set enable_stats=false;""" - explain { - sql("select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;") - contains "(session_distribution_2)" - } + mv_rewrite_success("select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;", + "session_distribution_2") qt_select_group_mv "select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;" sql """set enable_stats=true;""" - explain { - sql("select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;") - contains "(session_distribution_2)" - } + mv_rewrite_success("select n_dx, percentile_approx(n_duration, 0.5) as p50, percentile_approx(n_duration, 0.90) as p90 FROM u_axx GROUP BY n_dx;", + "session_distribution_2") } diff --git a/regression-test/suites/mv_p0/unique/unique.groovy b/regression-test/suites/mv_p0/unique/unique.groovy index 58aa0529c7b449..e2a78c60bc2b0f 100644 --- a/regression-test/suites/mv_p0/unique/unique.groovy +++ b/regression-test/suites/mv_p0/unique/unique.groovy @@ -61,10 +61,7 @@ suite ("unique") { sql """analyze table u_table with sync;""" sql """set enable_stats=false;""" - explain { - sql("select k3,length(k1),k2 from u_table order by 1,2,3;") - contains "(k31l42)" - } + mv_rewrite_success("select k3,length(k1),k2 from u_table order by 1,2,3;", "k31l42") qt_select "select k3,length(k1),k2 from u_table order by 1,2,3;" @@ -76,10 +73,7 @@ suite ("unique") { qt_select_star "select * from u_table order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k3,length(k1),k2 from u_table order by 1,2,3;") - contains "(k31l42)" - } + mv_rewrite_success("select k3,length(k1),k2 from u_table order by 1,2,3;", "k31l42") // todo: support match query } diff --git a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV1/testAggQueryOnAggMV1.groovy b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV1/testAggQueryOnAggMV1.groovy index 6dfb8b6809cff3..70b016de2da80f 100644 --- a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV1/testAggQueryOnAggMV1.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV1/testAggQueryOnAggMV1.groovy @@ -45,7 +45,7 @@ suite ("testAggQueryOnAggMV1") { sql "analyze table emps with sync;" - mv_rewrite_all_fail("select * from emps order by empid;") + mv_rewrite_all_fail("select * from emps order by empid;", ["emps_mv", "emps_mv_count_key", "emps_mv_if"]) qt_select_star "select * from emps order by empid;" @@ -69,7 +69,7 @@ suite ("testAggQueryOnAggMV1") { qt_select_mv "select deptno, count(deptno) from emps where deptno=1 group by deptno order by deptno;" - mv_rewrite_all_fail("select deptno, sum(salary), max(commission) from emps where salary=1 group by deptno order by deptno;") + mv_rewrite_all_fail("select deptno, sum(salary), max(commission) from emps where salary=1 group by deptno order by deptno;", ["emps_mv", "emps_mv_count_key", "emps_mv_if"]) qt_select_mv "select deptno, sum(salary), max(commission) from emps where salary=1 group by deptno order by deptno;" diff --git a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV10/testAggQueryOnAggMV10.groovy b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV10/testAggQueryOnAggMV10.groovy index a9638bfb1feee6..a25ac24404e181 100644 --- a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV10/testAggQueryOnAggMV10.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV10/testAggQueryOnAggMV10.groovy @@ -43,26 +43,16 @@ suite ("testAggQueryOnAggMV10") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { - sql("select deptno, commission, sum(salary) + 1 from emps group by rollup (deptno, commission);") - contains "(emps_mv)" - } + mv_rewrite_success("select deptno, commission, sum(salary) + 1 from emps group by rollup (deptno, commission);", + "emps_mv") qt_select_mv "select deptno, commission, sum(salary) + 1 from emps group by rollup (deptno, commission) order by 1,2;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select deptno, commission, sum(salary) + 1 from emps group by rollup (deptno, commission);") - contains "(emps_mv)" - } + mv_rewrite_success("select deptno, commission, sum(salary) + 1 from emps group by rollup (deptno, commission);", + "emps_mv") } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV11/testAggQueryOnAggMV11.groovy b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV11/testAggQueryOnAggMV11.groovy index 8ee78912c62c85..c26db8e034e66a 100644 --- a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV11/testAggQueryOnAggMV11.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV11/testAggQueryOnAggMV11.groovy @@ -43,26 +43,15 @@ suite ("testAggQueryOnAggMV11") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { - sql("select deptno, count(salary) + count(1) from emps group by deptno;") - contains "(emps)" - } + mv_rewrite_fail("select deptno, count(salary) + count(1) from emps group by deptno;", "emps_mv") qt_select_mv "select deptno, count(salary) + count(1) from emps group by deptno order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") + + mv_rewrite_fail("select deptno, count(salary) + count(1) from emps group by deptno;", "emps_mv") - explain { - sql("select deptno, count(salary) + count(1) from emps group by deptno;") - contains "(emps)" - } } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV2/testAggQueryOnAggMV2.groovy b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV2/testAggQueryOnAggMV2.groovy index 6b47e292d59fef..945e4e9194910f 100644 --- a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV2/testAggQueryOnAggMV2.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV2/testAggQueryOnAggMV2.groovy @@ -45,26 +45,16 @@ suite ("testAggQueryOnAggMV2") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid, salary;" - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where (sum_salary * 2) > 3 order by deptno ;") - contains "(emps_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where (sum_salary * 2) > 3 order by deptno ;", + "emps_mv") qt_select_mv "select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where (sum_salary * 2) > 3 order by deptno ;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where (sum_salary * 2) > 3 order by deptno ;") - contains "(emps_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where (sum_salary * 2) > 3 order by deptno ;", + "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV3/testAggQueryOnAggMV3.groovy b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV3/testAggQueryOnAggMV3.groovy index c3183041d5c2e9..46457f0d0a81d4 100644 --- a/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV3/testAggQueryOnAggMV3.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQueryOnAggMV3/testAggQueryOnAggMV3.groovy @@ -44,38 +44,23 @@ suite ("testAggQueryOnAggMV3") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - - explain { - sql("select commission, sum(salary) from emps where deptno > 0 and commission * (deptno + commission) = 100 group by commission order by commission;") - contains "(emps_mv)" - } + mv_rewrite_success("select commission, sum(salary) from emps where deptno > 0 and commission * (deptno + commission) = 100 group by commission order by commission;", + "emps_mv") qt_select_mv "select commission, sum(salary) from emps where commission * (deptno + commission) = 100 group by commission order by commission;" - explain { - sql("select commission, sum(salary) from emps where deptno > 0 and commission = 100 group by commission order by commission;") - contains "(emps_mv)" - } + mv_rewrite_success("select commission, sum(salary) from emps where deptno > 0 and commission = 100 group by commission order by commission;", + "emps_mv") qt_select_mv "select commission, sum(salary) from emps where commission = 100 group by commission order by commission;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") + + mv_rewrite_success("select commission, sum(salary) from emps where deptno > 0 and commission * (deptno + commission) = 100 group by commission order by commission;", + "emps_mv") - explain { - sql("select commission, sum(salary) from emps where deptno > 0 and commission * (deptno + commission) = 100 group by commission order by commission;") - contains "(emps_mv)" - } - - explain { - sql("select commission, sum(salary) from emps where deptno > 0 and commission = 100 group by commission order by commission;") - contains "(emps_mv)" - } + mv_rewrite_success("select commission, sum(salary) from emps where deptno > 0 and commission = 100 group by commission order by commission;", + "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV5/testAggQuqeryOnAggMV5.groovy b/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV5/testAggQuqeryOnAggMV5.groovy index 393133e7701738..1fa4342952cad4 100644 --- a/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV5/testAggQuqeryOnAggMV5.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV5/testAggQuqeryOnAggMV5.groovy @@ -43,26 +43,16 @@ suite ("testAggQuqeryOnAggMV5") { sql """analyze table emps with sync;""" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where sum_salary>0;") - contains "(emps_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where sum_salary>0;", + "emps_mv") qt_select_mv "select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where sum_salary>10 order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where sum_salary>0;") - contains "(emps_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from emps group by deptno) a where sum_salary>0;", + "emps_mv") } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV6/testAggQuqeryOnAggMV6.groovy b/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV6/testAggQuqeryOnAggMV6.groovy index 8d67b57168d243..3cca0273051f0a 100644 --- a/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV6/testAggQuqeryOnAggMV6.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV6/testAggQuqeryOnAggMV6.groovy @@ -43,26 +43,16 @@ suite ("testAggQuqeryOnAggMV6") { sql """analyze table emps with sync;""" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from emps where deptno>=0 group by deptno) a where sum_salary>10;") - contains "(emps_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from emps where deptno>=0 group by deptno) a where sum_salary>10;", + "emps_mv") qt_select_mv "select * from (select deptno, sum(salary) as sum_salary from emps where deptno>=20 group by deptno) a where sum_salary>10 order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from emps where deptno>=0 group by deptno) a where sum_salary>10;") - contains "(emps_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from emps where deptno>=0 group by deptno) a where sum_salary>10;", + "emps_mv") } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV7/testAggQuqeryOnAggMV7.groovy b/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV7/testAggQuqeryOnAggMV7.groovy index 454c0e8b71a7f4..1a606141e38f04 100644 --- a/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV7/testAggQuqeryOnAggMV7.groovy +++ b/regression-test/suites/mv_p0/ut/testAggQuqeryOnAggMV7/testAggQuqeryOnAggMV7.groovy @@ -43,26 +43,14 @@ suite ("testAggQuqeryOnAggMV7") { sql """analyze table emps with sync;""" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { - sql("select deptno, sum(salary) from emps where deptno>=20 group by deptno;") - contains "(emps_mv)" - } + mv_rewrite_success("select deptno, sum(salary) from emps where deptno>=20 group by deptno;", "emps_mv") qt_select_mv "select deptno, sum(salary) from emps where deptno>=20 group by deptno order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select deptno, sum(salary) from emps where deptno>=20 group by deptno;") - contains "(emps_mv)" - } + mv_rewrite_success("select deptno, sum(salary) from emps where deptno>=20 group by deptno;", "emps_mv") } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testAggregateMVCalcAggFunctionQuery/testAggregateMVCalcAggFunctionQuery.groovy b/regression-test/suites/mv_p0/ut/testAggregateMVCalcAggFunctionQuery/testAggregateMVCalcAggFunctionQuery.groovy index 7fda21f349f174..7f2427e275de47 100644 --- a/regression-test/suites/mv_p0/ut/testAggregateMVCalcAggFunctionQuery/testAggregateMVCalcAggFunctionQuery.groovy +++ b/regression-test/suites/mv_p0/ut/testAggregateMVCalcAggFunctionQuery/testAggregateMVCalcAggFunctionQuery.groovy @@ -43,26 +43,14 @@ suite ("testAggregateMVCalcAggFunctionQuery") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - - explain { - sql("select deptno, sum(salary + 1) from emps where deptno > 10 group by deptno;") - notContains "(emps_mv)" - } + mv_rewrite_fail("select deptno, sum(salary + 1) from emps where deptno > 10 group by deptno;", "emps_mv") qt_select_mv "select deptno, sum(salary + 1) from emps where deptno > 10 group by deptno order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } - explain { - sql("select deptno, sum(salary + 1) from emps where deptno > 10 group by deptno;") - notContains "(emps_mv)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") + + mv_rewrite_fail("select deptno, sum(salary + 1) from emps where deptno > 10 group by deptno;", "emps_mv") } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy b/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy index 43bdaccb35a1e2..69410ae7be5d0d 100644 --- a/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy +++ b/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy @@ -39,38 +39,24 @@ suite ("testBitmapUnionInQuery") { sql "analyze table user_tags with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col,tag_id;" - explain { - sql("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;", + "user_tags_mv") qt_select_mv "select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;" - explain { - sql("select user_id, bitmap_count(bitmap_union(to_bitmap(tag_id))) a from user_tags group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, bitmap_count(bitmap_union(to_bitmap(tag_id))) a from user_tags group by user_id having a>1 order by a;", + "user_tags_mv") qt_select_mv "select user_id, bitmap_count(bitmap_union(to_bitmap(tag_id))) a from user_tags group by user_id having a>1 order by a;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") - explain { - sql("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;", + "user_tags_mv") - explain { - sql("select user_id, bitmap_count(bitmap_union(to_bitmap(tag_id))) a from user_tags group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, bitmap_count(bitmap_union(to_bitmap(tag_id))) a from user_tags group by user_id having a>1 order by a;", + "user_tags_mv") } diff --git a/regression-test/suites/mv_p0/ut/testCountDistinctToBitmap/testCountDistinctToBitmap.groovy b/regression-test/suites/mv_p0/ut/testCountDistinctToBitmap/testCountDistinctToBitmap.groovy index 0fad3830ff1546..12152aad369e1d 100644 --- a/regression-test/suites/mv_p0/ut/testCountDistinctToBitmap/testCountDistinctToBitmap.groovy +++ b/regression-test/suites/mv_p0/ut/testCountDistinctToBitmap/testCountDistinctToBitmap.groovy @@ -39,28 +39,18 @@ suite ("testCountDistinctToBitmap") { sql "analyze table user_tags with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col,tag_id;" - explain { - sql("select user_id, count(distinct tag_id) a from user_tags group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, count(distinct tag_id) a from user_tags group by user_id having a>1 order by a;", + "user_tags_mv") qt_select_mv "select user_id, count(distinct tag_id) a from user_tags group by user_id having a>1 order by a;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") - explain { - sql("select user_id, count(distinct tag_id) a from user_tags group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, count(distinct tag_id) a from user_tags group by user_id having a>1 order by a;", + "user_tags_mv") sql """ DROP TABLE IF EXISTS user_tags2; """ @@ -80,26 +70,16 @@ suite ("testCountDistinctToBitmap") { sql """insert into user_tags2 values("2020-01-01",1,"a",2);""" - explain { - sql("select * from user_tags2 order by time_col;") - contains "(user_tags2)" - } + mv_rewrite_fail("select * from user_tags2 order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags2 order by time_col,tag_id;" - explain { - sql("select user_id, count(distinct tag_id) a from user_tags2 group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, count(distinct tag_id) a from user_tags2 group by user_id having a>1 order by a;", + "user_tags_mv") qt_select_mv "select user_id, count(distinct tag_id) a from user_tags2 group by user_id having a>1 order by a;" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags2 order by time_col;") - contains "(user_tags2)" - } - - explain { - sql("select user_id, count(distinct tag_id) a from user_tags2 group by user_id having a>1 order by a;") - contains "(user_tags_mv)" - } + mv_rewrite_fail("select * from user_tags2 order by time_col;", "user_tags_mv") + + mv_rewrite_success("select user_id, count(distinct tag_id) a from user_tags2 group by user_id having a>1 order by a;", + "user_tags_mv") } diff --git a/regression-test/suites/mv_p0/ut/testIncorrectMVRewriteInSubquery/testIncorrectMVRewriteInSubquery.groovy b/regression-test/suites/mv_p0/ut/testIncorrectMVRewriteInSubquery/testIncorrectMVRewriteInSubquery.groovy index 22ef07970fb0c1..c671e106a10648 100644 --- a/regression-test/suites/mv_p0/ut/testIncorrectMVRewriteInSubquery/testIncorrectMVRewriteInSubquery.groovy +++ b/regression-test/suites/mv_p0/ut/testIncorrectMVRewriteInSubquery/testIncorrectMVRewriteInSubquery.groovy @@ -38,27 +38,17 @@ suite ("testIncorrectMVRewriteInSubquery") { sql "analyze table user_tags with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col, tag_id;" - explain { - sql("select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags where user_name in (select user_name from user_tags group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;") - contains "(user_tags)" - } + mv_rewrite_fail("select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags where user_name in (select user_name from user_tags group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;", + "user_tags_mv") + qt_select_mv "select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags where user_name in (select user_name from user_tags group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } - - explain { - sql("select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags where user_name in (select user_name from user_tags group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") + mv_rewrite_fail("select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags where user_name in (select user_name from user_tags group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;", + "user_tags_mv") } diff --git a/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy b/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy index 0b168d6bd4368c..dbece0c9592364 100644 --- a/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy +++ b/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy @@ -38,26 +38,14 @@ suite ("testIncorrectRewriteCountDistinct") { sql "analyze table user_tags with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col,tag_id;" - explain { - sql("select user_name, count(distinct tag_id) from user_tags group by user_name;") - contains "(user_tags)" - } + mv_rewrite_fail("select user_name, count(distinct tag_id) from user_tags group by user_name;", "user_tags_mv") qt_select_mv "select user_name, count(distinct tag_id) from user_tags group by user_name order by user_name;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } - - explain { - sql("select user_name, count(distinct tag_id) from user_tags group by user_name;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") + + mv_rewrite_fail("select user_name, count(distinct tag_id) from user_tags group by user_name;", "user_tags_mv") } diff --git a/regression-test/suites/mv_p0/ut/testJoinOnLeftProjectToJoin/testJoinOnLeftProjectToJoin.groovy b/regression-test/suites/mv_p0/ut/testJoinOnLeftProjectToJoin/testJoinOnLeftProjectToJoin.groovy index fe60cbed15c8cc..3caf0000c1824d 100644 --- a/regression-test/suites/mv_p0/ut/testJoinOnLeftProjectToJoin/testJoinOnLeftProjectToJoin.groovy +++ b/regression-test/suites/mv_p0/ut/testJoinOnLeftProjectToJoin/testJoinOnLeftProjectToJoin.groovy @@ -53,17 +53,12 @@ suite ("testJoinOnLeftProjectToJoin") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from (select deptno , sum(salary) from emps group by deptno) A join (select deptno, max(cost) from depts group by deptno ) B on A.deptno = B.deptno;") - contains "(emps_mv)" - contains "(depts_mv)" - } + mv_rewrite_all_success("select * from (select deptno , sum(salary) from emps group by deptno) A join (select deptno, max(cost) from depts group by deptno ) B on A.deptno = B.deptno;", + ["emps_mv", "depts_mv"]) + qt_select_mv "select * from (select deptno , sum(salary) from emps group by deptno) A join (select deptno, max(cost) from depts group by deptno ) B on A.deptno = B.deptno order by A.deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from (select deptno , sum(salary) from emps group by deptno) A join (select deptno, max(cost) from depts group by deptno ) B on A.deptno = B.deptno;") - contains "(emps_mv)" - contains "(depts_mv)" - } + mv_rewrite_all_success("select * from (select deptno , sum(salary) from emps group by deptno) A join (select deptno, max(cost) from depts group by deptno ) B on A.deptno = B.deptno;", + ["emps_mv", "depts_mv"]) } diff --git a/regression-test/suites/mv_p0/ut/testNDVToHll/testNDVToHll.groovy b/regression-test/suites/mv_p0/ut/testNDVToHll/testNDVToHll.groovy index 28c7b6d946611c..a9456cb4e79c96 100644 --- a/regression-test/suites/mv_p0/ut/testNDVToHll/testNDVToHll.groovy +++ b/regression-test/suites/mv_p0/ut/testNDVToHll/testNDVToHll.groovy @@ -40,37 +40,20 @@ suite ("testNDVToHll") { sql "analyze table user_tags with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") qt_select_star "select * from user_tags order by time_col,tag_id;" - explain { - sql("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") qt_select_mv "select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;" - explain { - sql("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") qt_select_mv "select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;" sql """set enable_stats=true;""" - explain { - sql("select * from user_tags order by time_col;") - contains "(user_tags)" - } + mv_rewrite_fail("select * from user_tags order by time_col;", "user_tags_mv") - explain { - sql("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } + mv_rewrite_success("select user_id, ndv(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") + + mv_rewrite_success("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;", "user_tags_mv") - explain { - sql("select user_id, approx_count_distinct(tag_id) a from user_tags group by user_id order by user_id;") - contains "(user_tags_mv)" - } } diff --git a/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy b/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy index 1a78f9843e6717..2aa88d84f3d433 100644 --- a/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy +++ b/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy @@ -42,26 +42,14 @@ suite ("testOrderByQueryOnProjectView") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - - explain { - sql("select empid from emps where deptno > 0 order by deptno;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid from emps where deptno > 0 order by deptno;", "emps_mv") qt_select_mv "select empid from emps order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } - explain { - sql("select empid from emps where deptno > 0 order by deptno;") - contains "(emps_mv)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") + + mv_rewrite_success("select empid from emps where deptno > 0 order by deptno;", "emps_mv") } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy b/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy index f7b277b08aa828..d95c3e2fc6de88 100644 --- a/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy +++ b/regression-test/suites/mv_p0/ut/testProjectionMV1/testProjectionMV1.groovy @@ -46,48 +46,28 @@ suite ("testProjectionMV1") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - - explain { - sql("select empid, deptno from emps where deptno > 0 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid, deptno from emps where deptno > 0 order by empid;", "emps_mv") qt_select_mv "select empid, deptno from emps order by empid;" - explain { - sql("select empid, sum(deptno) from emps where deptno > 0 group by empid order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid, sum(deptno) from emps where deptno > 0 group by empid order by empid;", + "emps_mv") qt_select_mv "select empid, sum(deptno) from emps group by empid order by empid;" - explain { - sql("select deptno, sum(empid) from emps where deptno > 0 group by deptno order by deptno;") - contains "(emps_mv)" - } + mv_rewrite_success("select deptno, sum(empid) from emps where deptno > 0 group by deptno order by deptno;", + "emps_mv") qt_select_mv "select deptno, sum(empid) from emps group by deptno order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } - explain { - sql("select empid, deptno from emps where deptno > 0 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select empid, sum(deptno) from emps where deptno > 0 group by empid order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid, deptno from emps where deptno > 0 order by empid;", "emps_mv") - explain { - sql("select deptno, sum(empid) from emps where deptno > 0 group by deptno order by deptno;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid, sum(deptno) from emps where deptno > 0 group by empid order by empid;", + "emps_mv") + + mv_rewrite_success("select deptno, sum(empid) from emps where deptno > 0 group by deptno order by deptno;", + "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testProjectionMV2/testProjectionMV2.groovy b/regression-test/suites/mv_p0/ut/testProjectionMV2/testProjectionMV2.groovy index 3ed5a756b4dc32..2f7548b14c8635 100644 --- a/regression-test/suites/mv_p0/ut/testProjectionMV2/testProjectionMV2.groovy +++ b/regression-test/suites/mv_p0/ut/testProjectionMV2/testProjectionMV2.groovy @@ -41,37 +41,19 @@ suite ("testProjectionMV2") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - - explain { - sql("select empid + 1 from emps where deptno = 1 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid + 1 from emps where deptno = 1 order by empid;", "emps_mv") qt_select_mv "select empid + 1 from emps where deptno = 1 order by empid;" - explain { - sql("select name from emps where deptno -1 = 0 order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select name from emps where deptno -1 = 0 order by empid;", "emps_mv") qt_select_base "select name from emps where deptno -1 = 0 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } - explain { - sql("select empid + 1 from emps where deptno = 1 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") + + mv_rewrite_success("select empid + 1 from emps where deptno = 1 order by empid;", "emps_mv") - explain { - sql("select name from emps where deptno -1 = 0 order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select name from emps where deptno -1 = 0 order by empid;", "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testProjectionMV3/testProjectionMV3.groovy b/regression-test/suites/mv_p0/ut/testProjectionMV3/testProjectionMV3.groovy index aaeb0ec19fb301..e4ea1aa4de023e 100644 --- a/regression-test/suites/mv_p0/ut/testProjectionMV3/testProjectionMV3.groovy +++ b/regression-test/suites/mv_p0/ut/testProjectionMV3/testProjectionMV3.groovy @@ -43,37 +43,19 @@ suite ("testProjectionMV3") { sql """analyze table emps with sync;""" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - - explain { - sql("select empid + 1, name from emps where deptno = 1 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select empid + 1, name from emps where deptno = 1 order by empid;", "emps_mv") qt_select_mv "select empid + 1, name from emps where deptno = 1 order by empid;" - explain { - sql("select name from emps where deptno = 1 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select name from emps where deptno = 1 order by empid;", "emps_mv") qt_select_mv2 "select name from emps where deptno = 1 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } - explain { - sql("select empid + 1, name from emps where deptno = 1 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") + + mv_rewrite_success("select empid + 1, name from emps where deptno = 1 order by empid;", "emps_mv") - explain { - sql("select name from emps where deptno = 1 order by empid;") - contains "(emps_mv)" - } + mv_rewrite_success("select name from emps where deptno = 1 order by empid;", "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testProjectionMV4/testProjectionMV4.groovy b/regression-test/suites/mv_p0/ut/testProjectionMV4/testProjectionMV4.groovy index 3799670d607a6d..0c6f737deabb29 100644 --- a/regression-test/suites/mv_p0/ut/testProjectionMV4/testProjectionMV4.groovy +++ b/regression-test/suites/mv_p0/ut/testProjectionMV4/testProjectionMV4.groovy @@ -43,29 +43,16 @@ suite ("testProjectionMV4") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - qt_select_mv "select name from emps where deptno > 1 and salary > 1 order by name;" - explain { - sql("select empid from emps where deptno > 1 and empid > 1 order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select empid from emps where deptno > 1 and empid > 1 order by empid;", "emps_mv") qt_select_base "select empid from emps where deptno > 1 and empid > 1 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") - explain { - sql("select empid from emps where deptno > 1 and empid > 1 order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select empid from emps where deptno > 1 and empid > 1 order by empid;", "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy b/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy index 67da303968e678..0cfd80fcb06b4e 100644 --- a/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy +++ b/regression-test/suites/mv_p0/ut/testSelectMVWithTableAlias/testSelectMVWithTableAlias.groovy @@ -38,7 +38,7 @@ suite ("testSelectMVWithTableAlias") { sql "analyze table user_tags with sync;" - mv_rewrite_all_fail("select * from user_tags order by time_col;") + mv_rewrite_all_fail("select * from user_tags order by time_col;", ["user_tags_mv"]) qt_select_star "select * from user_tags order by time_col;" diff --git a/regression-test/suites/mv_p0/ut/testSingleMVMultiUsage/testSingleMVMultiUsage.groovy b/regression-test/suites/mv_p0/ut/testSingleMVMultiUsage/testSingleMVMultiUsage.groovy index 71f3d876496c46..006b72885ec112 100644 --- a/regression-test/suites/mv_p0/ut/testSingleMVMultiUsage/testSingleMVMultiUsage.groovy +++ b/regression-test/suites/mv_p0/ut/testSingleMVMultiUsage/testSingleMVMultiUsage.groovy @@ -42,13 +42,9 @@ suite ("testSingleMVMultiUsage") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { sql("select * from (select deptno, empid from emps where deptno>100) A join (select deptno, empid from emps where deptno >200) B using (deptno);") contains "(emps_mv)" @@ -56,10 +52,7 @@ suite ("testSingleMVMultiUsage") { } qt_select_mv "select * from (select deptno, empid from emps where deptno>100) A join (select deptno, empid from emps where deptno >200) B using (deptno) order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") explain { sql("select * from (select deptno, empid from emps where deptno>100) A join (select deptno, empid from emps where deptno >200) B using (deptno);") diff --git a/regression-test/suites/mv_p0/ut/testSubQuery/testSubQuery.groovy b/regression-test/suites/mv_p0/ut/testSubQuery/testSubQuery.groovy index 548c2a7d59936d..6c1747059d1ae3 100644 --- a/regression-test/suites/mv_p0/ut/testSubQuery/testSubQuery.groovy +++ b/regression-test/suites/mv_p0/ut/testSubQuery/testSubQuery.groovy @@ -46,17 +46,11 @@ suite ("testSubQuery") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" qt_select_mv "select empid, deptno, salary from emps e1 where empid = (select max(empid) from emps where deptno = e1.deptno) order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") } diff --git a/regression-test/suites/mv_p0/ut/testUnionDistinct/testUnionDistinct.groovy b/regression-test/suites/mv_p0/ut/testUnionDistinct/testUnionDistinct.groovy index 595650ee2e85d6..f504c81f214e91 100644 --- a/regression-test/suites/mv_p0/ut/testUnionDistinct/testUnionDistinct.groovy +++ b/regression-test/suites/mv_p0/ut/testUnionDistinct/testUnionDistinct.groovy @@ -42,13 +42,9 @@ suite ("testUnionDistinct") { sql "analyze table emps with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") qt_select_star "select * from emps order by empid;" - explain { sql("select empid, deptno from emps where empid >1 union select empid, deptno from emps where empid <0 order by empid;") contains "(emps_mv)" @@ -56,15 +52,11 @@ suite ("testUnionDistinct") { } qt_select_mv "select * from (select empid, deptno from emps where empid >1 union select empid, deptno from emps where empid <0) t order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from emps order by empid;") - contains "(emps)" - } + mv_rewrite_fail("select * from emps order by empid;", "emps_mv") explain { sql("select empid, deptno from emps where empid >1 union select empid, deptno from emps where empid <0 order by empid;") contains "(emps_mv)" notContains "(emps)" } - } \ No newline at end of file diff --git a/regression-test/suites/mv_p0/where/k123/k123.groovy b/regression-test/suites/mv_p0/where/k123/k123.groovy index 554d44f41e4ab7..366fc76580ff48 100644 --- a/regression-test/suites/mv_p0/where/k123/k123.groovy +++ b/regression-test/suites/mv_p0/where/k123/k123.groovy @@ -49,83 +49,42 @@ suite ("k123p") { qt_select_star "select * from d_table order by k1;" - explain { - sql("select k1,k2+k3 from d_table order by k1;") - contains "(d_table)" - } + mv_rewrite_all_fail("select k1,k2+k3 from d_table order by k1;", ["k123p1w", "k123p4w"]) qt_select_mv "select k1,k2+k3 from d_table order by k1;" - explain { - sql("select k1,k2+k3 from d_table where k1 = 1 order by k1;") - contains "(k123p1w)" - } + mv_rewrite_success("select k1,k2+k3 from d_table where k1 = 1 order by k1;", "k123p1w") qt_select_mv "select k1,k2+k3 from d_table where k1 = 1 order by k1;" - explain { - sql("select k1,k2+k3 from d_table where k1 = 2 order by k1;") - contains "(d_table)" - } + mv_rewrite_all_fail("select k1,k2+k3 from d_table where k1 = 2 order by k1;", ["k123p1w", "k123p4w"]) qt_select_mv "select k1,k2+k3 from d_table where k1 = 2 order by k1;" - explain { - sql("select k1,k2+k3 from d_table where k1 = '1' order by k1;") - contains "(k123p1w)" - } + mv_rewrite_success("select k1,k2+k3 from d_table where k1 = '1' order by k1;", "k123p1w") qt_select_mv "select k1,k2+k3 from d_table where k1 = '1' order by k1;" - explain { - sql("select k1,k2+k3 from d_table where k4 = 'b' order by k1;") - contains "(k123p4w)" - } + mv_rewrite_success("select k1,k2+k3 from d_table where k4 = 'b' order by k1;", "k123p4w") qt_select_mv "select k1,k2+k3 from d_table where k4 = 'b' order by k1;" - explain { - sql("select k1,k2+k3 from d_table where k4 = 'a' order by k1;") - contains "(d_table)" - } + mv_rewrite_all_fail("select k1,k2+k3 from d_table where k4 = 'a' order by k1;", ["k123p1w", "k123p4w"]) qt_select_mv "select k1,k2+k3 from d_table where k4 = 'a' order by k1;" - explain { - sql("""select k1,k2+k3 from d_table where k1 = 2 and k4 = "b";""") - contains "(k123p4w)" - } + mv_rewrite_success("""select k1,k2+k3 from d_table where k1 = 2 and k4 = "b";""", "k123p4w") qt_select_mv """select k1,k2+k3 from d_table where k1 = 2 and k4 = "b" order by k1;""" qt_select_mv_constant """select bitmap_empty() from d_table where true;""" sql """set enable_stats=true;""" - explain { - sql("select k1,k2+k3 from d_table order by k1;") - contains "(d_table)" - } - - explain { - sql("select k1,k2+k3 from d_table where k1 = 1 order by k1;") - contains "(k123p1w)" - } - - explain { - sql("select k1,k2+k3 from d_table where k1 = 2 order by k1;") - contains "(d_table)" - } - - explain { - sql("select k1,k2+k3 from d_table where k1 = '1' order by k1;") - contains "(k123p1w)" - } - - explain { - sql("select k1,k2+k3 from d_table where k4 = 'b' order by k1;") - contains "(k123p4w)" - } - - explain { - sql("select k1,k2+k3 from d_table where k4 = 'a' order by k1;") - contains "(d_table)" - } - - explain { - sql("""select k1,k2+k3 from d_table where k1 = 2 and k4 = "b";""") - contains "(k123p4w)" - } + mv_rewrite_all_fail("select k1,k2+k3 from d_table order by k1;", ["k123p1w", "k123p4w"]) + + mv_rewrite_success("select k1,k2+k3 from d_table where k1 = 1 order by k1;", "k123p1w") + + mv_rewrite_all_fail("select k1,k2+k3 from d_table where k1 = 2 order by k1;", ["k123p1w", "k123p4w"]) + + mv_rewrite_success("select k1,k2+k3 from d_table where k1 = '1' order by k1;", "k123p1w") + + mv_rewrite_success("select k1,k2+k3 from d_table where k4 = 'b' order by k1;", "k123p4w") + + mv_rewrite_all_fail("select k1,k2+k3 from d_table where k4 = 'a' order by k1;", ["k123p1w", "k123p4w"]) + + mv_rewrite_success("""select k1,k2+k3 from d_table where k1 = 2 and k4 = "b";""", "k123p4w") + } diff --git a/regression-test/suites/mv_p0/where/k123_nereids/k123_nereids.groovy b/regression-test/suites/mv_p0/where/k123_nereids/k123_nereids.groovy index 21c01eafebe6dd..7a05256d2dc4a9 100644 --- a/regression-test/suites/mv_p0/where/k123_nereids/k123_nereids.groovy +++ b/regression-test/suites/mv_p0/where/k123_nereids/k123_nereids.groovy @@ -50,7 +50,7 @@ suite ("k123p_nereids") { sql "analyze table d_table with sync;" - mv_rewrite_all_fail("select k1,k2+k3 from d_table order by k1;") + mv_rewrite_all_fail("select k1,k2+k3 from d_table order by k1;", ["k123p1w", "k123p4w", "kwh1", "kwh2"]) qt_select_mv "select k1,k2+k3 from d_table order by k1;" @@ -59,7 +59,7 @@ suite ("k123p_nereids") { qt_select_mv "select k1,k2+k3 from d_table where k1 = 1 order by k1;" - mv_rewrite_all_fail("select k1,k2+k3 from d_table where k1 = 2 order by k1;") + mv_rewrite_all_fail("select k1,k2+k3 from d_table where k1 = 2 order by k1;", ["k123p1w", "k123p4w", "kwh1", "kwh2"]) qt_select_mv "select k1,k2+k3 from d_table where k1 = 2 order by k1;" @@ -71,7 +71,7 @@ suite ("k123p_nereids") { qt_select_mv "select k1,k2+k3 from d_table where k4 = 'b' order by k1;" - mv_rewrite_all_fail("select k1,k2+k3 from d_table where k4 = 'a' order by k1;") + mv_rewrite_all_fail("select k1,k2+k3 from d_table where k4 = 'a' order by k1;", ["k123p1w", "k123p4w", "kwh1", "kwh2"]) qt_select_mv "select k1,k2+k3 from d_table where k4 = 'a' order by k1;" @@ -81,13 +81,13 @@ suite ("k123p_nereids") { qt_select_mv_constant """select bitmap_empty() from d_table where true;""" - mv_rewrite_all_fail("select k2 from d_table where k1=1 and (k1>2 or k1 < 0) order by k2;") + mv_rewrite_success("select k2 from d_table where k1=1 and (k1>2 or k1 < 0) order by k2;", "kwh1") qt_select_mv "select k2 from d_table where k1=1 and (k1>2 or k1 < 0) order by k2;" mv_rewrite_success("select k2 from d_table where k1>10 order by k2;", "kwh2") - mv_rewrite_all_fail("select k2 from d_table where k1>10 or k2 = 0 order by k2;") + mv_rewrite_all_fail("select k2 from d_table where k1>10 or k2 = 0 order by k2;", ["k123p1w", "k123p4w", "kwh1", "kwh2"]) mv_rewrite_success("select k2 from d_table where k1=1 and (k2>2 or k2<0) order by k2;", "kwh1") @@ -97,7 +97,7 @@ suite ("k123p_nereids") { qt_select_mv "select k2,k1=1 from d_table where k1=1 order by k2;" - mv_rewrite_all_fail("select k2,k1=2 from d_table where k1=1 order by k2;") + mv_rewrite_success("select k2,k1=2 from d_table where k1=1 order by k2;", "kwh1") qt_select_mv "select k2,k1=2 from d_table where k1=1 order by k2;" diff --git a/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy b/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy index 1cde190c57ee39..4db7c97268a927 100644 --- a/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy +++ b/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy @@ -45,26 +45,18 @@ suite ("mvljc") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 order by 1,2;") - contains "(mvljc)" - } + mv_rewrite_success("SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 order by 1,2;", + "mvljc") qt_select_mv "SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 order by 1,2;" - explain { - sql("SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;") - contains "(mvljc)" - } + mv_rewrite_success("SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;", + "mvljc") qt_select_mv "SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;" sql """set enable_stats=true;""" - explain { - sql("SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 order by 1,2;") - contains "(mvljc)" - } + mv_rewrite_success("SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 order by 1,2;", + "mvljc") - explain { - sql("SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;") - contains "(mvljc)" - } + mv_rewrite_success("SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;", + "mvljc") } diff --git a/regression-test/suites/nereids_rules_p0/mv/agg_on_none_agg/agg_on_none_agg.groovy b/regression-test/suites/nereids_rules_p0/mv/agg_on_none_agg/agg_on_none_agg.groovy index 865e3f8f66e9e8..6fba64f06084f3 100644 --- a/regression-test/suites/nereids_rules_p0/mv/agg_on_none_agg/agg_on_none_agg.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/agg_on_none_agg/agg_on_none_agg.groovy @@ -39,11 +39,6 @@ suite("agg_on_none_agg") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -86,10 +81,6 @@ suite("agg_on_none_agg") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" 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 f132aec4f362df..355165055c8ef5 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 @@ -39,11 +39,6 @@ suite("agg_optimize_when_uniform") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -74,10 +69,6 @@ suite("agg_optimize_when_uniform") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/agg_variety/agg_variety.groovy b/regression-test/suites/nereids_rules_p0/mv/agg_variety/agg_variety.groovy index 6c71dc7df64223..3fa6dffca01367 100644 --- a/regression-test/suites/nereids_rules_p0/mv/agg_variety/agg_variety.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/agg_variety/agg_variety.groovy @@ -39,11 +39,6 @@ suite("agg_variety") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -86,10 +81,6 @@ suite("agg_variety") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/agg_with_roll_up/aggregate_with_roll_up.groovy b/regression-test/suites/nereids_rules_p0/mv/agg_with_roll_up/aggregate_with_roll_up.groovy index c75fb5f6e9d35b..cda9b21fc4e51d 100644 --- a/regression-test/suites/nereids_rules_p0/mv/agg_with_roll_up/aggregate_with_roll_up.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/agg_with_roll_up/aggregate_with_roll_up.groovy @@ -38,11 +38,6 @@ suite("aggregate_with_roll_up") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -73,10 +68,6 @@ suite("aggregate_with_roll_up") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -142,26 +133,6 @@ suite("aggregate_with_roll_up") { sql """analyze table lineitem with sync""" sql """analyze table orders with sync""" - def check_rewrite_with_mv_partition = { mv_sql, query_sql, mv_name, partition_column -> - - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - PARTITION BY (${partition_column}) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mv_sql} - """ - - def job_name = getJobName(db, mv_name); - waitingMTMVTaskFinished(job_name) - explain { - sql("${query_sql}") - contains("${mv_name}(${mv_name})") - } - } - // multi table // filter inside + left + use roll up dimension def mv13_0 = @@ -299,7 +270,7 @@ suite("aggregate_with_roll_up") { "l_partkey, " + "l_suppkey" order_qt_query15_0_before "${query15_0}" - check_rewrite_with_mv_partition(mv15_0, query15_0, "mv15_0", "l_shipdate") + async_mv_rewrite_success(db, mv15_0, query15_0, "mv15_0") order_qt_query15_0_after "${query15_0}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv15_0""" @@ -339,7 +310,7 @@ suite("aggregate_with_roll_up") { """ order_qt_query15_1_before "${query15_1}" - check_rewrite_with_mv_partition(mv15_1, query15_1, "mv15_1", "l_shipdate") + async_mv_rewrite_success(db, mv15_1, query15_1, "mv15_1") order_qt_query15_1_after "${query15_1}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv15_1""" diff --git a/regression-test/suites/nereids_rules_p0/mv/agg_without_roll_up/aggregate_without_roll_up.groovy b/regression-test/suites/nereids_rules_p0/mv/agg_without_roll_up/aggregate_without_roll_up.groovy index 07412e92311562..9d60280503cf74 100644 --- a/regression-test/suites/nereids_rules_p0/mv/agg_without_roll_up/aggregate_without_roll_up.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/agg_without_roll_up/aggregate_without_roll_up.groovy @@ -39,11 +39,6 @@ suite("aggregate_without_roll_up") { o_comment VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -74,11 +69,6 @@ suite("aggregate_without_roll_up") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/availability/grace_period.groovy b/regression-test/suites/nereids_rules_p0/mv/availability/grace_period.groovy index f4cfbdc4d9a6d4..5a6c75f6c59c6e 100644 --- a/regression-test/suites/nereids_rules_p0/mv/availability/grace_period.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/availability/grace_period.groovy @@ -147,8 +147,7 @@ suite("grace_period") { """ // force consistency when partition table, and query use the partition changed, should fail - explain { - sql(""" + mv_rewrite_fail(""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -159,12 +158,9 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_partition_consistent_name}(${mv_partition_consistent_name})") - } + """, mv_partition_consistent_name) // force consistency when partition table, and query doesn't use the partition changed, should success - explain { - sql(""" + mv_rewrite_success(""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -175,9 +171,7 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - contains("${mv_partition_consistent_name}(${mv_partition_consistent_name})") - } + """, mv_partition_consistent_name) sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_partition_consistent_name}""" @@ -201,8 +195,7 @@ suite("grace_period") { (1, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy'); """ // force consistency when un partition table, and query use the partition changed, should fail - explain { - sql(""" + mv_not_part_in (""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -213,13 +206,10 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_un_partition_consistent_name}(${mv_un_partition_consistent_name})") - } + """, mv_un_partition_consistent_name) // force consistency when un partition table, and query use the partition changed, should fail - explain { - sql(""" + mv_not_part_in (""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -230,9 +220,7 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_un_partition_consistent_name}(${mv_un_partition_consistent_name})") - } + """, mv_un_partition_consistent_name) sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_un_partition_consistent_name}""" @@ -259,8 +247,7 @@ suite("grace_period") { """ // allow 10s staleness when partition table, and query use the partition changed, should success - explain { - sql(""" + mv_rewrite_success (""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -271,12 +258,10 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - contains("${mv_partition_allow_staleness_name}(${mv_partition_allow_staleness_name})") - } + """, mv_partition_allow_staleness_name, true, + is_partition_statistics_ready(db, ["lineitem_partition", "orders_partition", mv_partition_allow_staleness_name])) // allow 10s staleness when partition table, and query doesn't use the partition changed, should success - explain { - sql(""" + mv_rewrite_success (""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -287,14 +272,13 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - contains("${mv_partition_allow_staleness_name}(${mv_partition_allow_staleness_name})") - } + """, mv_partition_allow_staleness_name, true, + is_partition_statistics_ready(db, ["lineitem_partition", "orders_partition", mv_partition_allow_staleness_name])) sql "SET enable_materialized_view_rewrite=false" // allow 10s staleness when partition table, and query use the partition changed, should success, // but disable materialized view rewrite, should fail - explain { - sql(""" + mv_not_part_in( + """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -305,13 +289,11 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_partition_allow_staleness_name}(${mv_partition_allow_staleness_name})") - } + """, mv_partition_allow_staleness_name) // allow 10s staleness when partition table, and query doesn't use the partition changed, // but disable materialized view rewrite, should fail - explain { - sql(""" + mv_not_part_in( + """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -322,14 +304,12 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_partition_allow_staleness_name}(${mv_partition_allow_staleness_name})") - } + """, mv_partition_allow_staleness_name) sql "SET enable_materialized_view_rewrite=true" Thread.sleep(15000); // after 10s when partition table, and query use the partition changed, should fail - explain { - sql(""" + mv_rewrite_fail( + """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -340,12 +320,9 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_partition_allow_staleness_name}(${mv_partition_allow_staleness_name})") - } + """, mv_partition_allow_staleness_name) // after 10s when partition table, and query doesn't use the partition changed, should success - explain { - sql(""" + mv_rewrite_success (""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -356,9 +333,8 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - contains("${mv_partition_allow_staleness_name}(${mv_partition_allow_staleness_name})") - } + """, mv_partition_allow_staleness_name, true, + is_partition_statistics_ready(db, ["lineitem_partition", "orders_partition", mv_partition_allow_staleness_name])) sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_partition_allow_staleness_name}""" @@ -383,8 +359,7 @@ suite("grace_period") { (1, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-10-17', '2023-10-17', '2023-10-17', 'a', 'b', 'yyyyyyyyy'); """ // allow 10s staleness when un partition table should success - explain { - sql(""" + mv_rewrite_success (""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -395,12 +370,11 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - contains("${mv_un_partition_allow_staleness_name}(${mv_un_partition_allow_staleness_name})") - } + """, mv_un_partition_allow_staleness_name, true, + is_partition_statistics_ready(db, ["lineitem_partition", "orders_partition", mv_un_partition_allow_staleness_name])) // allow 10s staleness when un partition table, should success - explain { - sql(""" + mv_rewrite_success ( + """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -411,13 +385,11 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - contains("${mv_un_partition_allow_staleness_name}(${mv_un_partition_allow_staleness_name})") - } + """, mv_un_partition_allow_staleness_name, true, + is_partition_statistics_ready(db, ["lineitem_partition", "orders_partition", mv_un_partition_allow_staleness_name])) sql "SET enable_materialized_view_rewrite=false" // allow 10s staleness when un partition table, but disable materialized view rewrite, should fail - explain { - sql(""" + mv_not_part_in(""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -428,12 +400,9 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_un_partition_allow_staleness_name}(${mv_un_partition_allow_staleness_name})") - } + """, mv_un_partition_allow_staleness_name) // allow 10s staleness when un partition table, but disable materialized view rewrite, should fail - explain { - sql(""" + mv_not_part_in(""" select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -444,14 +413,12 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_un_partition_allow_staleness_name}(${mv_un_partition_allow_staleness_name})") - } + """, mv_un_partition_allow_staleness_name) sql "SET enable_materialized_view_rewrite=true" Thread.sleep(15000); // after 10s when un partition table, and query use the partition changed, should fail - explain { - sql(""" + mv_not_part_in( + """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -462,12 +429,10 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_un_partition_allow_staleness_name}(${mv_un_partition_allow_staleness_name})") - } + """, mv_un_partition_allow_staleness_name) // after 10s when un partition table, and query doesn't use the partition changed, should fail - explain { - sql(""" + mv_not_part_in( + """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total from lineitem_partition @@ -478,8 +443,6 @@ suite("grace_period") { o_orderdate, l_partkey, l_suppkey; - """) - notContains("${mv_un_partition_allow_staleness_name}(${mv_un_partition_allow_staleness_name})") - } + """, mv_un_partition_allow_staleness_name) sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_un_partition_allow_staleness_name}""" } diff --git a/regression-test/suites/nereids_rules_p0/mv/availability/materialized_view_switch.groovy b/regression-test/suites/nereids_rules_p0/mv/availability/materialized_view_switch.groovy index 97d9325d959ddc..ae349c6514c469 100644 --- a/regression-test/suites/nereids_rules_p0/mv/availability/materialized_view_switch.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/availability/materialized_view_switch.groovy @@ -39,11 +39,6 @@ suite("materialized_view_switch") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -74,10 +69,6 @@ suite("materialized_view_switch") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_1.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_1.groovy index 9b5aa76b5baa2b..f2b5ad09c0b17a 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_1.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_1.groovy @@ -39,7 +39,6 @@ suite("partition_mv_rewrite_dimension_1") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -69,7 +68,6 @@ suite("partition_mv_rewrite_dimension_1") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -103,47 +101,6 @@ suite("partition_mv_rewrite_dimension_1") { sql """analyze table orders_1 with sync;""" sql """analyze table lineitem_1 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -170,7 +127,7 @@ suite("partition_mv_rewrite_dimension_1") { on lineitem_1.l_orderkey = orders_1.o_orderkey """ - create_mv_lineitem(mv_name_1, join_direction_mv_1) + create_async_mv(db, mv_name_1, join_direction_mv_1) def job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) @@ -186,15 +143,9 @@ suite("partition_mv_rewrite_dimension_1") { left join lineitem_1 on orders_1.o_orderkey = lineitem_1.L_ORDERKEY """ - explain { - sql("${join_direction_sql_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(join_direction_sql_1, mv_name_1) compare_res(join_direction_sql_1 + " order by 1") - explain { - sql("${join_direction_sql_2}") - notContains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_fail(join_direction_sql_2, mv_name_1) sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_1};""" @@ -206,7 +157,7 @@ suite("partition_mv_rewrite_dimension_1") { on lineitem_1.l_orderkey = orders_1.o_orderkey """ - create_mv_lineitem(mv_name_2, join_direction_mv_2) + create_async_mv(db, mv_name_2, join_direction_mv_2) def job_name_2 = getJobName(db, mv_name_2) waitingMTMVTaskFinished(job_name_2) @@ -222,15 +173,9 @@ suite("partition_mv_rewrite_dimension_1") { inner join lineitem_1 on orders_1.o_orderkey = lineitem_1.l_orderkey """ - explain { - sql("${join_direction_sql_3}") - contains "${mv_name_2}(${mv_name_2})" - } + mv_rewrite_success(join_direction_sql_3, mv_name_2) compare_res(join_direction_sql_3 + " order by 1") - explain { - sql("${join_direction_sql_4}") - contains "${mv_name_2}(${mv_name_2})" - } + mv_rewrite_success(join_direction_sql_4, mv_name_2) compare_res(join_direction_sql_4 + " order by 1") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_2};""" @@ -282,7 +227,7 @@ suite("partition_mv_rewrite_dimension_1") { for (int i =0; i < mv_list.size(); i++) { logger.info("i:" + i) def join_filter_mv = """join_filter_mv_${i}""" - create_mv_lineitem(join_filter_mv, mv_list[i]) + create_async_mv(db, join_filter_mv, mv_list[i]) def job_name = getJobName(db, join_filter_mv) waitingMTMVTaskFinished(job_name) def res_1 = sql """show partitions from ${join_filter_mv};""" @@ -293,42 +238,27 @@ suite("partition_mv_rewrite_dimension_1") { if (j == 2) { continue } - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } } else if (i == 1) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 1 || j == 4 || j == 3) { - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } else { - explain { - sql("${mv_list[j]}") - notContains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_fail(mv_list[j], join_filter_mv) } } } else if (i == 2) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 2 || j == 3 || j == 5) { - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } else { - explain { - sql("${mv_list[j]}") - notContains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_fail(mv_list[j], join_filter_mv) } } @@ -336,63 +266,39 @@ suite("partition_mv_rewrite_dimension_1") { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 3) { - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } else { - explain { - sql("${mv_list[j]}") - notContains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_fail(mv_list[j], join_filter_mv) } } } else if (i == 4) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 4 || j == 1 || j == 3) { - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } else { - explain { - sql("${mv_list[j]}") - notContains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_fail(mv_list[j], join_filter_mv) } } } else if (i == 5) { for (int j = 0; j < mv_list.size(); j++) { if (j == 5 || j == 3) { - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } else { - explain { - sql("${mv_list[j]}") - notContains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_fail(mv_list[j], join_filter_mv) } } } else if (i == 6) { for (int j = 0; j < mv_list.size(); j++) { if (j == 6) { - explain { - sql("${mv_list[j]}") - contains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_success(mv_list[j], join_filter_mv) compare_res(mv_list[j] + " order by 1, 2, 3, 4, 5") } else { - explain { - sql("${mv_list[j]}") - notContains "${join_filter_mv}(${join_filter_mv})" - } + mv_rewrite_fail(mv_list[j], join_filter_mv) } } @@ -454,27 +360,21 @@ suite("partition_mv_rewrite_dimension_1") { logger.info("i:" + i) String join_type_mv = """join_type_mv_${i}""" if (i in [2, 5, 7]) { - create_mv_orders(join_type_mv, join_type_stmt_list[i]) + create_async_mv(db, join_type_mv, join_type_stmt_list[i]) } else if (i == 3) { - create_mv(join_type_mv, join_type_stmt_list[i]) + create_async_mv(db, join_type_mv, join_type_stmt_list[i]) } else { - create_mv_lineitem(join_type_mv, join_type_stmt_list[i]) + create_async_mv(db, join_type_mv, join_type_stmt_list[i]) } def job_name = getJobName(db, join_type_mv) waitingMTMVTaskFinished(job_name) for (int j = 0; j < join_type_stmt_list.size(); j++) { logger.info("j:" + j) if (i == j) { - explain { - sql("${join_type_stmt_list[j]}") - contains "${join_type_mv}(${join_type_mv})" - } + mv_rewrite_success(join_type_stmt_list[j], join_type_mv) compare_res(join_type_stmt_list[j] + " order by 1,2,3,4") } else { - explain { - sql("${join_type_stmt_list[j]}") - notContains "${join_type_mv}(${join_type_mv})" - } + mv_rewrite_fail(join_type_stmt_list[j], join_type_mv) } } sql """DROP MATERIALIZED VIEW IF EXISTS ${join_type_mv};""" @@ -485,13 +385,8 @@ suite("partition_mv_rewrite_dimension_1") { def agg_mv_name_1 = "agg_mv_name_1" sql """DROP MATERIALIZED VIEW IF EXISTS ${agg_mv_name_1};""" sql """DROP TABLE IF EXISTS ${agg_mv_name_1}""" - sql """ - CREATE MATERIALIZED VIEW ${agg_mv_name_1} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - select + create_async_mv(db, agg_mv_name_1, """ + select sum(O_TOTALPRICE) as sum_total, max(o_totalprice) as max_total, min(o_totalprice) as min_total, @@ -499,7 +394,7 @@ suite("partition_mv_rewrite_dimension_1") { bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) cnt_1, bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 from orders_1 - """ + """) def agg_job_name_1 = getJobName(db, agg_mv_name_1) waitingMTMVTaskFinished(agg_job_name_1) @@ -512,10 +407,7 @@ suite("partition_mv_rewrite_dimension_1") { count(*) from orders_1 """ - explain { - sql("${agg_sql_1}") - contains "${agg_mv_name_1}(${agg_mv_name_1})" - } + mv_rewrite_success(agg_sql_1, agg_mv_name_1) compare_res(agg_sql_1 + " order by 1,2,3,4,5,6") sql """DROP MATERIALIZED VIEW IF EXISTS ${agg_mv_name_1};""" @@ -529,7 +421,7 @@ suite("partition_mv_rewrite_dimension_1") { o_shippriority, o_comment """ - create_mv_orders(agg_mv_name_2, agg_mv_stmt_2) + create_async_mv(db, agg_mv_name_2, agg_mv_stmt_2) def agg_job_name_2 = getJobName(db, agg_mv_name_2) waitingMTMVTaskFinished(agg_job_name_2) sql """analyze table ${agg_mv_name_2} with sync;""" @@ -562,7 +454,7 @@ suite("partition_mv_rewrite_dimension_1") { o_shippriority, o_comment """ - create_mv_orders(agg_mv_name_3, agg_mv_stmt_3) + create_async_mv(db, agg_mv_name_3, agg_mv_stmt_3) def agg_job_name_3 = getJobName(db, agg_mv_name_3) waitingMTMVTaskFinished(agg_job_name_3) sql """analyze table ${agg_mv_name_3} with sync;""" @@ -594,7 +486,7 @@ suite("partition_mv_rewrite_dimension_1") { // left join orders_1 // on lineitem_1.l_orderkey = orders_1.o_orderkey // """ -// create_mv_orders(query_partition_mv_name_1, query_partition_mv_stmt_1) +// create_async_mv(db, query_partition_mv_name_1, query_partition_mv_stmt_1) // def query_partition_job_name_1 = getJobName(db, query_partition_mv_name_1) // waitingMTMVTaskFinished(query_partition_job_name_1) // @@ -615,7 +507,7 @@ suite("partition_mv_rewrite_dimension_1") { def view_partition_mv_name_1 = "view_partition_mv_name_1" def view_partition_mv_stmt_1 = """ select l_shipdatE, l_partkey, l_orderkey from lineitem_1 group by l_shipdate, l_partkey, l_orderkeY""" - create_mv_lineitem(view_partition_mv_name_1, view_partition_mv_stmt_1) + create_async_mv(db, view_partition_mv_name_1, view_partition_mv_stmt_1) def view_partition_job_name_1 = getJobName(db, view_partition_mv_name_1) waitingMTMVTaskFinished(view_partition_job_name_1) @@ -624,10 +516,7 @@ suite("partition_mv_rewrite_dimension_1") { left join orders_1 on t.l_orderkey = orders_1.o_orderkey group by t.l_shipdate, o_orderdate, t.l_partkey """ - explain { - sql("${view_partition_sql_1}") - contains "${view_partition_mv_name_1}(${view_partition_mv_name_1})" - } + mv_rewrite_success(view_partition_sql_1, view_partition_mv_name_1) compare_res(view_partition_sql_1 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${view_partition_mv_name_1};""" @@ -640,7 +529,7 @@ suite("partition_mv_rewrite_dimension_1") { // on lineitem_1.l_orderkey = orders_1.o_orderkey // where l_shipdate >= "2023-12-04" // """ -// create_mv_orders(union_mv_name_1, union_mv_stmt_1) +// create_async_mv(db, union_mv_name_1, union_mv_stmt_1) // def union_job_name_1 = getJobName(db, union_mv_name_1) // waitingMTMVTaskFinished(union_job_name_1) // @@ -665,7 +554,7 @@ suite("partition_mv_rewrite_dimension_1") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate >= "2023-10-17" """ - create_mv_lineitem(predicate_mv_name_1, predicate_mv_stmt_1) + create_async_mv(db, predicate_mv_name_1, predicate_mv_stmt_1) def predicate_job_name_1 = getJobName(db, predicate_mv_name_1) waitingMTMVTaskFinished(predicate_job_name_1) @@ -676,10 +565,7 @@ suite("partition_mv_rewrite_dimension_1") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate >= "2023-10-17" and l_partkey = 1 """ - explain { - sql("${predicate_sql_1}") - contains "${predicate_mv_name_1}(${predicate_mv_name_1})" - } + mv_rewrite_success(predicate_sql_1, predicate_mv_name_1) compare_res(predicate_sql_1 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${predicate_mv_name_1};""" @@ -692,7 +578,7 @@ suite("partition_mv_rewrite_dimension_1") { // from orders_1 // where o_orderkey > 1 + 1; // """ -// create_mv_orders(rewriting_mv_name_1, rewriting_mv_stmt_1) +// create_async_mv(db, rewriting_mv_name_1, rewriting_mv_stmt_1) // def rewriting_job_name_1 = getJobName(db, rewriting_mv_name_1) // waitingMTMVTaskFinished(rewriting_job_name_1) // @@ -708,20 +594,6 @@ suite("partition_mv_rewrite_dimension_1") { // } // sql """DROP MATERIALIZED VIEW IF EXISTS ${rewriting_mv_name_1};""" - - def create_mv_lineitem_without_partition = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - // single table mv_name_1 = "single_tb_mv_1" def single_table_mv_stmt_1 = """ @@ -730,7 +602,7 @@ suite("partition_mv_rewrite_dimension_1") { where l_commitdate like '2023-10-%' """ - create_mv_lineitem_without_partition(mv_name_1, single_table_mv_stmt_1) + create_async_mv(db, mv_name_1, single_table_mv_stmt_1) job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) @@ -745,16 +617,10 @@ suite("partition_mv_rewrite_dimension_1") { where l_commitdate like '2023-10-%' and l_partkey > 0 + 1 """ - explain { - sql("${single_table_query_stmt_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(single_table_query_stmt_1, mv_name_1) compare_res(single_table_query_stmt_1 + " order by 1,2,3") - explain { - sql("${single_table_query_stmt_2}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(single_table_query_stmt_2, mv_name_1) compare_res(single_table_query_stmt_2 + " order by 1,2,3") @@ -768,20 +634,7 @@ suite("partition_mv_rewrite_dimension_1") { from orders_1 where o_orderdate >= '2022-10-17' + interval '1' year """ - def create_mv_orders_without_partition = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - create_mv_orders_without_partition(mv_name_1, single_table_mv_stmt_1) + create_async_mv(db, mv_name_1, single_table_mv_stmt_1) job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) @@ -822,7 +675,7 @@ suite("partition_mv_rewrite_dimension_1") { where l_commitdate in (select l_commitdate from lineitem_1) """ - create_mv_lineitem_without_partition(mv_name_1, single_table_mv_stmt_1) + create_async_mv(db, mv_name_1, single_table_mv_stmt_1) job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) @@ -831,10 +684,7 @@ suite("partition_mv_rewrite_dimension_1") { from lineitem_1 where l_commitdate in (select l_commitdate from lineitem_1) """ - explain { - sql("${single_table_query_stmt_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(single_table_query_stmt_1, mv_name_1) compare_res(single_table_query_stmt_1 + " order by 1,2,3") // not supported currently @@ -844,7 +694,7 @@ suite("partition_mv_rewrite_dimension_1") { // where exists (select l_commitdate from lineitem_1 where l_commitdate like "2023-10-17") // """ // -// create_mv_lineitem_without_partition(mv_name_1, single_table_mv_stmt_1) +// create_async_mv(db, mv_name_1, single_table_mv_stmt_1) // job_name_1 = getJobName(db, mv_name_1) // waitingMTMVTaskFinished(job_name_1) // @@ -866,7 +716,7 @@ suite("partition_mv_rewrite_dimension_1") { // where exists (select l_commitdate from lineitem_1 where l_commitdate like "2023-10-17") // """ // -// create_mv_lineitem_without_partition(mv_name_1, single_table_mv_stmt_1) +// create_async_mv(db, mv_name_1, single_table_mv_stmt_1) // job_name_1 = getJobName(db, mv_name_1) // waitingMTMVTaskFinished(job_name_1) // diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_3.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_3.groovy index 91b50ecd0d2078..53f8777a1589d7 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_3.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_3.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_3") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_3") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,47 +102,6 @@ suite("partition_mv_rewrite_dimension_2_3") { sql """analyze table orders_2_3 with sync;""" sql """analyze table lineitem_2_3 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -172,7 +129,7 @@ suite("partition_mv_rewrite_dimension_2_3") { bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 from orders_2_3 left join lineitem_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey""" - create_all_mv(mv_name_1, mv_stmt_1) + create_async_mv(db, mv_name_1, mv_stmt_1) def job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) @@ -185,10 +142,7 @@ suite("partition_mv_rewrite_dimension_2_3") { count(*) from orders_2_3 left join lineitem_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey""" - explain { - sql("${sql_stmt_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(sql_stmt_1, mv_name_1) compare_res(sql_stmt_1 + " order by 1,2,3,4,5,6") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_1};""" @@ -201,7 +155,7 @@ suite("partition_mv_rewrite_dimension_2_3") { o_orderdate, o_shippriority, o_comment """ - create_mv_orders(mv_name_2, mv_stmt_2) + create_async_mv(db, mv_name_2, mv_stmt_2) def job_name_2 = getJobName(db, mv_name_2) waitingMTMVTaskFinished(job_name_2) @@ -211,10 +165,7 @@ suite("partition_mv_rewrite_dimension_2_3") { group by o_shippriority, o_comment """ - explain { - sql("${sql_stmt_2}") - contains "${mv_name_2}(${mv_name_2})" - } + mv_rewrite_success(sql_stmt_2, mv_name_2) compare_res(sql_stmt_2 + " order by 1,2") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_2};""" @@ -233,7 +184,7 @@ suite("partition_mv_rewrite_dimension_2_3") { o_orderdate, o_shippriority, o_comment """ - create_mv_orders(mv_name_3, mv_stmt_3) + create_async_mv(db, mv_name_3, mv_stmt_3) def job_name_3 = getJobName(db, mv_name_3) waitingMTMVTaskFinished(job_name_3) @@ -249,10 +200,7 @@ suite("partition_mv_rewrite_dimension_2_3") { group by o_shippriority, o_comment """ - explain { - sql("${sql_stmt_3}") - contains "${mv_name_3}(${mv_name_3})" - } + mv_rewrite_success(sql_stmt_3, mv_name_3) compare_res(sql_stmt_3 + " order by 1,2,3,4,5,6,7,8") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_3};""" @@ -263,7 +211,7 @@ suite("partition_mv_rewrite_dimension_2_3") { // from lineitem_2_3 // left join orders_2_3 // on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey """ -// create_mv_orders(mv_name_4, mv_stmt_4) +// create_async_mv(db, mv_name_4, mv_stmt_4) // def job_name_4 = getJobName(db, mv_name_4) // waitingMTMVTaskFinished(job_name_4) // @@ -284,17 +232,14 @@ suite("partition_mv_rewrite_dimension_2_3") { from lineitem_2_3 left join orders_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey""" - create_mv_lineitem(mv_name_5, mv_stmt_5) + create_async_mv(db, mv_name_5, mv_stmt_5) def job_name_5 = getJobName(db, mv_name_5) waitingMTMVTaskFinished(job_name_5) def sql_stmt_5 = """select l_shipdate, o_orderdate, l_partkey from lineitem_2_3 left join orders_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey""" - explain { - sql("${sql_stmt_5}") - contains "${mv_name_5}(${mv_name_5})" - } + mv_rewrite_success(sql_stmt_5, mv_name_5) compare_res(sql_stmt_5 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_5};""" @@ -306,7 +251,7 @@ suite("partition_mv_rewrite_dimension_2_3") { // left join orders_2_3 // on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey // where l_shipdate >= '2023-10-17'""" -// create_mv_lineitem(mv_name_6, mv_stmt_6) +// create_async_mv(db, mv_name_6, mv_stmt_6) // def job_name_6 = getJobName(db, mv_name_6) // waitingMTMVTaskFinished(job_name_6) // @@ -327,7 +272,7 @@ suite("partition_mv_rewrite_dimension_2_3") { left join orders_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey where l_shipdate >= '2023-10-17'""" - create_mv_lineitem(mv_name_7, mv_stmt_7) + create_async_mv(db, mv_name_7, mv_stmt_7) def job_name_7 = getJobName(db, mv_name_7) waitingMTMVTaskFinished(job_name_7) @@ -336,10 +281,7 @@ suite("partition_mv_rewrite_dimension_2_3") { left join orders_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey where l_shipdate >= "2023-10-17" and l_partkey = 3""" - explain { - sql("${sql_stmt_7}") - contains "${mv_name_7}(${mv_name_7})" - } + mv_rewrite_success(sql_stmt_7, mv_name_7) compare_res(sql_stmt_7 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_7};""" @@ -351,7 +293,7 @@ suite("partition_mv_rewrite_dimension_2_3") { case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end as cnt_2 from orders_2_3 left join lineitem_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey where o_orderkey > 1 + 1 """ - create_mv_orders(mv_name_8, mv_stmt_8) + create_async_mv(db, mv_name_8, mv_stmt_8) def job_name_8 = getJobName(db, mv_name_8) waitingMTMVTaskFinished(job_name_8) @@ -360,10 +302,7 @@ suite("partition_mv_rewrite_dimension_2_3") { case when O_SHIPPRIORITY > 2 and o_orderkey IN (2) then o_custkey else null end as cnt_2 from orders_2_3 left join lineitem_2_3 on lineitem_2_3.l_orderkey = orders_2_3.o_orderkey where o_orderkey > (-3) + 5 """ - explain { - sql("${sql_stmt_8}") - contains "${mv_name_8}(${mv_name_8})" - } + mv_rewrite_success(sql_stmt_8, mv_name_8) compare_res(sql_stmt_8 + " order by 1,2,3,4,5") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_8};""" } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_4.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_4.groovy index 9535fc2e4ad4a5..deb6255119a26e 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_4.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_4.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_4") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_4") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -130,47 +128,6 @@ suite("partition_mv_rewrite_dimension_2_4") { sql """analyze table lineitem_2_4 with sync;""" sql """analyze table partsupp_2_4 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -199,7 +156,7 @@ suite("partition_mv_rewrite_dimension_2_4") { // bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 // from orders_2_4 // left join lineitem_2_4 on lineitem_2_4.l_orderkey = orders_2_4.o_orderkey""" -// create_all_mv(mv_name_1, mv_stmt_1) +// create_async_mv(db, mv_name_1, mv_stmt_1) // def job_name_1 = getJobName(db, mv_name_1) // waitingMTMVTaskFinished(job_name_1) // @@ -226,7 +183,7 @@ suite("partition_mv_rewrite_dimension_2_4") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_2, mv_stmt_2) +// create_async_mv(db, mv_name_2, mv_stmt_2) // def job_name_2 = getJobName(db, mv_name_2) // waitingMTMVTaskFinished(job_name_2) // @@ -255,7 +212,7 @@ suite("partition_mv_rewrite_dimension_2_4") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_3, mv_stmt_3) +// create_async_mv(db, mv_name_3, mv_stmt_3) // def job_name_3 = getJobName(db, mv_name_3) // waitingMTMVTaskFinished(job_name_3) // @@ -287,7 +244,7 @@ suite("partition_mv_rewrite_dimension_2_4") { from orders_2_4 left join lineitem_2_4 on lineitem_2_4.l_orderkey = orders_2_4.o_orderkey """ - create_all_mv(mv_name_4, mv_stmt_4) + create_async_mv(db, mv_name_4, mv_stmt_4) def job_name_4 = getJobName(db, mv_name_4) waitingMTMVTaskFinished(job_name_4) @@ -301,10 +258,7 @@ suite("partition_mv_rewrite_dimension_2_4") { left join lineitem_2_4 on lineitem_2_4.l_orderkey = orders_2_4.o_orderkey left join partsupp_2_4 on partsupp_2_4.ps_partkey = lineitem_2_4.l_orderkey""" - explain { - sql("${sql_stmt_4}") - contains "${mv_name_4}(${mv_name_4})" - } + mv_rewrite_success(sql_stmt_4, mv_name_4) compare_res(sql_stmt_4 + " order by 1,2,3,4,5") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_4};""" @@ -318,7 +272,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - create_mv_orders(mv_name_5, mv_stmt_5) + create_async_mv(db, mv_name_5, mv_stmt_5) def job_name_5 = getJobName(db, mv_name_5) waitingMTMVTaskFinished(job_name_5) @@ -330,10 +284,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - explain { - sql("${sql_stmt_5}") - notContains "${mv_name_5}(${mv_name_5})" - } + mv_rewrite_fail(sql_stmt_5, mv_name_5) compare_res(sql_stmt_5 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_5};""" @@ -353,7 +304,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - create_mv_orders(mv_name_6, mv_stmt_6) + create_async_mv(db, mv_name_6, mv_stmt_6) def job_name_6 = getJobName(db, mv_name_6) waitingMTMVTaskFinished(job_name_6) @@ -371,10 +322,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - explain { - sql("${sql_stmt_6}") - notContains "${mv_name_6}(${mv_name_6})" - } + mv_rewrite_fail(sql_stmt_6, mv_name_6) compare_res(sql_stmt_6 + " order by 1,2,3,4,5,6,7") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_6};""" @@ -392,7 +340,7 @@ suite("partition_mv_rewrite_dimension_2_4") { // bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 // from orders_2_4 // where o_orderdate >= '2023-10-17'""" -// create_mv_orders(mv_name_7, mv_stmt_7) +// create_async_mv(db, mv_name_7, mv_stmt_7) // def job_name_7 = getJobName(db, mv_name_7) // waitingMTMVTaskFinished(job_name_7) // @@ -420,7 +368,7 @@ suite("partition_mv_rewrite_dimension_2_4") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_8, mv_stmt_8) +// create_async_mv(db, mv_name_8, mv_stmt_8) // def job_name_8 = getJobName(db, mv_name_8) // waitingMTMVTaskFinished(job_name_8) // @@ -453,7 +401,7 @@ suite("partition_mv_rewrite_dimension_2_4") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_9, mv_stmt_9) +// create_async_mv(db, mv_name_9, mv_stmt_9) // def job_name_9 = getJobName(db, mv_name_9) // waitingMTMVTaskFinished(job_name_9) // @@ -489,7 +437,7 @@ suite("partition_mv_rewrite_dimension_2_4") { bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 from orders_2_4 where o_orderdate >= '2023-10-17'""" - create_all_mv(mv_name_10, mv_stmt_10) + create_async_mv(db, mv_name_10, mv_stmt_10) def job_name_10 = getJobName(db, mv_name_10) waitingMTMVTaskFinished(job_name_10) @@ -502,10 +450,7 @@ suite("partition_mv_rewrite_dimension_2_4") { bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 from orders_2_4 where o_orderdate >= "2023-10-17" ) as t where t.count_all = 3""" - explain { - sql("${sql_stmt_10}") - contains "${mv_name_10}(${mv_name_10})" - } + mv_rewrite_success(sql_stmt_10, mv_name_10) compare_res(sql_stmt_10 + " order by 1") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_10};""" @@ -520,7 +465,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - create_all_mv(mv_name_11, mv_stmt_11) + create_async_mv(db, mv_name_11, mv_stmt_11) def job_name_11 = getJobName(db, mv_name_11) waitingMTMVTaskFinished(job_name_11) @@ -531,10 +476,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - explain { - sql("${sql_stmt_11}") - notContains "${mv_name_11}(${mv_name_11})" - } + mv_rewrite_fail(sql_stmt_11, mv_name_11) compare_res(sql_stmt_11 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_11};""" @@ -547,7 +489,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_shippriority, o_comment, o_totalprice """ - create_all_mv(mv_name_16, mv_stmt_16) + create_async_mv(db, mv_name_16, mv_stmt_16) def job_name_16 = getJobName(db, mv_name_16) waitingMTMVTaskFinished(job_name_16) @@ -583,7 +525,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_shippriority, o_comment, o_totalprice """ - create_all_mv(mv_name_12, mv_stmt_12) + create_async_mv(db, mv_name_12, mv_stmt_12) def job_name_12 = getJobName(db, mv_name_12) waitingMTMVTaskFinished(job_name_12) @@ -606,10 +548,7 @@ suite("partition_mv_rewrite_dimension_2_4") { ) as t where t.o_totalprice = 1 """ - explain { - sql("${sql_stmt_12}") - contains "${mv_name_12}(${mv_name_12})" - } + mv_rewrite_success(sql_stmt_12, mv_name_12) compare_res(sql_stmt_12 + " order by 1,2,3,4,5,6,7") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_12};""" @@ -625,7 +564,7 @@ suite("partition_mv_rewrite_dimension_2_4") { bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 from orders_2_4 where o_orderkey > 1 + 1 """ - create_all_mv(mv_name_13, mv_stmt_13) + create_async_mv(db, mv_name_13, mv_stmt_13) def job_name_13 = getJobName(db, mv_name_13) waitingMTMVTaskFinished(job_name_13) @@ -634,10 +573,7 @@ suite("partition_mv_rewrite_dimension_2_4") { count(distinct case when O_SHIPPRIORITY > 2 and o_orderkey IN (2) then o_custkey else null end) as cnt_2 from orders_2_4 where o_orderkey > (-3) + 5 """ - explain { - sql("${sql_stmt_13}") - contains "${mv_name_13}(${mv_name_13})" - } + mv_rewrite_success(sql_stmt_13, mv_name_13) compare_res(sql_stmt_13 + " order by 1") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_13};""" @@ -651,7 +587,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - create_all_mv(mv_name_14, mv_stmt_14) + create_async_mv(db, mv_name_14, mv_stmt_14) def job_name_14 = getJobName(db, mv_name_14) waitingMTMVTaskFinished(job_name_14) @@ -662,10 +598,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_orderdate, o_shippriority, o_comment """ - explain { - sql("${sql_stmt_14}") - contains "${mv_name_14}(${mv_name_14})" - } + mv_rewrite_success(sql_stmt_14, mv_name_14) compare_res(sql_stmt_14 + " order by 1,2") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_14};""" @@ -685,7 +618,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_custkey, case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end, case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end """ - create_all_mv(mv_name_15, mv_stmt_15) + create_async_mv(db, mv_name_15, mv_stmt_15) def job_name_15 = getJobName(db, mv_name_15) waitingMTMVTaskFinished(job_name_15) @@ -701,10 +634,7 @@ suite("partition_mv_rewrite_dimension_2_4") { o_custkey, case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end, case when O_SHIPPRIORITY > 2 and o_orderkey IN (2) then o_custkey else null end """ - explain { - sql("${sql_stmt_15}") - contains "${mv_name_15}(${mv_name_15})" - } + mv_rewrite_success(sql_stmt_15, mv_name_15) compare_res(sql_stmt_15 + " order by 1,2,3,4,5") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_15};""" diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_5.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_5.groovy index 6f5d4ce42ccb51..5d8a6b5270285b 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_5.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_5.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_5") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_5") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -130,47 +128,6 @@ suite("partition_mv_rewrite_dimension_2_5") { sql """analyze table lineitem_2_5 with sync;""" sql """analyze table partsupp_2_5 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -199,7 +156,7 @@ suite("partition_mv_rewrite_dimension_2_5") { // bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 // from orders_2_5 // left join lineitem_2_5 on lineitem_2_5.l_orderkey = orders_2_5.o_orderkey""" -// create_all_mv(mv_name_1, mv_stmt_1) +// create_async_mv(db, mv_name_1, mv_stmt_1) // def job_name_1 = getJobName(db, mv_name_1) // waitingMTMVTaskFinished(job_name_1) // @@ -225,7 +182,7 @@ suite("partition_mv_rewrite_dimension_2_5") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_2, mv_stmt_2) +// create_async_mv(db, mv_name_2, mv_stmt_2) // def job_name_2 = getJobName(db, mv_name_2) // waitingMTMVTaskFinished(job_name_2) // @@ -254,7 +211,7 @@ suite("partition_mv_rewrite_dimension_2_5") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_3, mv_stmt_3) +// create_async_mv(db, mv_name_3, mv_stmt_3) // def job_name_3 = getJobName(db, mv_name_3) // waitingMTMVTaskFinished(job_name_3) // @@ -286,7 +243,7 @@ suite("partition_mv_rewrite_dimension_2_5") { o_comment, l_orderkey, o_orderkey """ - create_mv_orders(mv_name_5, mv_stmt_5) + create_async_mv(db, mv_name_5, mv_stmt_5) def job_name_5 = getJobName(db, mv_name_5) waitingMTMVTaskFinished(job_name_5) @@ -298,10 +255,7 @@ suite("partition_mv_rewrite_dimension_2_5") { o_orderdate, o_shippriority, o_comment """ - explain { - sql("${sql_stmt_5}") - notContains "${mv_name_5}(${mv_name_5})" - } + mv_rewrite_fail(sql_stmt_5, mv_name_5) compare_res(sql_stmt_5 + " order by 1,2,3") def sql_stmt_5_2 = """select o_orderdate, o_shippriority, o_comment @@ -312,10 +266,7 @@ suite("partition_mv_rewrite_dimension_2_5") { o_orderdate, o_shippriority, o_comment """ - explain { - sql("${sql_stmt_5_2}") - notContains "${mv_name_5}(${mv_name_5})" - } + mv_rewrite_fail(sql_stmt_5_2, mv_name_5) compare_res(sql_stmt_5_2 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_5};""" @@ -332,7 +283,7 @@ suite("partition_mv_rewrite_dimension_2_5") { // bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 // from orders_2_5 // where o_orderdate >= '2023-10-17'""" -// create_mv_orders(mv_name_7, mv_stmt_7) +// create_async_mv(db, mv_name_7, mv_stmt_7) // def job_name_7 = getJobName(db, mv_name_7) // waitingMTMVTaskFinished(job_name_7) // @@ -360,7 +311,7 @@ suite("partition_mv_rewrite_dimension_2_5") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_8, mv_stmt_8) +// create_async_mv(db, mv_name_8, mv_stmt_8) // def job_name_8 = getJobName(db, mv_name_8) // waitingMTMVTaskFinished(job_name_8) // @@ -393,7 +344,7 @@ suite("partition_mv_rewrite_dimension_2_5") { // o_orderdate, // o_shippriority, // o_comment """ -// create_mv_orders(mv_name_9, mv_stmt_9) +// create_async_mv(db, mv_name_9, mv_stmt_9) // def job_name_9 = getJobName(db, mv_name_9) // waitingMTMVTaskFinished(job_name_9) // diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_6.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_6.groovy index 39c3d13e09b900..1831e8de9a7a9d 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_6.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_6.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_6") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_6") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -130,47 +128,6 @@ suite("partition_mv_rewrite_dimension_2_6") { sql """analyze table lineitem_2_6 with sync;""" sql """analyze table partsupp_2_6 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -196,7 +153,7 @@ suite("partition_mv_rewrite_dimension_2_6") { // on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey // where l_shipdate >= "2023-10-17" // group by l_shipdate, o_orderdate, l_partkey, l_suppkey""" -// create_mv_lineitem(mv_name_1, mv_stmt_1) +// create_async_mv(db, mv_name_1, mv_stmt_1) // def job_name_1 = getJobName(db, mv_name_1) // waitingMTMVTaskFinished(job_name_1) // @@ -218,7 +175,7 @@ suite("partition_mv_rewrite_dimension_2_6") { // on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey // where l_shipdate >= "2023-10-17" // group by l_shipdate, o_orderdate, l_partkey, l_suppkey""" -// create_mv_lineitem(mv_name_2, mv_stmt_2) +// create_async_mv(db, mv_name_2, mv_stmt_2) // def job_name_2 = getJobName(db, mv_name_2) // waitingMTMVTaskFinished(job_name_2) // @@ -242,7 +199,7 @@ suite("partition_mv_rewrite_dimension_2_6") { // left join lineitem_2_6 // on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey // where o_custkey > 1 + 1""" -// create_mv_lineitem(mv_name_3, mv_stmt_3) +// create_async_mv(db, mv_name_3, mv_stmt_3) // def job_name_3 = getJobName(db, mv_name_3) // waitingMTMVTaskFinished(job_name_3) // @@ -264,7 +221,7 @@ suite("partition_mv_rewrite_dimension_2_6") { // from lineitem_2_6 // where l_shipdate >= "2023-10-17" // group by l_shipdate, l_partkey, l_orderkey""" -// create_mv_lineitem(mv_name_4, mv_stmt_4) +// create_async_mv(db, mv_name_4, mv_stmt_4) // def job_name_4 = getJobName(db, mv_name_4) // waitingMTMVTaskFinished(job_name_4) // @@ -286,7 +243,7 @@ suite("partition_mv_rewrite_dimension_2_6") { from lineitem_2_6 where l_shipdate >= "2023-10-17" group by l_shipdate, l_partkey, l_orderkey""" - create_mv_lineitem(mv_name_5, mv_stmt_5) + create_async_mv(db, mv_name_5, mv_stmt_5) def job_name_5 = getJobName(db, mv_name_5) waitingMTMVTaskFinished(job_name_5) @@ -296,10 +253,7 @@ suite("partition_mv_rewrite_dimension_2_6") { on t.l_orderkey = orders_2_6.o_orderkey where l_shipdate >= "2023-10-17" and l_partkey > 1 + 1 group by t.l_shipdate, o_orderdate, t.l_partkey""" - explain { - sql("${sql_stmt_5}") - contains "${mv_name_5}(${mv_name_5})" - } + mv_rewrite_success(sql_stmt_5, mv_name_5) compare_res(sql_stmt_5 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_5};""" @@ -309,7 +263,7 @@ suite("partition_mv_rewrite_dimension_2_6") { from lineitem_2_6 where l_partkey > 1 + 1 group by l_shipdate, l_partkey, l_orderkey""" - create_mv_lineitem(mv_name_6, mv_stmt_6) + create_async_mv(db, mv_name_6, mv_stmt_6) def job_name_6 = getJobName(db, mv_name_6) waitingMTMVTaskFinished(job_name_6) @@ -319,10 +273,7 @@ suite("partition_mv_rewrite_dimension_2_6") { on t.l_orderkey = orders_2_6.o_orderkey where l_partkey > (-3) + 5 group by t.l_shipdate, o_orderdate, t.l_partkey""" - explain { - sql("${sql_stmt_6}") - contains "${mv_name_6}(${mv_name_6})" - } + mv_rewrite_success(sql_stmt_6, mv_name_6) compare_res(sql_stmt_6 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_6};""" @@ -335,7 +286,7 @@ suite("partition_mv_rewrite_dimension_2_6") { // left join orders_2_6 // on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey // where l_shipdate >= '2023-10-17'""" -// create_mv_lineitem(mv_name_7, mv_stmt_7) +// create_async_mv(db, mv_name_7, mv_stmt_7) // def job_name_7 = getJobName(db, mv_name_7) // waitingMTMVTaskFinished(job_name_7) // @@ -358,7 +309,7 @@ suite("partition_mv_rewrite_dimension_2_6") { // left join orders_2_6 // on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey // where l_shipdate >= "2023-10-17" and o_custkey > 1 + 1""" -// create_mv_lineitem(mv_name_8, mv_stmt_8) +// create_async_mv(db, mv_name_8, mv_stmt_8) // def job_name_8 = getJobName(db, mv_name_8) // waitingMTMVTaskFinished(job_name_8) // @@ -383,7 +334,7 @@ suite("partition_mv_rewrite_dimension_2_6") { left join lineitem_2_6 on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey where o_custkey > 1 + 1""" - create_mv_orders(mv_name_9, mv_stmt_9) + create_async_mv(db, mv_name_9, mv_stmt_9) def job_name_9 = getJobName(db, mv_name_9) waitingMTMVTaskFinished(job_name_9) @@ -394,10 +345,7 @@ suite("partition_mv_rewrite_dimension_2_6") { left join lineitem_2_6 on lineitem_2_6.l_orderkey = orders_2_6.o_orderkey where o_custkey > (-3) + 5 and o_orderdate >= '2023-10-17' """ - explain { - sql("${sql_stmt_9}") - contains "${mv_name_9}(${mv_name_9})" - } + mv_rewrite_success(sql_stmt_9, mv_name_9) compare_res(sql_stmt_9 + " order by 1,2,3,4,5,6") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_9};""" diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_full_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_full_join.groovy index e38ef749ea8ed6..6def436e11c5c4 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_full_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_full_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_full_join") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_full_join") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,46 +102,6 @@ suite("partition_mv_rewrite_dimension_2_full_join") { sql """analyze table orders_2_full_join with sync;""" sql """analyze table lineitem_2_full_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_all = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" @@ -236,199 +194,127 @@ suite("partition_mv_rewrite_dimension_2_full_join") { for (int i = 0; i < mv_list_1.size(); i++) { logger.info("i:" + i) def mv_name = """mv_name_2_full_join_${i}""" - create_mv_all(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) if (i == 0) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("current index j:" + j) if (j in [0, 2, 4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [2, 4, 5, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 5, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [2, 4, 5, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 5, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 10) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 11) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_inner_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_inner_join.groovy index 932f36f9c78bbd..526e05f0692fbe 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_inner_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_inner_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_2") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_2") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_2") { sql """analyze table orders_2_2 with sync;""" sql """analyze table lineitem_2_2 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -224,9 +194,9 @@ suite("partition_mv_rewrite_dimension_2_2") { logger.info("i:" + i) def mv_name = """mv_name_2_2_${i}""" if (i < 6) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -234,192 +204,120 @@ suite("partition_mv_rewrite_dimension_2_2") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("current index j:" + j) if (j in [0, 2, 4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 10) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 11) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_anti_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_anti_join.groovy index 14daf54727d103..0db7b3bf008c68 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_anti_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_anti_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_left_anti_join") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_left_anti_join") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_left_anti_join") { sql """analyze table orders_2_left_anti_join with sync;""" sql """analyze table lineitem_2_left_anti_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -187,9 +157,9 @@ suite("partition_mv_rewrite_dimension_2_left_anti_join") { logger.info("i:" + i) def mv_name = """mv_name_2_left_anti_join_${i}""" if (i < 3) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -197,96 +167,60 @@ suite("partition_mv_rewrite_dimension_2_left_anti_join") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_join.groovy index 043625335dfaa4..f59dffd0091bb4 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_1") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_1") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_1") { sql """analyze table orders_2_1 with sync;""" sql """analyze table lineitem_2_1 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -224,9 +194,9 @@ suite("partition_mv_rewrite_dimension_2_1") { logger.info("i:" + i) def mv_name = """mv_name_2_1_${i}""" if (i < 3) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -234,96 +204,60 @@ suite("partition_mv_rewrite_dimension_2_1") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 2, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { @@ -331,96 +265,60 @@ suite("partition_mv_rewrite_dimension_2_1") { logger.info("j:" + j) // 5, 11 should be success but not now, should support in the future by equivalence class if (j in [4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 10) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 11) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_semi_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_semi_join.groovy index e5bb974a5b133a..5e60250ef91d26 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_semi_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_left_semi_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_left_semi_join") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_left_semi_join") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_left_semi_join") { sql """analyze table orders_2_left_semi_join with sync;""" sql """analyze table lineitem_2_left_semi_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -187,9 +157,9 @@ suite("partition_mv_rewrite_dimension_2_left_semi_join") { logger.info("i:" + i) def mv_name = """mv_name_2_left_semi_join_${i}""" if (i < 3) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -197,96 +167,60 @@ suite("partition_mv_rewrite_dimension_2_left_semi_join") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_anti_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_anti_join.groovy index 957a1b45a080e5..289ed57287f1d8 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_anti_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_anti_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_right_anti_join") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_right_anti_join") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_right_anti_join") { sql """analyze table orders_2_right_anti_join with sync;""" sql """analyze table lineitem_2_right_anti_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -187,9 +157,9 @@ suite("partition_mv_rewrite_dimension_2_right_anti_join") { logger.info("i:" + i) def mv_name = """mv_name_2_right_anti_join_${i}""" if (i < 3) { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -197,96 +167,60 @@ suite("partition_mv_rewrite_dimension_2_right_anti_join") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_join.groovy index 83c41fd0fd4ff2..8d6abb6dc561f8 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_right_join") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_right_join") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_right_join") { sql """analyze table orders_2_right_join with sync;""" sql """analyze table lineitem_2_right_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -225,9 +195,9 @@ suite("partition_mv_rewrite_dimension_2_right_join") { logger.info("i:" + i) def mv_name = """mv_name_2_right_join_${i}""" if (i < 6) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -235,96 +205,60 @@ suite("partition_mv_rewrite_dimension_2_right_join") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 2, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { @@ -332,96 +266,60 @@ suite("partition_mv_rewrite_dimension_2_right_join") { logger.info("j:" + j) // 5, 11 should be success but not now, should support in the future by equivalence class if (j in [4, 5, 6, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 8, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 7, 9, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 10) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 10, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 11) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 11]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_semi_join.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_semi_join.groovy index c1307667685fdc..8f1f6f48a0ae91 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_semi_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_2_right_semi_join.groovy @@ -40,7 +40,6 @@ suite("partition_mv_rewrite_dimension_2_right_semi_join") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("partition_mv_rewrite_dimension_2_right_semi_join") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -104,34 +102,6 @@ suite("partition_mv_rewrite_dimension_2_right_semi_join") { sql """analyze table orders_2_right_semi_join with sync;""" sql """analyze table lineitem_2_right_semi_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -187,9 +157,9 @@ suite("partition_mv_rewrite_dimension_2_right_semi_join") { logger.info("i:" + i) def mv_name = """mv_name_2_right_semi_join_${i}""" if (i < 3) { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -197,96 +167,60 @@ suite("partition_mv_rewrite_dimension_2_right_semi_join") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 2]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + order_by_stmt) } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_self_conn.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_self_conn.groovy index 2cc50eafd378fe..f433e18f48c062 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_self_conn.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension/dimension_self_conn.groovy @@ -39,7 +39,6 @@ suite("partition_mv_rewrite_dimension_self_conn") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -69,7 +68,6 @@ suite("partition_mv_rewrite_dimension_self_conn") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -103,19 +101,6 @@ suite("partition_mv_rewrite_dimension_self_conn") { sql """analyze table orders_self_conn with sync;""" sql """analyze table lineitem_self_conn with sync;""" - def create_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -143,9 +128,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { on t1.l_orderkey = t2.l_orderkey """ - create_mv(mv_name_1, join_direction_mv_1) - def job_name_1 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_name_1, join_direction_mv_1) def join_direction_sql_1 = """ select t1.L_SHIPDATE @@ -153,10 +136,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { left join lineitem_self_conn as t2 on t1.l_orderkey = t2.l_orderkey """ - explain { - sql("${join_direction_sql_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(join_direction_sql_1, mv_name_1) compare_res(join_direction_sql_1 + " order by 1") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_1};""" @@ -190,51 +170,35 @@ suite("partition_mv_rewrite_dimension_self_conn") { for (int i =0; i < mv_list.size(); i++) { logger.info("i:" + i) def join_self_conn_mv = """join_self_conn_mv_${i}""" - create_mv(join_self_conn_mv, mv_list[i]) - def job_name = getJobName(db, join_self_conn_mv) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, join_self_conn_mv, mv_list[i]) + if (i == 0) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 2) { continue } - explain { - sql("${mv_list[j]}") - contains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_success(mv_list[j], join_self_conn_mv) compare_res(mv_list[j] + join_self_conn_order) } } else if (i == 1) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 1 || j == 3) { - explain { - sql("${mv_list[j]}") - contains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_success(mv_list[j], join_self_conn_mv) compare_res(mv_list[j] + join_self_conn_order) } else { - explain { - sql("${mv_list[j]}") - notContains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_fail(mv_list[j], join_self_conn_mv) } } } else if (i == 2) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 2) { - explain { - sql("${mv_list[j]}") - contains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_success(mv_list[j], join_self_conn_mv) compare_res(mv_list[j] + join_self_conn_order) } else { - explain { - sql("${mv_list[j]}") - notContains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_fail(mv_list[j], join_self_conn_mv) } } @@ -242,32 +206,20 @@ suite("partition_mv_rewrite_dimension_self_conn") { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 1 || j == 3) { - explain { - sql("${mv_list[j]}") - contains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_success(mv_list[j], join_self_conn_mv) compare_res(mv_list[j] + join_self_conn_order) } else { - explain { - sql("${mv_list[j]}") - notContains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_fail(mv_list[j], join_self_conn_mv) } } } else if (i == 4) { for (int j = 0; j < mv_list.size(); j++) { logger.info("j:" + j) if (j == 4) { - explain { - sql("${mv_list[j]}") - contains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_success(mv_list[j], join_self_conn_mv) compare_res(mv_list[j] + join_self_conn_order) } else { - explain { - sql("${mv_list[j]}") - notContains "${join_self_conn_mv}(${join_self_conn_mv})" - } + mv_rewrite_fail(mv_list[j], join_self_conn_mv) } } } @@ -312,55 +264,36 @@ suite("partition_mv_rewrite_dimension_self_conn") { for (int i = 0; i < join_type_stmt_list.size(); i++) { logger.info("i:" + i) String join_type_self_conn_mv = """join_type_self_conn_mv_${i}""" - create_mv(join_type_self_conn_mv, join_type_stmt_list[i]) - def job_name = getJobName(db, join_type_self_conn_mv) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, join_type_self_conn_mv, join_type_stmt_list[i]) + if (i in [4, 5]) { for (int j = 0; j < join_type_stmt_list.size(); j++) { logger.info("j: " + j) if (j in [4, 5]) { - explain { - sql("${join_type_stmt_list[j]}") - contains "${join_type_self_conn_mv}(${join_type_self_conn_mv})" - } + mv_rewrite_success(join_type_stmt_list[j], join_type_self_conn_mv) compare_res(join_type_stmt_list[j] + " order by 1,2,3") } else { - explain { - sql("${join_type_stmt_list[j]}") - notContains "${join_type_self_conn_mv}(${join_type_self_conn_mv})" - } + mv_rewrite_fail(join_type_stmt_list[j], join_type_self_conn_mv) } } } else if (i in [6, 7]) { for (int j = 0; j < join_type_stmt_list.size(); j++) { logger.info("j: " + j) if (j in [6, 7]) { - explain { - sql("${join_type_stmt_list[j]}") - contains "${join_type_self_conn_mv}(${join_type_self_conn_mv})" - } + mv_rewrite_success(join_type_stmt_list[j], join_type_self_conn_mv) compare_res(join_type_stmt_list[j] + " order by 1,2,3") } else { - explain { - sql("${join_type_stmt_list[j]}") - notContains "${join_type_self_conn_mv}(${join_type_self_conn_mv})" - } + mv_rewrite_fail(join_type_stmt_list[j], join_type_self_conn_mv) } } } else { for (int j = 0; j < join_type_stmt_list.size(); j++) { logger.info("j:" + j) if (i == j) { - explain { - sql("${join_type_stmt_list[j]}") - contains "${join_type_self_conn_mv}(${join_type_self_conn_mv})" - } + mv_rewrite_success(join_type_stmt_list[j], join_type_self_conn_mv) compare_res(join_type_stmt_list[j] + " order by 1,2,3") } else { - explain { - sql("${join_type_stmt_list[j]}") - notContains "${join_type_self_conn_mv}(${join_type_self_conn_mv})" - } + mv_rewrite_fail(join_type_stmt_list[j], join_type_self_conn_mv) } } } @@ -383,9 +316,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { group by t2.o_orderkey """ - create_mv(mv_name_1, agg_mv_stmt) - job_name_1 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_name_1, agg_mv_stmt) def agg_sql_1 = """select t2.o_orderkey, count(distinct case when t1.o_shippriority > 1 and t1.o_orderkey IN (1, 3) then t1.o_custkey else null end) as cnt_1, @@ -399,10 +330,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { on t1.o_orderkey = t2.o_orderkey group by t2.o_orderkey """ - explain { - sql("${agg_sql_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(agg_sql_1, mv_name_1) compare_res(agg_sql_1 + " order by 1,2,3,4,5,6,7") agg_sql_1 = """select t2.o_orderkey, @@ -417,10 +345,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { on t1.o_orderkey = t2.o_orderkey group by t2.o_orderkey """ - explain { - sql("${agg_sql_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(agg_sql_1, mv_name_1) compare_res(agg_sql_1 + " order by 1,2,3,4,5,6") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_1};""" @@ -436,10 +361,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { t2.o_shippriority, t1.o_comment """ - create_mv(mv_name_1, agg_mv_stmt_2) - def agg_job_name_2 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(agg_job_name_2) - sql """analyze table ${mv_name_1} with sync;""" + create_async_mv(db, mv_name_1, agg_mv_stmt_2) def agg_sql_2 = """ select t2.O_SHIPPRIORITY, t1.o_comment @@ -450,10 +372,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { t2.o_shippriority, t1.o_comment """ - explain { - sql("${agg_sql_2}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(agg_sql_2, mv_name_1) compare_res(agg_sql_2 + " order by 1,2") // agg + with group by + with agg function @@ -473,10 +392,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { t2.o_shippriority, t1.o_comment """ - create_mv(mv_name_1, agg_mv_stmt_3) - def agg_job_name_3 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(agg_job_name_3) - sql """analyze table ${mv_name_1} with sync;""" + create_async_mv(db, mv_name_1, agg_mv_stmt_3) def agg_sql_3 = """ select t2.o_shippriority, t1.o_comment, @@ -493,10 +409,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { t2.o_shippriority, t1.o_comment """ - explain { - sql("${agg_sql_3}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(agg_sql_3, mv_name_1) compare_res(agg_sql_3 + " order by 1,2,3,4,5,6") @@ -507,9 +420,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { inner join lineitem_self_conn as t2 on t1.L_ORDERKEY = t2.L_ORDERKEY group by t1.l_shipdate, t2.l_partkey, t1.l_orderkeY""" - create_mv(mv_name_1, view_partition_mv_stmt_1) - def view_partition_job_name_1 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(view_partition_job_name_1) + create_async_mv(db, mv_name_1, view_partition_mv_stmt_1) def view_partition_sql_1 = """select t.l_shipdate, lineitem_self_conn.l_orderkey, t.l_partkey from ( @@ -523,10 +434,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { on t.l_partkey = lineitem_self_conn.l_partkey group by t.l_shipdate, lineitem_self_conn.l_orderkey, t.l_partkey """ - explain { - sql("${view_partition_sql_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(view_partition_sql_1, mv_name_1) compare_res(view_partition_sql_1 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_1};""" @@ -539,9 +447,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { on t1.l_orderkey = t2.l_orderkey where t1.l_shipdate >= "2023-10-17" """ - create_mv(mv_name_1, predicate_mv_stmt_1) - def predicate_job_name_1 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(predicate_job_name_1) + create_async_mv(db, mv_name_1, predicate_mv_stmt_1) def predicate_sql_1 = """ select t1.l_shipdatE, t2.l_shipdate, t1.l_partkey @@ -550,10 +456,7 @@ suite("partition_mv_rewrite_dimension_self_conn") { on t1.l_orderkey = t2.l_orderkey where t1.l_shipdate >= "2023-10-17" and t1.l_partkey = 1 """ - explain { - sql("${predicate_sql_1}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(predicate_sql_1, mv_name_1) compare_res(predicate_sql_1 + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name_1};""" diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_2_join_agg.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_2_join_agg.groovy index 4d28ea5f3edd1e..dee43f20f4926a 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_2_join_agg.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_2_join_agg.groovy @@ -39,7 +39,6 @@ suite("dimension_2_join_agg_replenish") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -69,7 +68,6 @@ suite("dimension_2_join_agg_replenish") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -103,47 +101,6 @@ suite("dimension_2_join_agg_replenish") { sql """analyze table orders with sync;""" sql """analyze table lineitem with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -904,14 +861,9 @@ suite("dimension_2_join_agg_replenish") { def mv_name = "mv_" + (i + 1) - create_all_mv(mv_name, sql_list[i]) - def job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, sql_list[i]) - explain { - sql("${sql_list[i]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(sql_list[i], mv_name) compare_res(sql_list[i] + " order by 1,2,3") sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_join_agg_negative.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_join_agg_negative.groovy index 995e070d4b845a..04bd6ac5c6ac8d 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_join_agg_negative.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_2_join_agg/dimension_join_agg_negative.groovy @@ -39,7 +39,6 @@ suite("dimension_join_agg_negative") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -69,7 +68,6 @@ suite("dimension_join_agg_negative") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -103,19 +101,6 @@ suite("dimension_join_agg_negative") { sql """analyze table orders_negative with sync;""" sql """analyze table lineitem_negative with sync;""" - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - // left join + agg (function + group by + +-*/ + filter) def left_mv_stmt_1 = """select t1.o_orderdate, t1.o_shippriority, t1.o_orderkey from (select o_orderkey, o_custkey, o_orderstatus, o_orderdate, o_shippriority from orders_negative group by o_orderkey, o_custkey, o_orderstatus, o_orderdate, o_shippriority) as t1 @@ -465,14 +450,9 @@ suite("dimension_join_agg_negative") { def mv_name = "mv_negative_" + (i + 1) - create_all_mv(mv_name, sql_list[i]) - def job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, sql_list[i]) - explain { - sql("${query_list[i]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_list[i], mv_name) sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_equal/filter_equal_or_notequal.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_equal/filter_equal_or_notequal.groovy index fed1ec06ed7e42..763880ea94be44 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_equal/filter_equal_or_notequal.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_equal/filter_equal_or_notequal.groovy @@ -37,7 +37,6 @@ suite("filter_equal_or_notequal_case") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -67,7 +66,6 @@ suite("filter_equal_or_notequal_case") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -101,34 +99,6 @@ suite("filter_equal_or_notequal_case") { sql """analyze table orders_1 with sync;""" sql """analyze table lineitem_1 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -154,9 +124,7 @@ suite("filter_equal_or_notequal_case") { where l_shipdate = '2023-10-17' """ - create_mv_lineitem(mv_name, mtmv_sql) - def job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mv equal and sql equal def query_sql = """ @@ -168,10 +136,7 @@ suite("filter_equal_or_notequal_case") { """ def res_tmp = sql """explain ${query_sql}""" logger.info("res_temp:" + res_tmp) - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // mv equal and sql not equal @@ -182,10 +147,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate != '2023-10-17' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv equal and sql equal and number is difference query_sql = """ @@ -195,10 +157,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate = '2023-10-19' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey @@ -208,9 +167,7 @@ suite("filter_equal_or_notequal_case") { where l_shipdate != '2023-10-17' """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mv not equal and sql equal query_sql = """ @@ -220,10 +177,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate = '2023-10-17' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv not equal and sql not equal query_sql = """ @@ -233,10 +187,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate != '2023-10-17' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") @@ -248,9 +199,7 @@ suite("filter_equal_or_notequal_case") { where l_shipdate > '2023-10-17' """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mv is range and sql equal and filter not in mv range query_sql = """ @@ -260,10 +209,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate = '2023-10-16' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql equal and filter in mv range query_sql = """ @@ -273,10 +219,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate = '2023-10-17' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql equal and filter in mv range query_sql = """ @@ -286,10 +229,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate = '2023-10-19' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // mv is range and sql is range and sql range is bigger than mv @@ -300,10 +240,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-16' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql is range and sql range is not in mv range query_sql = """ @@ -313,10 +250,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate < '2023-10-16' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql is range and sql range is bigger than mv query_sql = """ @@ -326,10 +260,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-17' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // mv is range and sql is range and sql range is not in mv range @@ -340,10 +271,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate < '2023-10-17' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql is range and sql range is bigger than mv query_sql = """ @@ -353,10 +281,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-18' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // mv is range and sql is range and sql range is not in mv range @@ -367,10 +292,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate < '2023-10-19' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql is range and sql range is bigger than mv query_sql = """ @@ -380,10 +302,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-16' and l_shipdate < '2023-10-17' """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mv is range and sql is range and sql range is not in mv range query_sql = """ @@ -393,10 +312,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-17' and l_shipdate < '2023-10-19' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // sql range is not in mv range @@ -407,10 +323,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate in ('2023-10-17') """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // sql range is in mv range // single value @@ -421,10 +334,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate in ('2023-10-18') """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // multi value @@ -435,10 +345,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate in ('2023-10-18', '2023-11-18') """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // sql range like mv range @@ -449,10 +356,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate like "%2023-10-18%" """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // sql range is null query_sql = """ @@ -462,10 +366,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate is null """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // sql range is not null query_sql = """ @@ -475,10 +376,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate is not null """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey @@ -488,9 +386,7 @@ suite("filter_equal_or_notequal_case") { where l_shipdate > '2023-10-16' and l_shipdate < '2023-10-19' """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mv is range and sql is range and filter not in mv range query_sql = """ @@ -500,10 +396,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-16' and l_shipdate < '2023-10-19' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") @@ -514,10 +407,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate > '2023-10-17' and l_shipdate < '2023-10-19' """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // @@ -529,9 +419,7 @@ suite("filter_equal_or_notequal_case") { where l_shipdate in ('2023-10-17', '2023-10-18', '2023-10-19') """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mv is in range and sql is in range and filter is in mv range query_sql = """ @@ -541,10 +429,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate in ('2023-10-17', '2023-10-18', '2023-10-19') """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // mv is in range and sql is in range and filter is not in mv range @@ -555,10 +440,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate not in ('2023-10-17', '2023-10-18', '2023-10-19') """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey @@ -568,9 +450,7 @@ suite("filter_equal_or_notequal_case") { where l_shipdate like "%2023-10-17%" """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mv is like filter and sql is like filter and filter number is equal query_sql = """ @@ -580,10 +460,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate like "%2023-10-17%" """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // mv is like filter and sql is not like filter @@ -594,10 +471,7 @@ suite("filter_equal_or_notequal_case") { on lineitem_1.l_orderkey = orders_1.o_orderkey where l_shipdate like "%2023-10-17%" """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) compare_res(query_sql + " order by 1,2,3,4") // Todo: It is not currently supported and is expected to be @@ -610,9 +484,7 @@ suite("filter_equal_or_notequal_case") { // where l_shipdate between '2023-10-16' and '2023-10-19' // """ // -// create_mv_lineitem(mv_name, mtmv_sql) -// job_name = getJobName(db, mv_name) -// waitingMTMVTaskFinished(job_name) +// create_async_mv(db, mv_name, mtmv_sql) // // query_sql = """ // select l_shipdate, o_orderdate, l_partkey, l_suppkey diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/full_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/full_join_filter.groovy index 4268876a333886..ce30fab1b6c71e 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/full_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/full_join_filter.groovy @@ -43,7 +43,6 @@ suite("full_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("full_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -107,19 +105,6 @@ suite("full_join_filter") { sql """analyze table orders_full_join with sync;""" sql """analyze table lineitem_full_join with sync;""" - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -198,167 +183,105 @@ suite("full_join_filter") { for (int i = 0; i < mv_list_1.size(); i++) { logger.info("i:" + i) def mv_name = """mv_name_full_join_${i}""" - create_all_mv(mv_name, mv_list_1[i]) - def job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mv_list_1[i]) if (i == 0) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 4, 5, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 4, 6, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [2, 4, 7, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 8, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 4, 5, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 4, 6, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [2, 4, 7, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 8, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/inner_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/inner_join_filter.groovy index 0047029d8a4766..932c2608ad408a 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/inner_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/inner_join_filter.groovy @@ -43,7 +43,6 @@ suite("inner_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("inner_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -107,20 +105,6 @@ suite("inner_join_filter") { sql """analyze table orders_inner_join with sync;""" sql """analyze table lineitem_inner_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -199,167 +183,105 @@ suite("inner_join_filter") { for (int i = 0; i < mv_list_1.size(); i++) { logger.info("i:" + i) def mv_name = """mv_name_inner_join_${i}""" - create_mv_lineitem(mv_name, mv_list_1[i]) - def job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mv_list_1[i]) if (i == 0) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 4, 5, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 4, 6, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 7, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 6, 8, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 4, 5, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 4, 6, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 5, 7, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 6, 8, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_anti_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_anti_join_filter.groovy index e3b52b608915d2..d813e55f33286a 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_anti_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_anti_join_filter.groovy @@ -43,7 +43,6 @@ suite("left_anti_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("left_anti_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -109,34 +107,6 @@ suite("left_anti_join_filter") { sql """analyze table orders_left_anti_join with sync;""" sql """analyze table lineitem_left_anti_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -209,9 +179,9 @@ suite("left_anti_join_filter") { logger.info("i:" + i) def mv_name = """mv_name_left_anti_join_${i}""" if (i < 4) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -219,128 +189,80 @@ suite("left_anti_join_filter") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 5, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 6, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_join_filter.groovy index 587994922c1ae5..608aec88c63621 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_join_filter.groovy @@ -43,7 +43,6 @@ suite("left_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("left_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -107,34 +105,6 @@ suite("left_join_filter") { sql """analyze table orders_left_join with sync;""" sql """analyze table lineitem_left_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -214,9 +184,9 @@ suite("left_join_filter") { logger.info("i:" + i) def mv_name = """mv_name_left_join_${i}""" if (i < 5) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -224,160 +194,100 @@ suite("left_join_filter") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 6, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 7, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 6, 8, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_semi_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_semi_join_filter.groovy index 048e09448c4b44..da12c8fbeaef3f 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_semi_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/left_semi_join_filter.groovy @@ -43,7 +43,6 @@ suite("left_semi_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("left_semi_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -107,34 +105,6 @@ suite("left_semi_join_filter") { sql """analyze table orders_left_semi_join with sync;""" sql """analyze table lineitem_left_semi_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -202,9 +172,9 @@ suite("left_semi_join_filter") { logger.info("i:" + i) def mv_name = """mv_name_left_semi_join_${i}""" if (i < 4) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -212,128 +182,80 @@ suite("left_semi_join_filter") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [0, 2, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 5, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5, 6, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_anti_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_anti_join_filter.groovy index d2143209df9682..b920b766b07aa4 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_anti_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_anti_join_filter.groovy @@ -43,7 +43,6 @@ suite("right_anti_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("right_anti_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -109,34 +107,6 @@ suite("right_anti_join_filter") { sql """analyze table orders_right_anti_join with sync;""" sql """analyze table lineitem_right_anti_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -208,9 +178,9 @@ suite("right_anti_join_filter") { logger.info("i:" + i) def mv_name = """mv_name_right_anti_join_${i}""" if (i > 3) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -218,96 +188,60 @@ suite("right_anti_join_filter") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 2, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { @@ -315,32 +249,20 @@ suite("right_anti_join_filter") { logger.info("j:" + j) // 5, 11 should be success but not now, should support in the future by equivalence class if (j in [4, 6, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_join_filter.groovy index a9261951b356ee..f3223855173f48 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_join_filter.groovy @@ -43,7 +43,6 @@ suite("right_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -73,7 +72,6 @@ suite("right_join_filter") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -107,34 +105,6 @@ suite("right_join_filter") { sql """analyze table orders_right_join with sync;""" sql """analyze table lineitem_right_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -214,9 +184,9 @@ suite("right_join_filter") { logger.info("i:" + i) def mv_name = """mv_name_right_join_${i}""" if (i > 4) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -224,160 +194,100 @@ suite("right_join_filter") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [2, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3, 4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 6, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 5, 7, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 8) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 8, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 9) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 9]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3,4,5") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_semi_join_filter.groovy b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_semi_join_filter.groovy index b86356438e60eb..bbf4e60afb64ec 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_semi_join_filter.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dimension_predicate/right_semi_join_filter.groovy @@ -107,34 +107,6 @@ suite("right_semi_join_filter") { sql """analyze table orders_right_semi_join with sync;""" sql """analyze table lineitem_right_semi_join with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -202,9 +174,9 @@ suite("right_semi_join_filter") { logger.info("i:" + i) def mv_name = """mv_name_right_semi_join_${i}""" if (i > 3) { - create_mv_lineitem(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } else { - create_mv_orders(mv_name, mv_list_1[i]) + create_async_mv(db, mv_name, mv_list_1[i]) } def job_name = getJobName(db, mv_name) waitingMTMVTaskFinished(job_name) @@ -212,96 +184,60 @@ suite("right_semi_join_filter") { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [ 0]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 1) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 2) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [1, 2, 3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 3) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [3]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 4) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [4, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 5) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [5]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 6) { @@ -309,32 +245,20 @@ suite("right_semi_join_filter") { logger.info("j:" + j) // 5, 11 should be success but not now, should support in the future by equivalence class if (j in [4, 6, 7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } else if (i == 7) { for (int j = 0; j < mv_list_1.size(); j++) { logger.info("j:" + j) if (j in [7]) { - explain { - sql("${mv_list_1[j]}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(mv_list_1[j], mv_name) compare_res(mv_list_1[j] + " order by 1,2,3") } else { - explain { - sql("${mv_list_1[j]}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(mv_list_1[j], mv_name) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/direct_query/direct_query.groovy b/regression-test/suites/nereids_rules_p0/mv/direct_query/direct_query.groovy index 404154300d2724..6ebc97896e5e6c 100644 --- a/regression-test/suites/nereids_rules_p0/mv/direct_query/direct_query.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/direct_query/direct_query.groovy @@ -38,7 +38,6 @@ suite("direct_query_mv") { o_comment VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -69,7 +68,6 @@ suite("direct_query_mv") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/dml/external/dml_query_has_external_table.groovy b/regression-test/suites/nereids_rules_p0/mv/dml/external/dml_query_has_external_table.groovy index faef522f105d99..4c2b79998eb48f 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dml/external/dml_query_has_external_table.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dml/external/dml_query_has_external_table.groovy @@ -70,17 +70,6 @@ suite("dml_query_has_external_table") { ) """ - def create_async_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mv_sql} - """ - waitingMTMVTaskFinished(getJobName(db, mv_name)) - } def result_test_sql = """select * from insert_target_olap_table;""" @@ -97,7 +86,7 @@ suite("dml_query_has_external_table") { count_value; """ - create_async_mv(insert_into_async_mv_name_external, """ + create_async_mv(dbName, insert_into_async_mv_name_external, """ select id, count_value @@ -114,26 +103,15 @@ suite("dml_query_has_external_table") { sql "set enable_dml_materialized_view_rewrite=true"; sql "set enable_dml_materialized_view_rewrite_when_base_table_data_unawareness=false"; - explain { - sql """ + mv_not_part_in( """ insert into insert_target_olap_table - ${insert_into_async_query_external}""" - check {result -> - !result.contains(insert_into_async_mv_name_external) - } - } + ${insert_into_async_query_external}""", insert_into_async_mv_name_external) sql "set enable_dml_materialized_view_rewrite_when_base_table_data_unawareness=true"; - explain { - sql """ + mv_rewrite_success_without_check_chosen(""" insert into insert_target_olap_table ${insert_into_async_query_external} - """ - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(insert_into_async_mv_name_external) : false - } - } + """, insert_into_async_mv_name_external) sql """insert into insert_target_olap_table ${insert_into_async_query_external}""" order_qt_query_insert_into_async_mv_after "${result_test_sql}" diff --git a/regression-test/suites/nereids_rules_p0/mv/dml/insert/dml_insert_and_overwrite.groovy b/regression-test/suites/nereids_rules_p0/mv/dml/insert/dml_insert_and_overwrite.groovy index 7b258b8a1b8328..54e9b57f7e5adb 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dml/insert/dml_insert_and_overwrite.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dml/insert/dml_insert_and_overwrite.groovy @@ -68,18 +68,6 @@ suite("dml_insert_and_overwrite") { ) """ - def create_async_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mv_sql} - """ - waitingMTMVTaskFinished(getJobName(db, mv_name)) - } - def result_test_sql = """select * from insert_target_olap_table;""" @@ -101,7 +89,7 @@ suite("dml_insert_and_overwrite") { ps_supplycost, ps_comment; """ - create_async_mv(insert_into_async_mv_name, + create_async_mv(db, insert_into_async_mv_name, """select ps_partkey, ps_suppkey, @@ -122,14 +110,9 @@ suite("dml_insert_and_overwrite") { // enable dml rewrite by mv sql "set enable_dml_materialized_view_rewrite=true"; - explain { - sql """insert into insert_target_olap_table - ${insert_into_async_query}""" - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(insert_into_async_mv_name) : false - } - } + mv_rewrite_success_without_check_chosen ( + """insert into insert_target_olap_table + ${insert_into_async_query}""", insert_into_async_mv_name) sql """insert into insert_target_olap_table ${insert_into_async_query}""" order_qt_query_insert_into_async_mv_after "${result_test_sql}" @@ -176,14 +159,9 @@ suite("dml_insert_and_overwrite") { // enable dml rewrite by mv sql "set enable_dml_materialized_view_rewrite=true"; - explain { - sql """insert into insert_target_olap_table - ${insert_into_sync_query}""" - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(insert_into_sync_mv_name) : false - } - } + mv_rewrite_success_without_check_chosen ( + """insert into insert_target_olap_table + ${insert_into_sync_query}""", insert_into_sync_mv_name) sql """insert into insert_target_olap_table ${insert_into_sync_query}""" order_qt_query_insert_into_sync_mv_after "${result_test_sql}" @@ -208,7 +186,7 @@ suite("dml_insert_and_overwrite") { ps_supplycost, ps_comment; """ - create_async_mv(insert_overwrite_async_mv_name, + create_async_mv(db, insert_overwrite_async_mv_name, """select ps_partkey, ps_suppkey, @@ -229,14 +207,8 @@ suite("dml_insert_and_overwrite") { // enable dml rewrite by mv sql "set enable_dml_materialized_view_rewrite=true"; - explain { - sql """INSERT OVERWRITE table insert_target_olap_table - ${insert_overwrite_async_query}""" - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(insert_overwrite_async_mv_name) : false - } - } + mv_rewrite_success_without_check_chosen ("""INSERT OVERWRITE table insert_target_olap_table + ${insert_overwrite_async_query}""", insert_overwrite_async_mv_name) sql """INSERT OVERWRITE table insert_target_olap_table ${insert_overwrite_async_query}""" order_qt_query_insert_overwrite_async_mv_after "${result_test_sql}" @@ -260,7 +232,7 @@ suite("dml_insert_and_overwrite") { ps_supplycost, ps_comment; """ - create_async_mv(insert_overwrite_sync_mv_name, + create_async_mv(db, insert_overwrite_sync_mv_name, """select ps_partkey, ps_suppkey, diff --git a/regression-test/suites/nereids_rules_p0/mv/dml/outfile/dml_into_outfile.groovy b/regression-test/suites/nereids_rules_p0/mv/dml/outfile/dml_into_outfile.groovy index 42c1c835e0dd92..350e49057d08ba 100644 --- a/regression-test/suites/nereids_rules_p0/mv/dml/outfile/dml_into_outfile.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/dml/outfile/dml_into_outfile.groovy @@ -69,18 +69,6 @@ suite("dml_into_outfile", "p0") { sql """analyze table partsupp with sync;""" - def create_async_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mv_sql} - """ - waitingMTMVTaskFinished(getJobName(db, mv_name)) - } - def outfile_to_S3 = {query_sql -> // select ... into outfile ... def res = sql """ @@ -117,7 +105,7 @@ suite("dml_into_outfile", "p0") { ); """ - create_async_mv(into_outfile_async_mv_name, + create_async_mv(db, into_outfile_async_mv_name, """select ps_partkey, ps_suppkey, @@ -138,13 +126,8 @@ suite("dml_into_outfile", "p0") { // enable dml rewrite by mv sql "set enable_dml_materialized_view_rewrite=true"; - explain { - sql """${into_outfile_async_query}""" - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(into_outfile_async_mv_name) : false - } - } + mv_rewrite_success_without_check_chosen ( + """${into_outfile_async_query}""", into_outfile_async_mv_name) def outfile_url = outfile_to_S3(into_outfile_async_query) order_qt_query_into_outfile_async_mv_after """ SELECT * FROM S3 ( @@ -206,13 +189,7 @@ suite("dml_into_outfile", "p0") { // enable dml rewrite by mv sql "set enable_dml_materialized_view_rewrite=true"; - explain { - sql """${into_outfile_sync_query}""" - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(into_outfile_sync_mv_name) : false - } - } + mv_rewrite_success_without_check_chosen ("""${into_outfile_sync_query}""", into_outfile_sync_mv_name) def sync_outfile_url = outfile_to_S3(into_outfile_sync_query) order_qt_query_into_outfile_sync_mv_after """ SELECT * FROM S3 ( diff --git a/regression-test/suites/nereids_rules_p0/mv/external_table/mv_contain_external_table.groovy b/regression-test/suites/nereids_rules_p0/mv/external_table/mv_contain_external_table.groovy index 5ddc532a72f94d..42e27150c5f7fe 100644 --- a/regression-test/suites/nereids_rules_p0/mv/external_table/mv_contain_external_table.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/external_table/mv_contain_external_table.groovy @@ -160,33 +160,21 @@ suite("mv_contain_external_table", "p0,external,hive,external_docker,external_do // test query rewrite by mv, should fail ,because materialized_view_rewrite_enable_contain_external_table // switch is false default - explain { - sql(""" ${query_sql}""") - notContains("${mv_name}(${mv_name})") - } + mv_not_part_in(query_sql, mv_name) sql "SET materialized_view_rewrite_enable_contain_external_table=true" - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) // data change in external table doesn't influence query rewrite, // if want to use new data in external table should be refresh manually hive_docker """ ${insert_str3} """ - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_query_rewritten_with_old_data """ ${query_sql}""" // refresh manually sql """REFRESH catalog ${catalog_name}""" sql """REFRESH MATERIALIZED VIEW ${mv_name} complete""" waitingMTMVTaskFinished(getJobName(db, mv_name)) - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_query_rewritten_with_new_data """ ${query_sql}""" @@ -196,19 +184,13 @@ suite("mv_contain_external_table", "p0,external,hive,external_docker,external_do def insert_str4 = """ insert into ${hive_database}.${hive_table} PARTITION(o_orderdate='2023-10-20') values(3, 3, 'ok', 100.5, 'f', 'h', 3, 'ss')""" hive_docker """ ${insert_str4} """ - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_query_rewritten_with_old_data_after_add_partition """ ${query_sql}""" sql """REFRESH catalog ${catalog_name}""" sql """REFRESH MATERIALIZED VIEW ${mv_name} complete""" waitingMTMVTaskFinished(getJobName(db, mv_name)) - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_query_rewritten_with_new_data """ ${query_sql}""" hive_docker """ ${autogather_on_str} """ diff --git a/regression-test/suites/nereids_rules_p0/mv/external_table/part_partition_invalid.groovy b/regression-test/suites/nereids_rules_p0/mv/external_table/part_partition_invalid.groovy index d2e6f18824def8..4d02edec19562a 100644 --- a/regression-test/suites/nereids_rules_p0/mv/external_table/part_partition_invalid.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/external_table/part_partition_invalid.groovy @@ -141,139 +141,92 @@ suite("part_partition_invalid", "p0,external") { // test query rewrite by mv, should fail ,because materialized_view_rewrite_enable_contain_external_table // is false default - explain { - sql(""" ${query_sql}""") - notContains("${mv_name}(${mv_name})") - } + mv_rewrite_fail(query_sql, mv_name) sql "SET materialized_view_rewrite_enable_contain_external_table=true" - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) // data change in external table doesn't influence query rewrite, // if want to use new data in external table should be refresh manually sql """insert into ${hive_catalog_name}.${hive_database}.${hive_table} values(3, 3, 'ok', 99.5, 'a', 'b', 1, 'yy', '2023-10-19');""" - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_after_modify_data_without_refresh_catalog """ ${query_sql}""" - explain { - sql(""" + mv_rewrite_success(""" ${query_sql} where o_orderdate = '2023-10-19'; - """) - // query invalid partition data, should hit mv, because not check now. - contains("${mv_name}(${mv_name})") - } + """, mv_name) order_qt_after_modify_and_without_refresh_catalog_19 """ ${query_sql} where o_orderdate = '2023-10-19';""" - explain { - sql(""" - ${query_sql} where o_orderdate = '2023-10-18'; - """) - // query valid partition data, should hit mv - contains("${mv_name}(${mv_name})") - } + // query valid partition data, should hit mv + mv_rewrite_success(""" + ${query_sql} where o_orderdate = '2023-10-18'; + """, mv_name + ) order_qt_after_modify_and_without_refresh_catalog_18 """ ${query_sql} where o_orderdate = '2023-10-18';""" // refresh catalog cache sql """ REFRESH CATALOG ${hive_catalog_name} PROPERTIES("invalid_cache" = "true"); """ - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_after_modify_data_and_refresh_catalog """ ${query_sql}""" - explain { - sql(""" + // query invalid partition data, should hit mv, because not check now. + mv_rewrite_success(""" ${query_sql} where o_orderdate = '2023-10-19'; - """) - // query invalid partition data, should hit mv, because not check now. - contains("${mv_name}(${mv_name})") - } + """, mv_name) order_qt_after_modify_and_refresh_catalog_19 """ ${query_sql} where o_orderdate = '2023-10-19';""" - explain { - sql(""" + // query valid partition data, should hit mv + mv_rewrite_success(""" ${query_sql} where o_orderdate = '2023-10-18'; - """) - // query valid partition data, should hit mv - contains("${mv_name}(${mv_name})") - } + """, mv_name) order_qt_after_modify_and_refresh_catalog_18 """ ${query_sql} where o_orderdate = '2023-10-18';""" // refresh manually sql """ REFRESH CATALOG ${hive_catalog_name} PROPERTIES("invalid_cache" = "true"); """ sql """REFRESH MATERIALIZED VIEW ${mv_name} auto""" waitingMTMVTaskFinished(getJobName(olap_db, mv_name)) - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_after_modify_data_and_refresh_catalog_and_mv """ ${query_sql}""" // test after hive add partition sql """insert into ${hive_catalog_name}.${hive_database}.${hive_table} values(6, 7, 'ok', 29.5, 'x', 'y', 6, 'ss', '2023-10-20');""" - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_after_add_data_without_refresh_catalog """ ${query_sql}""" - explain { - sql(""" - ${query_sql} - """) - // query invalid partition data, should hit mv, because not check now. - contains("${mv_name}(${mv_name})") - } + // query invalid partition data, should hit mv, because not check now. + mv_rewrite_success(query_sql, mv_name) + order_qt_after_add_and_without_refresh_catalog_19 """ ${query_sql} where o_orderdate = '2023-10-19';""" - explain { - sql(""" + // query valid partition data, should hit mv + mv_rewrite_success(""" ${query_sql} where o_orderdate = '2023-10-20'; - """) - // query valid partition data, should hit mv - notContains("${mv_name}(${mv_name})") - } + """, mv_name) + order_qt_after_add_and_without_refresh_catalog_20 """ ${query_sql} where o_orderdate = '2023-10-20';""" // refresh catalog cache sql """ REFRESH CATALOG ${hive_catalog_name} PROPERTIES("invalid_cache" = "true"); """ - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_after_add_data_with_refresh_catalog """ ${query_sql}""" - explain { - sql(""" + // query invalid partition data, should hit mv, because not check now. + mv_rewrite_success(""" ${query_sql} where o_orderdate = '2023-10-19'; - """) - // query invalid partition data, should hit mv, because not check now. - contains("${mv_name}(${mv_name})") - } + """, mv_name) + order_qt_after_add_and_refresh_catalog_19 """ ${query_sql} where o_orderdate = '2023-10-19';""" - explain { - sql(""" + // query valid partition data, should hit mv + mv_rewrite_success(""" ${query_sql} where o_orderdate = '2023-10-20'; - """) - // query valid partition data, should hit mv - notContains("${mv_name}(${mv_name})") - } + """, mv_name) order_qt_after_add_and_refresh_catalog_20 """ ${query_sql} where o_orderdate = '2023-10-20';""" // refresh manually sql """ REFRESH CATALOG ${hive_catalog_name} PROPERTIES("invalid_cache" = "true"); """ sql """REFRESH MATERIALIZED VIEW ${mv_name} auto""" waitingMTMVTaskFinished(getJobName(olap_db, mv_name)) - explain { - sql(""" ${query_sql}""") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(query_sql, mv_name) order_qt_after_add_data_and_refresh_catalog_and_mv """ ${query_sql}""" sql """drop table if exists ${hive_catalog_name}.${hive_database}.${hive_table}""" diff --git a/regression-test/suites/nereids_rules_p0/mv/external_table/single_external_table.groovy b/regression-test/suites/nereids_rules_p0/mv/external_table/single_external_table.groovy index 30f3fe64b3f8d9..1600dc7cc22d07 100644 --- a/regression-test/suites/nereids_rules_p0/mv/external_table/single_external_table.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/external_table/single_external_table.groovy @@ -88,7 +88,7 @@ suite("single_external_table", "p0,external,hive") { from ${hive_catalog_name}.${hive_database}.${hive_table}; """ order_qt_query1_0_before "${query1_0}" - check_mv_rewrite_success(olap_db, mv1_0, query1_0, "mv1_0") + async_mv_rewrite_success(olap_db, mv1_0, query1_0, "mv1_0") order_qt_query1_0_after "${query1_0}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv1_0""" @@ -105,7 +105,7 @@ suite("single_external_table", "p0,external,hive") { where o_custkey > 2; """ order_qt_query1_1_before "${query1_1}" - check_mv_rewrite_success(olap_db, mv1_1, query1_1, "mv1_1") + async_mv_rewrite_success(olap_db, mv1_1, query1_1, "mv1_1") order_qt_query1_1_after "${query1_1}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv1_1""" diff --git a/regression-test/suites/nereids_rules_p0/mv/grouping_sets/grouping_sets.groovy b/regression-test/suites/nereids_rules_p0/mv/grouping_sets/grouping_sets.groovy index b7b1215e5658fe..ec8cecbaf517d0 100644 --- a/regression-test/suites/nereids_rules_p0/mv/grouping_sets/grouping_sets.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/grouping_sets/grouping_sets.groovy @@ -42,11 +42,6 @@ suite("materialized_view_grouping_sets") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -77,10 +72,6 @@ suite("materialized_view_grouping_sets") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/join/dphyp_inner/inner_join_dphyp.groovy b/regression-test/suites/nereids_rules_p0/mv/join/dphyp_inner/inner_join_dphyp.groovy index 60b649a8cafce7..2b018ebc37373b 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join/dphyp_inner/inner_join_dphyp.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join/dphyp_inner/inner_join_dphyp.groovy @@ -38,7 +38,6 @@ suite("inner_join_dphyp") { o_comment VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -69,7 +68,6 @@ suite("inner_join_dphyp") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/join/dphyp_outer/outer_join_dphyp.groovy b/regression-test/suites/nereids_rules_p0/mv/join/dphyp_outer/outer_join_dphyp.groovy index 1e34ca299a317b..45d9aee067c798 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join/dphyp_outer/outer_join_dphyp.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join/dphyp_outer/outer_join_dphyp.groovy @@ -38,7 +38,6 @@ suite("outer_join_dphyp") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -69,7 +68,6 @@ suite("outer_join_dphyp") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy b/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy index 6fdfe08ed2f16a..b745f7d0197c28 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy @@ -37,7 +37,6 @@ suite("inner_join") { o_comment VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -68,7 +67,6 @@ suite("inner_join") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/join/left_outer/outer_join.groovy b/regression-test/suites/nereids_rules_p0/mv/join/left_outer/outer_join.groovy index 4ebb57b9338e95..92b8dc2670bcd5 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join/left_outer/outer_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join/left_outer/outer_join.groovy @@ -38,7 +38,6 @@ suite("outer_join") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -62,7 +61,6 @@ suite("outer_join") { O_COMMENT VARCHAR(79) NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -93,7 +91,6 @@ suite("outer_join") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/inner_join_infer_and_derive.groovy b/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/inner_join_infer_and_derive.groovy index 766f656adb617d..5688c2bbe21d6a 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/inner_join_infer_and_derive.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/inner_join_infer_and_derive.groovy @@ -44,7 +44,6 @@ suite("inner_join_infer_and_derive") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -74,7 +73,6 @@ suite("inner_join_infer_and_derive") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -108,19 +106,6 @@ suite("inner_join_infer_and_derive") { sql """analyze table orders_inner with sync;""" sql """analyze table lineitem_inner with sync;""" - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -226,22 +211,16 @@ suite("inner_join_infer_and_derive") { def order_stmt = " order by 1, 2, 3, 4, 5" for (int mtmv_it = 0; mtmv_it < mtmv_stmt_list.size(); mtmv_it++) { logger.info("mtmv_it:" + mtmv_it) - create_all_mv(mv_name_1, mtmv_stmt_list[mtmv_it]) + create_async_mv(db, mv_name_1, mtmv_stmt_list[mtmv_it]) def job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) if (mtmv_it == 0) { for (int i = 0; i < query_list.size(); i++) { logger.info("i: " + i) if (i in [0, 2, 5, 6, 8, 11]) { - explain { - sql("${query_list[i]}") - notContains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_fail(query_list[i], mv_name_1) } else { - explain { - sql("${query_list[i]}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(query_list[i], mv_name_1) compare_res(query_list[i] + order_stmt) } } @@ -249,15 +228,9 @@ suite("inner_join_infer_and_derive") { for (int i = 0; i < query_list.size(); i++) { logger.info("i: " + i) if (i in [1, 3, 4, 7, 9, 10]) { - explain { - sql("${query_list[i]}") - notContains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_fail(query_list[i], mv_name_1) } else { - explain { - sql("${query_list[i]}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(query_list[i], mv_name_1) compare_res(query_list[i] + order_stmt) } } @@ -265,16 +238,10 @@ suite("inner_join_infer_and_derive") { for (int i = 0; i < query_list.size(); i++) { logger.info("i: " + i) if (i in [12, 13]) { - explain { - sql("${query_list[i]}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(query_list[i], mv_name_1) compare_res(query_list[i] + order_stmt) } else { - explain { - sql("${query_list[i]}") - notContains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_fail(query_list[i], mv_name_1) } } } diff --git a/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/left_join_infer_and_derive.groovy b/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/left_join_infer_and_derive.groovy index f6d68c354cb035..dbfaa783383af8 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/left_join_infer_and_derive.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/left_join_infer_and_derive.groovy @@ -44,7 +44,6 @@ suite("left_join_infer_and_derive") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -74,7 +73,6 @@ suite("left_join_infer_and_derive") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -108,18 +106,6 @@ suite("left_join_infer_and_derive") { sql """analyze table orders_left with sync;""" sql """analyze table lineitem_left with sync;""" - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" @@ -217,22 +203,16 @@ suite("left_join_infer_and_derive") { def order_stmt = " order by 1, 2, 3, 4, 5" for (int mtmv_it = 0; mtmv_it < mtmv_stmt_list.size(); mtmv_it++) { logger.info("mtmv_it:" + mtmv_it) - create_all_mv(mv_name_1, mtmv_stmt_list[mtmv_it]) + create_async_mv(db, mv_name_1, mtmv_stmt_list[mtmv_it]) def job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) if (mtmv_it == 0) { for (int i = 0; i < query_list.size(); i++) { logger.info("i: " + i) if (i in [1, 3, 4, 6, 8, 11]) { - explain { - sql("${query_list[i]}") - notContains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_fail(query_list[i], mv_name_1) } else { - explain { - sql("${query_list[i]}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(query_list[i], mv_name_1) compare_res(query_list[i] + order_stmt) } } diff --git a/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/right_join_infer_and_derive.groovy b/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/right_join_infer_and_derive.groovy index 5ce0d334b669ca..4b5bdf467a5d02 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/right_join_infer_and_derive.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join_infer_derive/right_join_infer_and_derive.groovy @@ -44,7 +44,6 @@ suite("right_join_infer_and_derive") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -74,7 +73,6 @@ suite("right_join_infer_and_derive") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - AUTO PARTITION BY range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -108,19 +106,6 @@ suite("right_join_infer_and_derive") { sql """analyze table orders_right with sync;""" sql """analyze table lineitem_right with sync;""" - def create_all_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -217,22 +202,16 @@ suite("right_join_infer_and_derive") { def order_stmt = " order by 1, 2, 3, 4, 5" for (int mtmv_it = 0; mtmv_it < mtmv_stmt_list.size(); mtmv_it++) { logger.info("mtmv_it:" + mtmv_it) - create_all_mv(mv_name_1, mtmv_stmt_list[mtmv_it]) + create_async_mv(db, mv_name_1, mtmv_stmt_list[mtmv_it]) def job_name_1 = getJobName(db, mv_name_1) waitingMTMVTaskFinished(job_name_1) if (mtmv_it == 0) { for (int i = 0; i < query_list.size(); i++) { logger.info("i: " + i) if (i in [0, 2, 5, 7, 9, 10]) { - explain { - sql("${query_list[i]}") - notContains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_fail(query_list[i], mv_name_1) } else { - explain { - sql("${query_list[i]}") - contains "${mv_name_1}(${mv_name_1})" - } + mv_rewrite_success(query_list[i], mv_name_1) compare_res(query_list[i] + order_stmt) } } diff --git a/regression-test/suites/nereids_rules_p0/mv/negative/negative_test.groovy b/regression-test/suites/nereids_rules_p0/mv/negative/negative_test.groovy index f7328e1798ae57..03ddf46fdf1d3b 100644 --- a/regression-test/suites/nereids_rules_p0/mv/negative/negative_test.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/negative/negative_test.groovy @@ -39,7 +39,6 @@ suite("negative_partition_mv_rewrite") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -69,7 +68,6 @@ suite("negative_partition_mv_rewrite") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -129,47 +127,6 @@ suite("negative_partition_mv_rewrite") { sql """analyze table lineitem_1 with sync;""" sql """analyze table partsupp_1 with sync;""" - def create_mv_lineitem = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(l_shipdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv_orders = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - partition by(o_orderdate) - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - - def create_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def mv_name = "mv_1" def mtmv_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey @@ -178,9 +135,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey """ - create_mv_lineitem(mv_name, mtmv_sql) - def job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) // mtmv not exists query col def query_sql = """ @@ -189,10 +144,7 @@ suite("negative_partition_mv_rewrite") { left join orders_1 on lineitem_1.l_orderkey = orders_1.o_orderkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // Swap tables on either side of the left join query_sql = """ @@ -201,10 +153,7 @@ suite("negative_partition_mv_rewrite") { left join lineitem_1 on orders_1.o_orderkey = lineitem_1.l_orderkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // The filter condition of the query is not in the filter range of mtmv mtmv_sql = """ @@ -213,19 +162,14 @@ suite("negative_partition_mv_rewrite") { left join orders_1 on t1.l_orderkey = orders_1.o_orderkey """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey from (select * from lineitem_1 where l_shipdate = '2023-10-18' ) t1 left join orders_1 on t1.l_orderkey = orders_1.o_orderkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // The filter range of the query is larger than that of the mtmv mtmv_sql = """ @@ -235,9 +179,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey > 2 """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey from lineitem_1 @@ -245,10 +187,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey > 1 """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) query_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey @@ -257,10 +196,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey > 2 or orders_1.o_orderkey < 0 """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // filter in mtmv_sql = """ @@ -270,9 +206,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey in (1, 2, 3) """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey from lineitem_1 @@ -280,10 +214,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey in (1, 2, 3, 4) """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // agg not roll up mtmv_sql = """ @@ -294,18 +225,13 @@ suite("negative_partition_mv_rewrite") { o_shippriority, o_comment """ - create_mv_orders(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select o_orderdate from orders_1 """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select o_orderdate, o_shippriority, o_comment, @@ -321,9 +247,7 @@ suite("negative_partition_mv_rewrite") { o_shippriority, o_comment """ - create_mv_orders(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select @@ -335,10 +259,7 @@ suite("negative_partition_mv_rewrite") { bitmap_union(to_bitmap(case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end)) as cnt_2 from orders_1 """ - explain { - sql("${query_sql}") - contains "${mv_name}(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) // query partial rewriting mtmv_sql = """ @@ -348,18 +269,13 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey group by l_shipdate, o_orderdate, l_partkey, l_suppkey """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, l_partkey, count(*) from lineitem_1 group by l_shipdate, l_partkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select @@ -372,9 +288,7 @@ suite("negative_partition_mv_rewrite") { from orders_1 left join lineitem_1 on lineitem_1.l_orderkey = orders_1.o_orderkey """ - create_mv(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select @@ -386,18 +300,13 @@ suite("negative_partition_mv_rewrite") { count(*) from orders_1 """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // view partial rewriting mtmv_sql = """ select l_shipdate, l_partkey, l_orderkey, count(*) from lineitem_1 group by l_shipdate, l_partkey, l_orderkey """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, l_partkey, l_orderkey, count(*) @@ -405,10 +314,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_shipdate=orders_1.o_orderdate group by l_shipdate, l_partkey, l_orderkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select o_orderdate, o_shippriority, o_comment, l_orderkey, o_orderkey, sum(o_orderkey) @@ -421,9 +327,7 @@ suite("negative_partition_mv_rewrite") { l_orderkey, o_orderkey """ - create_mv_orders(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select o_orderdate, o_shippriority, o_comment, l_orderkey, ps_partkey, sum(o_orderkey) @@ -437,10 +341,7 @@ suite("negative_partition_mv_rewrite") { l_orderkey, ps_partkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // union rewrite mtmv_sql = """ @@ -451,9 +352,7 @@ suite("negative_partition_mv_rewrite") { where l_shipdate >= "2023-10-17" group by l_shipdate, o_orderdate, l_partkey """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, o_orderdate, l_partkey, count(*) @@ -463,10 +362,7 @@ suite("negative_partition_mv_rewrite") { where l_shipdate >= "2023-10-15" group by l_shipdate, o_orderdate, l_partkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) mtmv_sql = """ select l_shipdate, l_partkey, l_orderkey @@ -474,9 +370,7 @@ suite("negative_partition_mv_rewrite") { where l_shipdate >= "2023-10-10" group by l_shipdate, l_partkey, l_orderkey """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select t.l_shipdate, o_orderdate, t.l_partkey @@ -486,10 +380,7 @@ suite("negative_partition_mv_rewrite") { where l_shipdate >= "2023-10-10" group by t.l_shipdate, o_orderdate, t.l_partkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // project rewriting mtmv_sql = """ @@ -498,9 +389,7 @@ suite("negative_partition_mv_rewrite") { case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end as cnt_2 from orders_1; """ - create_mv_orders(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select o_shippriority, o_comment, o_shippriority + o_custkey + o_orderkey, @@ -508,10 +397,7 @@ suite("negative_partition_mv_rewrite") { case when o_shippriority > 2 and o_orderkey IN (2) then o_custkey else null end as cnt_2 from orders_1; """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // agg under join mtmv_sql = """ @@ -521,9 +407,7 @@ suite("negative_partition_mv_rewrite") { group by t1.o_orderdate, t1.o_shippriority, t1.o_orderkey """ - create_mv_orders(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select t1.o_orderdate, t1.o_shippriority, t1.o_orderkey @@ -532,10 +416,7 @@ suite("negative_partition_mv_rewrite") { group by t1.o_orderdate, t1.o_shippriority, t1.o_orderkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // filter include and or mtmv_sql = """ @@ -545,9 +426,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey > 2 and orders_1.o_orderdate >= "2023-10-17" or l_partkey > 1 """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) query_sql = """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey from lineitem_1 @@ -555,10 +434,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey = orders_1.o_orderkey where orders_1.o_orderkey > 2 and (orders_1.o_orderdate >= "2023-10-17" or l_partkey > 1) """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // group by under group by mtmv_sql = """ @@ -568,19 +444,15 @@ suite("negative_partition_mv_rewrite") { GROUP BY l_orderkey) AS c_orders GROUP BY c_count ORDER BY custdist DESC, c_count DESC; """ - create_mv(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) + query_sql = """ SELECT c_count, count(*) AS custdist FROM (SELECT l_orderkey, count(o_orderkey) AS c_count FROM lineitem_1 LEFT OUTER JOIN orders_1 ON l_orderkey = o_custkey AND o_comment NOT LIKE '%special%requests%' GROUP BY l_orderkey) AS c_orders GROUP BY c_count ORDER BY custdist DESC, c_count DESC;""" - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // condition on not equal mtmv_sql = """ @@ -590,9 +462,8 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey > orders_1.o_orderkey group by l_shipdate, o_orderdate, l_partkey; """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) + query_sql = """ select l_shipdate, o_orderdate, l_partkey, count(*) from lineitem_1 @@ -600,10 +471,7 @@ suite("negative_partition_mv_rewrite") { on lineitem_1.l_orderkey > orders_1.o_orderkey group by l_shipdate, o_orderdate, l_partkey """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) // mtmv exists join but not exists agg, query exists agg mtmv_sql = """ @@ -612,9 +480,8 @@ suite("negative_partition_mv_rewrite") { left join orders_1 on t.l_orderkey = orders_1.o_orderkey; """ - create_mv_lineitem(mv_name, mtmv_sql) - job_name = getJobName(db, mv_name) - waitingMTMVTaskFinished(job_name) + create_async_mv(db, mv_name, mtmv_sql) + query_sql = """ select l_shipdate, o_orderdate, l_partkey from (select l_shipdate, l_partkey, l_orderkey from lineitem_1 group by l_shipdate, l_partkey, l_orderkey) as t @@ -622,8 +489,5 @@ suite("negative_partition_mv_rewrite") { on t.l_orderkey = orders_1.o_orderkey group by l_shipdate, o_orderdate, l_partkey ; """ - explain { - sql("${query_sql}") - notContains "${mv_name}(${mv_name})" - } + mv_rewrite_fail(query_sql, mv_name) } diff --git a/regression-test/suites/nereids_rules_p0/mv/nested/nested_materialized_view.groovy b/regression-test/suites/nereids_rules_p0/mv/nested/nested_materialized_view.groovy index faf0f67ea3d1ab..3a130d489eb036 100644 --- a/regression-test/suites/nereids_rules_p0/mv/nested/nested_materialized_view.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/nested/nested_materialized_view.groovy @@ -101,20 +101,6 @@ suite("nested_materialized_view") { sql "set runtime_filter_mode=OFF" sql "SET enable_materialized_view_nest_rewrite = true" - def create_mtmv = { db_name, mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mv_sql} - """ - - def job_name = getJobName(db_name, mv_name); - waitingMTMVTaskFinished(job_name) - } - sql """ drop table if exists orders """ @@ -132,7 +118,6 @@ suite("nested_materialized_view") { o_comment VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -163,7 +148,6 @@ suite("nested_materialized_view") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -251,7 +235,7 @@ suite("nested_materialized_view") { where o_orderstatus = 'o' """ order_qt_query1_0_before "${query1_0}" - create_mtmv(db, "mv1_0_inner_mv", mv1_0_inner_mv) + create_async_mv(db, "mv1_0_inner_mv", mv1_0_inner_mv) async_mv_rewrite_success(db, mv1_0, query1_0, "mv1_0") order_qt_query1_0_after "${query1_0}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv1_0_inner_mv""" @@ -261,18 +245,15 @@ suite("nested_materialized_view") { sql "SET enable_materialized_view_nest_rewrite = false" order_qt_query1_1_before "${query1_0}" - create_mtmv(db, "mv1_0_inner_mv", mv1_0_inner_mv) + create_async_mv(db, "mv1_0_inner_mv", mv1_0_inner_mv) async_mv_rewrite_fail(db, mv1_0, query1_0, "mv1_0") - explain { - sql("${query1_0}") - contains("mv1_0_inner_mv(mv1_0_inner_mv)") - } + mv_rewrite_success(query1_0, "mv1_0_inner_mv") order_qt_query1_1_after "${query1_0}" // complex nest mv rewrite - create_mtmv(db, "mv1_a", """ + create_async_mv(db, "mv1_a", """ select lo_custkey, lo_partkey, @@ -290,7 +271,7 @@ suite("nested_materialized_view") { lo_orderkey, lo_orderdate;""") - create_mtmv(db, "mv2_a", """ + create_async_mv(db, "mv2_a", """ select lo_custkey, lo_orderdate, @@ -305,7 +286,7 @@ suite("nested_materialized_view") { lo_custkey, lo_orderdate;""") - create_mtmv(db, "mv4_a", """ + create_async_mv(db, "mv4_a", """ select lo_partkey, lo_orderdate, @@ -320,7 +301,7 @@ suite("nested_materialized_view") { lo_partkey, lo_orderdate;""") - create_mtmv(db, "mv_all_6_a", """ + create_async_mv(db, "mv_all_6_a", """ select '测试1' as nm, '测试2' as t_nm, @@ -345,7 +326,7 @@ from and t6.d_sellingseason = 'Spring'; """) - create_mtmv(db, "mv1_b", """ + create_async_mv(db, "mv1_b", """ select lo_custkey, lo_partkey, @@ -363,7 +344,7 @@ select lo_orderkey, lo_orderdate;""") - create_mtmv(db, "mv2_b", """ + create_async_mv(db, "mv2_b", """ select lo_custkey, lo_orderdate, @@ -378,7 +359,7 @@ select lo_custkey, lo_orderdate;""") - create_mtmv(db, "mv4_b", """ + create_async_mv(db, "mv4_b", """ select lo_partkey, lo_orderdate, @@ -393,7 +374,7 @@ select lo_partkey, lo_orderdate;""") - create_mtmv(db, "mv_all_6_b", """ + create_async_mv(db, "mv_all_6_b", """ select '测试1' as nm, '测试2' as t_nm, @@ -419,7 +400,7 @@ from """) - create_mtmv(db, "mv1_c", """ + create_async_mv(db, "mv1_c", """ select lo_custkey, lo_partkey, @@ -437,7 +418,7 @@ from lo_orderkey, lo_orderdate;""") - create_mtmv(db, "mv2_c", """ + create_async_mv(db, "mv2_c", """ select lo_custkey, lo_orderdate, @@ -452,7 +433,7 @@ from lo_custkey, lo_orderdate;""") - create_mtmv(db, "mv4_c", """ + create_async_mv(db, "mv4_c", """ select lo_partkey, lo_orderdate, @@ -467,7 +448,7 @@ from lo_partkey, lo_orderdate;""") - create_mtmv(db, "mv_all_6_c", """ + create_async_mv(db, "mv_all_6_c", """ select '测试1' as nm, '测试2' as t_nm, @@ -493,7 +474,7 @@ from """) - create_mtmv(db, "mv1_d", """ + create_async_mv(db, "mv1_d", """ select lo_custkey, lo_partkey, @@ -511,7 +492,7 @@ from lo_orderkey, lo_orderdate;""") - create_mtmv(db, "mv2_d", """ + create_async_mv(db, "mv2_d", """ select lo_custkey, lo_orderdate, @@ -526,7 +507,7 @@ from lo_custkey, lo_orderdate;""") - create_mtmv(db, "mv4_d", """ + create_async_mv(db, "mv4_d", """ select lo_partkey, lo_orderdate, @@ -541,7 +522,7 @@ from lo_partkey, lo_orderdate;""") - create_mtmv(db, "mv_all_6_d", """ + create_async_mv(db, "mv_all_6_d", """ select '测试1' as nm, '测试2' as t_nm, @@ -916,13 +897,7 @@ select * from ( sql "SET enable_materialized_view_rewrite= true" sql "SET enable_materialized_view_nest_rewrite = true" - explain { - sql("${query2_0}") - check {result -> - result.contains("mv_all_6_a(mv_all_6_a)") && result.contains("mv_all_6_b(mv_all_6_b)") - && result.contains("mv_all_6_c(mv_all_6_c)") && result.contains("mv_all_6_d(mv_all_6_d)") - } - } + mv_rewrite_all_success(query2_0, ["mv_all_6_a", "mv_all_6_b", "mv_all_6_c", "mv_all_6_d"]) // Compare result when before and after mv rewrite compare_res(query2_0) } diff --git a/regression-test/suites/nereids_rules_p0/mv/nested_mtmv/nested_mtmv.groovy b/regression-test/suites/nereids_rules_p0/mv/nested_mtmv/nested_mtmv.groovy index 5b2c386fa34a1a..700c17606d2539 100644 --- a/regression-test/suites/nereids_rules_p0/mv/nested_mtmv/nested_mtmv.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/nested_mtmv/nested_mtmv.groovy @@ -40,7 +40,6 @@ suite("nested_mtmv") { ) ENGINE=OLAP DUPLICATE KEY(`o_orderkey`, `o_custkey`) COMMENT 'OLAP' - auto partition by range (date_trunc(`o_orderdate`, 'day')) () DISTRIBUTED BY HASH(`o_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -70,7 +69,6 @@ suite("nested_mtmv") { ) ENGINE=OLAP DUPLICATE KEY(l_orderkey, l_linenumber, l_partkey, l_suppkey ) COMMENT 'OLAP' - auto partition by range (date_trunc(`l_shipdate`, 'day')) () DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 96 PROPERTIES ( "replication_allocation" = "tag.location.default: 1" @@ -134,19 +132,6 @@ suite("nested_mtmv") { sql """analyze table lineitem_1 with sync;""" sql """analyze table partsupp_1 with sync;""" - def create_mv = { mv_name, mv_sql -> - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name};""" - sql """DROP TABLE IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS - ${mv_sql} - """ - } - def compare_res = { def stmt -> sql "SET enable_materialized_view_rewrite=false" def origin_res = sql stmt @@ -184,17 +169,11 @@ suite("nested_mtmv") { FROM ${mv_name_2} GROUP BY l_orderkey;""" def mv_name_3 = "join_agg_mv3" - create_mv(mv_name_1, mv_stmt_1) - def job_name_1 = getJobName(db, mv_name_1) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_name_1, mv_stmt_1) - create_mv(mv_name_2, mv_stmt_2) - job_name_1 = getJobName(db, mv_name_2) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_name_2, mv_stmt_2) - create_mv(mv_name_3, mv_stmt_3) - job_name_1 = getJobName(db, mv_name_3) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_name_3, mv_stmt_3) def query_stmt_1 = """SELECT l_orderkey, @@ -203,10 +182,7 @@ suite("nested_mtmv") { FROM lineitem_1 INNER JOIN orders_1 ON l_orderkey = o_orderkey GROUP BY l_orderkey""" - explain { - sql("${query_stmt_1}") - contains "${mv_name_3}(${mv_name_3})" - } + mv_rewrite_success(query_stmt_1, mv_name_3) compare_res(query_stmt_1 + " order by 1,2,3") // user @@ -239,21 +215,13 @@ suite("nested_mtmv") { """ def mv_level4_name = "mv_level4_name" - create_mv(mv_level1_name, mv_stmt_4) - job_name_1 = getJobName(db, mv_level1_name) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_level1_name, mv_stmt_4) - create_mv(mv_level2_name, mv_stmt_5) - job_name_1 = getJobName(db, mv_level2_name) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_level2_name, mv_stmt_5) - create_mv(mv_level3_name, mv_stmt_6) - job_name_1 = getJobName(db, mv_level3_name) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_level3_name, mv_stmt_6) - create_mv(mv_level4_name, mv_stmt_7) - job_name_1 = getJobName(db, mv_level4_name) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_level4_name, mv_stmt_7) def query_stmt_2 = """ select t1.l_orderkey, t2.l_linenumber, t1.l_partkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.col1 @@ -276,14 +244,8 @@ suite("nested_mtmv") { ) as t1 ) as t2 on t1.l_orderkey = t2.l_orderkey """ - explain { - sql("${query_stmt_2}") - check {result -> - // both mv_level4_name and mv_level3_name can be rewritten successfully - result.contains("${mv_level4_name}(${mv_level4_name})") - || result.contains("${mv_level3_name}(${mv_level3_name})") - } - } + mv_rewrite_any_success(query_stmt_2, [mv_level4_name, mv_level3_name]) + compare_res(query_stmt_2 + " order by 1,2,3,4,5,6,7") // five level @@ -344,25 +306,15 @@ suite("nested_mtmv") { group by t1.l_orderkey, t2.l_partkey, t1.l_suppkey, t2.o_orderkey, t1.o_custkey, t2.ps_partkey, t1.ps_suppkey, t2.agg1, t1.agg2, t2.agg3, t1.agg4, t2.agg5, t1.agg6 """ - create_mv(mv_1, join_mv_1) - job_name_1 = getJobName(db, mv_1) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_1, join_mv_1) - create_mv(mv_2, join_mv_2) - job_name_1 = getJobName(db, mv_2) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_2, join_mv_2) - create_mv(mv_3, join_mv_3) - job_name_1 = getJobName(db, mv_3) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_3, join_mv_3) - create_mv(mv_4, join_mv_4) - job_name_1 = getJobName(db, mv_4) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_4, join_mv_4) - create_mv(mv_5, join_mv_5) - job_name_1 = getJobName(db, mv_5) - waitingMTMVTaskFinished(job_name_1) + create_async_mv(db, mv_5, join_mv_5) def sql_2 = """ diff --git a/regression-test/suites/nereids_rules_p0/mv/partition_mv_rewrite.groovy b/regression-test/suites/nereids_rules_p0/mv/partition_mv_rewrite.groovy index 7106dfbb08f2a8..35a983c264c0e2 100644 --- a/regression-test/suites/nereids_rules_p0/mv/partition_mv_rewrite.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/partition_mv_rewrite.groovy @@ -153,14 +153,11 @@ suite("partition_mv_rewrite") { analyze table mv_10086 with sync; """ sleep(10000) - explain { - sql("${all_partition_sql}") - contains("mv_10086(mv_10086)") - } - explain { - sql("${partition_sql}") - contains("mv_10086(mv_10086)") - } + mv_rewrite_success(all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) + + mv_rewrite_success(partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) // base table partition data change sql """ insert into lineitem values @@ -175,21 +172,17 @@ suite("partition_mv_rewrite") { sql "analyze table mv_10086 with sync" def memo = sql "explain memo plan ${all_partition_sql}" print(memo) - explain { - sql("${all_partition_sql}") - // should rewrite successful when union rewrite enalbe if sub partition is invalid - contains("mv_10086(mv_10086)") - } + // should rewrite successful when union rewrite enalbe if sub partition is invalid + mv_rewrite_success(all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_3_0_after "${all_partition_sql}" sql "SET enable_materialized_view_rewrite=false" order_qt_query_4_0_before "${partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${partition_sql}") - // should rewrite successfully when union rewrite enable if doesn't query invalid partition - contains("mv_10086(mv_10086)") - } + // should rewrite successfully when union rewrite enable if doesn't query invalid partition + mv_rewrite_success(partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_4_0_after "${partition_sql}" // base table add partition @@ -206,21 +199,17 @@ suite("partition_mv_rewrite") { sql "SET enable_materialized_view_rewrite=false" order_qt_query_7_0_before "${all_partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${all_partition_sql}") - // should rewrite successful when union rewrite enalbe if base table add new partition - contains("mv_10086(mv_10086)") - } + // should rewrite successful when union rewrite enalbe if base table add new partition + mv_rewrite_success(all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_7_0_after "${all_partition_sql}" sql "SET enable_materialized_view_rewrite=false" order_qt_query_8_0_before "${partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${partition_sql}") - // should rewrite successfully when union rewrite enable if doesn't query new partition - contains("mv_10086(mv_10086)") - } + // should rewrite successfully when union rewrite enable if doesn't query new partition + mv_rewrite_success(partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_8_0_after "${partition_sql}" // base table delete partition test @@ -235,21 +224,17 @@ suite("partition_mv_rewrite") { sql "SET enable_materialized_view_rewrite=false" order_qt_query_11_0_before "${all_partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${all_partition_sql}") - // should rewrite successful when union rewrite enalbe if base table delete partition - contains("mv_10086(mv_10086)") - } + // should rewrite successful when union rewrite enalbe if base table delete partition + mv_rewrite_success(all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_11_0_after "${all_partition_sql}" sql "SET enable_materialized_view_rewrite=false" order_qt_query_12_0_before "${partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${partition_sql}") - // should rewrite successfully when union rewrite enable if doesn't query deleted partition - contains("mv_10086(mv_10086)") - } + // should rewrite successfully when union rewrite enable if doesn't query deleted partition + mv_rewrite_success(partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_12_0_after "${partition_sql}" sql """ DROP MATERIALIZED VIEW IF EXISTS mv_10086""" @@ -363,20 +348,15 @@ suite("partition_mv_rewrite") { // test when mv is ttl // enable union rewrite sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${ttl_all_partition_sql}") - // should rewrite successful when union rewrite enalbe and mv is ttl, query the partition which is in mv - contains("${ttl_mv_name}(${ttl_mv_name})") - } + // should rewrite successful when union rewrite enalbe and mv is ttl, query the partition which is in mv + mv_rewrite_success(ttl_all_partition_sql, ttl_mv_name, true, + is_partition_statistics_ready(db, ["lineitem_static", "orders", ttl_mv_name])) sql "SET enable_materialized_view_rewrite=false" order_qt_query_16_0_before "${ttl_partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${ttl_partition_sql}") - // should rewrite fail when union rewrite enalbe and query the partition which is not in mv - notContains("${ttl_mv_name}(${ttl_mv_name})") - } + // should rewrite fail when union rewrite enalbe and query the partition which is not in mv + mv_rewrite_fail(ttl_partition_sql, ttl_mv_name) order_qt_query_16_0_after "${ttl_partition_sql}" sql """ DROP MATERIALIZED VIEW IF EXISTS ${ttl_mv_name}""" @@ -443,14 +423,10 @@ suite("partition_mv_rewrite") { analyze table orders with sync; """ - explain { - sql("${roll_up_all_partition_sql}") - contains("mv_10086(mv_10086)") - } - explain { - sql("${roll_up_partition_sql}") - contains("mv_10086(mv_10086)") - } + mv_rewrite_success(roll_up_all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) + mv_rewrite_success(roll_up_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) // base table add partition sql """ insert into lineitem values @@ -467,35 +443,21 @@ suite("partition_mv_rewrite") { analyze table lineitem with sync; analyze table orders with sync; """ - explain { - sql("${roll_up_all_partition_sql}") - // should rewrite successful when union rewrite enalbe if base table add new partition - contains("mv_10086(mv_10086)") - } + + // should rewrite successful when union rewrite enalbe if base table add new partition + mv_rewrite_success(roll_up_all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_17_0_after "${roll_up_all_partition_sql}" sql "SET enable_materialized_view_rewrite=false" order_qt_query_18_0_before "${roll_up_partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${roll_up_partition_sql}") - // should rewrite successfully when union rewrite enable if doesn't query new partition - contains("mv_10086(mv_10086)") - } + // should rewrite successfully when union rewrite enable if doesn't query new partition + mv_rewrite_success(roll_up_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_18_0_after "${roll_up_partition_sql}" - def check_rewrite_but_not_chose = { query_sql, mv_name_param -> - explain { - sql("${query_sql}") - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(mv_name_param) : false - } - } - } - - // base table partition add data sql "REFRESH MATERIALIZED VIEW mv_10086 AUTO" waitingMTMVTaskFinished(getJobName(db, "mv_10086")) @@ -517,21 +479,19 @@ suite("partition_mv_rewrite") { analyze table lineitem with sync; analyze table orders with sync; """ - explain { - sql("${roll_up_all_partition_sql}") - // should rewrite successful when union rewrite enalbe if base table add new partition - contains("mv_10086(mv_10086)") - } + + // should rewrite successful when union rewrite enalbe if base table add new partition + mv_rewrite_success(roll_up_all_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) order_qt_query_19_0_after "${roll_up_all_partition_sql}" sql "SET enable_materialized_view_rewrite=false" order_qt_query_20_0_before "${roll_up_partition_sql}" sql "SET enable_materialized_view_rewrite=true" - explain { - sql("${roll_up_partition_sql}") - // should rewrite successfully when union rewrite enable if doesn't query new partition - contains("mv_10086(mv_10086)") - } + // should rewrite successfully when union rewrite enable if doesn't query new partition + mv_rewrite_success(roll_up_partition_sql, "mv_10086", true, + is_partition_statistics_ready(db, ["lineitem", "orders", "mv_10086"])) + order_qt_query_20_0_after "${roll_up_partition_sql}" diff --git a/regression-test/suites/nereids_rules_p0/mv/same_name/sync_async_same_name.groovy b/regression-test/suites/nereids_rules_p0/mv/same_name/sync_async_same_name.groovy index 20dbc0a083158f..e518c016d2b641 100644 --- a/regression-test/suites/nereids_rules_p0/mv/same_name/sync_async_same_name.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/same_name/sync_async_same_name.groovy @@ -39,11 +39,6 @@ suite("sync_async_same_name") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -64,28 +59,6 @@ suite("sync_async_same_name") { sql """analyze table orders with sync;""" - def check_rewrite_but_not_chose = { mv_sql, query_sql, mv_name -> - - sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mv_sql} - """ - - def job_name = getJobName(db, mv_name); - waitingMTMVTaskFinished(job_name) - explain { - sql("${query_sql}") - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(mv_name) : false - } - } - } - def common_mv_name = 'common_mv_name' def mtmv_sql = """ @@ -139,35 +112,14 @@ suite("sync_async_same_name") { createMV ("create materialized view ${common_mv_name} as ${mv_query};") // create async mv - sql """DROP MATERIALIZED VIEW IF EXISTS ${common_mv_name}""" - sql""" - CREATE MATERIALIZED VIEW ${common_mv_name} - BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 2 - PROPERTIES ('replication_num' = '1') - AS ${mtmv_sql} - """ - def job_name = getJobName(db, common_mv_name); - waitingMTMVTaskFinished(job_name) + create_async_mv(db, common_mv_name, mtmv_sql) + // only async mv rewrite successfully - explain { - sql("${mtmv_query}") - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(common_mv_name) : false - } - } + mv_rewrite_success_without_check_chosen(mtmv_query, common_mv_name) // both sync and async mv rewrite successfully - explain { - sql("${mv_query}") - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(common_mv_name) - && splitResult[0].contains("orders.${common_mv_name}") : false - } - } + mv_rewrite_all_success_without_check_chosen(mv_query, [common_mv_name, "orders.${common_mv_name}"]) order_qt_query_mv_after "${mv_query}" diff --git a/regression-test/suites/nereids_rules_p0/mv/scan/scan_table.groovy b/regression-test/suites/nereids_rules_p0/mv/scan/scan_table.groovy index 0c9aba5ffebae3..6b5c2dc45e875f 100644 --- a/regression-test/suites/nereids_rules_p0/mv/scan/scan_table.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/scan/scan_table.groovy @@ -37,7 +37,6 @@ suite("mv_scan_table") { o_comment VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) (PARTITION `day_2` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -68,7 +67,6 @@ suite("mv_scan_table") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) (PARTITION `day_1` VALUES LESS THAN ('2023-12-30')) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/single_table_without_agg/single_table_without_aggregate.groovy b/regression-test/suites/nereids_rules_p0/mv/single_table_without_agg/single_table_without_aggregate.groovy index c91eb32f7be71b..b6f44bba80139c 100644 --- a/regression-test/suites/nereids_rules_p0/mv/single_table_without_agg/single_table_without_aggregate.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/single_table_without_agg/single_table_without_aggregate.groovy @@ -58,10 +58,7 @@ suite("single_table_without_aggregate") { sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name} ON orders""" createMV("create materialized view ${mv_name} as ${mv_sql}") - explain { - sql("${query_sql}") - contains "(${mv_name})" - } + mv_rewrite_success(query_sql, mv_name) order_qt_query1_0 "${query_sql}" sql """DROP MATERIALIZED VIEW IF EXISTS ${mv_name} ON orders""" } diff --git a/regression-test/suites/nereids_rules_p0/mv/union_all_compensate/union_all_compensate.groovy b/regression-test/suites/nereids_rules_p0/mv/union_all_compensate/union_all_compensate.groovy index dbab81ee22a51b..e72e7575053b5b 100644 --- a/regression-test/suites/nereids_rules_p0/mv/union_all_compensate/union_all_compensate.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/union_all_compensate/union_all_compensate.groovy @@ -160,7 +160,8 @@ suite("union_all_compensate") { sql """set enable_materialized_view_rewrite = false;""" order_qt_query1_0_before "${query1_0}" sql """set enable_materialized_view_rewrite = true;""" - mv_rewrite_success(query1_0, "test_agg_mv") + mv_rewrite_success(query1_0, "test_agg_mv", true, + is_partition_statistics_ready(db, ["test_table1", "test_table2", "test_agg_mv"])) order_qt_query1_0_after "${query1_0}" // Data modify @@ -197,7 +198,8 @@ suite("union_all_compensate") { order_qt_query2_0_before "${query2_0}" sql """set enable_materialized_view_rewrite = true;""" sql """ALTER MATERIALIZED VIEW test_agg_mv set("grace_period"="100000");""" - mv_rewrite_success(query2_0, "test_agg_mv") + mv_rewrite_success(query2_0, "test_agg_mv", true, + is_partition_statistics_ready(db, ["test_table1", "test_table2", "test_agg_mv"])) order_qt_query2_0_after "${query2_0}" @@ -215,11 +217,11 @@ suite("union_all_compensate") { group by t2.slot_id; """ sql """set enable_materialized_view_rewrite = false;""" - order_qt_query3_0_before "${query2_0}" + order_qt_query3_0_before "${query3_0}" sql """set enable_materialized_view_rewrite = true;""" sql """ALTER MATERIALIZED VIEW test_agg_mv set("grace_period"="0");""" - mv_rewrite_fail(query2_0, "test_agg_mv") - order_qt_query3_0_after "${query2_0}" + mv_rewrite_fail(query3_0, "test_agg_mv") + order_qt_query3_0_after "${query3_0}" // Aggregate, if query group by expression use the partition column, but the invalid partition is in the @@ -240,7 +242,8 @@ suite("union_all_compensate") { order_qt_query4_0_before "${query4_0}" sql """set enable_materialized_view_rewrite = true;""" sql """ALTER MATERIALIZED VIEW test_agg_mv set("grace_period"="100000");""" - mv_rewrite_success(query4_0, "test_agg_mv") + mv_rewrite_success(query4_0, "test_agg_mv", true, + is_partition_statistics_ready(db, ["test_table1", "test_table2", "test_agg_mv"])) order_qt_query4_0_after "${query4_0}" @@ -259,11 +262,12 @@ suite("union_all_compensate") { to_date(t1.data_date); """ sql """set enable_materialized_view_rewrite = false;""" - order_qt_query5_0_before "${query4_0}" + order_qt_query5_0_before "${query5_0}" sql """ALTER MATERIALIZED VIEW test_agg_mv set("grace_period"="0");""" sql """set enable_materialized_view_rewrite = true;""" - mv_rewrite_success(query4_0, "test_agg_mv") - order_qt_query5_0_after "${query4_0}" + mv_rewrite_success(query5_0, "test_agg_mv", true, + is_partition_statistics_ready(db, ["test_table1", "test_table2", "test_agg_mv"])) + order_qt_query5_0_after "${query5_0}" sql """ DROP MATERIALIZED VIEW IF EXISTS test_agg_mv""" @@ -289,7 +293,6 @@ suite("union_all_compensate") { test_table2 t4 on t3.data_date = t4.data_date """ waitingMTMVTaskFinishedByMvName("test_join_mv") - sql """analyze table test_table1 with sync""" // Data modify sql """ @@ -299,7 +302,7 @@ suite("union_all_compensate") { ('2024-09-12 00:20:00', 'a', 1), ('2024-09-12 00:20:00', 'b', 1); """ - sql """analyze table test_join_mv with sync""" + sql """analyze table test_table1 with sync""" // Join, if select expression not use the partition column, and the invalid partition is not in the // grace_period, should union all,and should rewritten successfully @@ -317,7 +320,8 @@ suite("union_all_compensate") { sql """set enable_materialized_view_rewrite = false;""" order_qt_query6_0_before "${query6_0}" sql """set enable_materialized_view_rewrite = true;""" - mv_rewrite_success(query6_0, "test_join_mv") + mv_rewrite_success(query6_0, "test_join_mv", true, + is_partition_statistics_ready(db, ["test_table1", "test_table2", "test_join_mv"])) order_qt_query6_0_after "${query6_0}" @@ -338,7 +342,8 @@ suite("union_all_compensate") { order_qt_query7_0_before "${query7_0}" sql """set enable_materialized_view_rewrite = true;""" sql """ALTER MATERIALIZED VIEW test_join_mv set("grace_period"="100000");""" - mv_rewrite_success(query7_0, "test_join_mv") + mv_rewrite_success(query7_0, "test_join_mv", true, + is_partition_statistics_ready(db, ["test_table1", "test_table2", "test_join_mv"])) order_qt_query7_0_after "${query7_0}" sql """ DROP MATERIALIZED VIEW IF EXISTS test_join_mv""" diff --git a/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_curd_union_rewrite.groovy b/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_curd_union_rewrite.groovy index 2c67a373664089..2b00c8200d2589 100644 --- a/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_curd_union_rewrite.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/union_rewrite/partition_curd_union_rewrite.groovy @@ -163,15 +163,12 @@ suite ("partition_curd_union_rewrite") { waitingMTMVTaskFinished(getJobName(db, mv_name)) // All partition is valid, test query and rewrite by materialized view - explain { - sql("${all_partition_sql}") - contains("${mv_name}(${mv_name})") - } + mv_rewrite_success(all_partition_sql, mv_name, true, + is_partition_statistics_ready(db, ["lineitem", "orders", mv_name])) compare_res(all_partition_sql + order_by_stmt) - explain { - sql("${partition_sql}") - contains("${mv_name}(${mv_name})") - } + + mv_rewrite_success(partition_sql, mv_name, true, + is_partition_statistics_ready(db, ["lineitem", "orders", mv_name])) compare_res(partition_sql + order_by_stmt) /* 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 d41f36627aa052..702431e5e391ae 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 @@ -154,23 +154,14 @@ suite ("usercase_union_rewrite") { o_orderdate """ - explain { - sql("${query_stmt}") - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(mv_name) : false - } - } + mv_rewrite_success(query_stmt, mv_name, true, + is_partition_statistics_ready(db, ["orders_user", mv_name])) compare_res(query_stmt + " order by 1,2,3,4,5,6,7,8") sql """insert into orders_user values (5, 5, 'k', 99.5, 'a', 'b', 1, 'yy', '2023-10-19');""" sleep(10 * 1000) - explain { - sql("${query_stmt}") - check {result -> - def splitResult = result.split("MaterializedViewRewriteFail") - splitResult.length == 2 ? splitResult[0].contains(mv_name) : false - } - } + + mv_rewrite_success(query_stmt, mv_name, true, + is_partition_statistics_ready(db, ["orders_user", mv_name])) compare_res(query_stmt + " order by 1,2,3,4,5,6,7,8") } diff --git a/regression-test/suites/nereids_rules_p0/mv/unsafe_equals/null_un_safe_equals.groovy b/regression-test/suites/nereids_rules_p0/mv/unsafe_equals/null_un_safe_equals.groovy index b210dd44850f19..5c64379950f942 100644 --- a/regression-test/suites/nereids_rules_p0/mv/unsafe_equals/null_un_safe_equals.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/unsafe_equals/null_un_safe_equals.groovy @@ -39,11 +39,6 @@ suite("null_unsafe_equals") { O_COMMENT VARCHAR(79) NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" diff --git a/regression-test/suites/nereids_rules_p0/mv/with_auth/with_select_table_auth.groovy b/regression-test/suites/nereids_rules_p0/mv/with_auth/with_select_table_auth.groovy index d84d0c6ed2d421..400e113b6f3ae5 100644 --- a/regression-test/suites/nereids_rules_p0/mv/with_auth/with_select_table_auth.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/with_auth/with_select_table_auth.groovy @@ -44,11 +44,6 @@ suite("with_select_table_auth","p0,auth") { O_COMMENT VARCHAR(79) NOT NULL ) DUPLICATE KEY(o_orderkey, o_custkey) - PARTITION BY RANGE(o_orderdate) ( - PARTITION `day_2` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_3` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_4` VALUES LESS THAN ("2023-12-30") - ) DISTRIBUTED BY HASH(o_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -78,10 +73,6 @@ suite("with_select_table_auth","p0,auth") { l_comment VARCHAR(44) NOT NULL ) DUPLICATE KEY(l_orderkey, l_partkey, l_suppkey, l_linenumber) - PARTITION BY RANGE(l_shipdate) ( - PARTITION `day_1` VALUES LESS THAN ('2023-12-9'), - PARTITION `day_2` VALUES LESS THAN ("2023-12-11"), - PARTITION `day_3` VALUES LESS THAN ("2023-12-30")) DISTRIBUTED BY HASH(l_orderkey) BUCKETS 3 PROPERTIES ( "replication_num" = "1" @@ -125,14 +116,7 @@ suite("with_select_table_auth","p0,auth") { sql """grant select_priv on ${db}.lineitem to ${user_name}""" sql """grant select_priv on regression_test to ${user_name}""" - - sql """drop materialized view if exists mv1;""" - sql """ - CREATE MATERIALIZED VIEW ${db}.mv1 - BUILD IMMEDIATE REFRESH AUTO ON MANUAL - DISTRIBUTED BY RANDOM BUCKETS 1 - PROPERTIES ('replication_num' = '1') - AS + create_async_mv(db, "mv1", """ select l_shipdate, o_orderdate, l_partkey, l_suppkey, sum(o_totalprice) as sum_total, max(o_totalprice) as max_total, @@ -146,9 +130,7 @@ suite("with_select_table_auth","p0,auth") { o_orderdate, l_partkey, l_suppkey; - """ - - sql """analyze table mv1 with sync""" + """) connect(user=user_name, password="${pwd}", url=context.config.jdbcUrl) { sql "use ${db}" diff --git a/regression-test/suites/nereids_syntax_p0/mv/aggregate/agg_sync_mv.groovy b/regression-test/suites/nereids_syntax_p0/mv/aggregate/agg_sync_mv.groovy index 60e3ec316da231..17142d8eda0dc7 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/aggregate/agg_sync_mv.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/aggregate/agg_sync_mv.groovy @@ -44,10 +44,7 @@ suite("agg_sync_mv") { qt_select_approx_count_distinct """select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync3 on agg_mv_test;""" createMV("""create materialized view mv_sync3 as select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync3)" - } + mv_rewrite_success("select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;", "mv_sync3") qt_select_approx_count_distinct_mv """select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;""" qt_select_collect_set """select id, collect_set(kint) from agg_mv_test group by id order by id;""" @@ -453,7 +450,9 @@ suite("agg_sync_mv") { createMV("""create materialized view mv_sync48 as select id, var_pop(kint) from agg_mv_test group by id order by id;""") explain { sql("select id, var_pop(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync47)" + check { result -> + result.contains("(mv_sync47)") || result.contains("(mv_sync48)") + } } qt_select_var_pop_mv """select id, var_pop(kint) from agg_mv_test group by id order by id;""" diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/case_ignore.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/case_ignore.groovy index c60ab23b81455c..91293bb747aa64 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/case_ignore.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/case_ignore.groovy @@ -48,27 +48,15 @@ suite ("case_ignore") { qt_select_star "select * from case_ignore order by k1;" - explain { - sql("select k1,abs(k2) from case_ignore order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select k1,abs(k2) from case_ignore order by k1;", "k12a") order_qt_select_mv "select k1,abs(k2) from case_ignore order by k1;" - explain { - sql("select K1,abs(K2) from case_ignore order by K1;") - contains "(k12a)" - } + mv_rewrite_success("select K1,abs(K2) from case_ignore order by K1;", "k12a") order_qt_select_mv "select K1,abs(K2) from case_ignore order by K1;" sql """set enable_stats=true;""" - explain { - sql("select k1,abs(k2) from case_ignore order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select k1,abs(k2) from case_ignore order by k1;", "k12a") - explain { - sql("select K1,abs(K2) from case_ignore order by K1;") - contains "(k12a)" - } + mv_rewrite_success("select K1,abs(K2) from case_ignore order by K1;", "k12a") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_abs.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_abs.groovy index 13f352a47b5058..132a4c3f054571 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_abs.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_abs.groovy @@ -50,26 +50,14 @@ suite ("dup_gb_mv_abs") { order_qt_select_star "select * from dup_gb_mv_abs order by k1;" - explain { - sql("select k1,sum(abs(k2)) from dup_gb_mv_abs group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select k1,sum(abs(k2)) from dup_gb_mv_abs group by k1;", "k12sa") order_qt_select_mv "select k1,sum(abs(k2)) from dup_gb_mv_abs group by k1 order by k1;" - explain { - sql("select sum(abs(k2)) from dup_gb_mv_abs group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select sum(abs(k2)) from dup_gb_mv_abs group by k1;", "k12sa") order_qt_select_mv_sub "select sum(abs(k2)) from dup_gb_mv_abs group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,sum(abs(k2)) from dup_gb_mv_abs group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select k1,sum(abs(k2)) from dup_gb_mv_abs group by k1;", "k12sa") - explain { - sql("select sum(abs(k2)) from dup_gb_mv_abs group by k1;") - contains "(k12sa)" - } + mv_rewrite_success("select sum(abs(k2)) from dup_gb_mv_abs group by k1;", "k12sa") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_plus.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_plus.groovy index 7a31c28d18a433..45271415b98ef5 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_plus.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_gb_mv_plus.groovy @@ -50,26 +50,14 @@ suite ("dup_gb_mv_plus") { order_qt_select_star "select * from dup_gb_mv_plus order by k1;" - explain { - sql("select k1,sum(k2+1) from dup_gb_mv_plus group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select k1,sum(k2+1) from dup_gb_mv_plus group by k1;", "k12sp") order_qt_select_mv "select k1,sum(k2+1) from dup_gb_mv_plus group by k1 order by k1;" - explain { - sql("select sum(k2+1) from dup_gb_mv_plus group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select sum(k2+1) from dup_gb_mv_plus group by k1;", "k12sp") order_qt_select_mv_sub "select sum(k2+1) from dup_gb_mv_plus group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,sum(k2+1) from dup_gb_mv_plus group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select k1,sum(k2+1) from dup_gb_mv_plus group by k1;", "k12sp") - explain { - sql("select sum(k2+1) from dup_gb_mv_plus group by k1;") - contains "(k12sp)" - } + mv_rewrite_success("select sum(k2+1) from dup_gb_mv_plus group by k1;", "k12sp") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_abs.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_abs.groovy index 67cc5d5efa7867..c4770d6dcd0262 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_abs.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_abs.groovy @@ -50,70 +50,34 @@ suite ("dup_mv_abs") { order_qt_select_star "select * from dup_mv_abs order by k1;" - explain { - sql("select k1,abs(k2) from dup_mv_abs order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select k1,abs(k2) from dup_mv_abs order by k1;", "k12a") order_qt_select_mv "select k1,abs(k2) from dup_mv_abs order by k1;" - explain { - sql("select abs(k2) from dup_mv_abs order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select abs(k2) from dup_mv_abs order by k1;", "k12a") order_qt_select_mv_sub "select abs(k2) from dup_mv_abs order by k1;" - explain { - sql("select abs(k2)+1 from dup_mv_abs order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select abs(k2)+1 from dup_mv_abs order by k1;", "k12a") order_qt_select_mv_sub_add "select abs(k2)+1 from dup_mv_abs order by k1;" - explain { - sql("select sum(abs(k2)) from dup_mv_abs group by k1 order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select sum(abs(k2)) from dup_mv_abs group by k1 order by k1;", "k12a") order_qt_select_group_mv "select sum(abs(k2)) from dup_mv_abs group by k1 order by k1;" - explain { - sql("select sum(abs(k2)+1) from dup_mv_abs group by k1 order by k1;") - contains "(k12a)" - } + mv_rewrite_success("select sum(abs(k2)+1) from dup_mv_abs group by k1 order by k1;", "k12a") order_qt_select_group_mv_add "select sum(abs(k2)+1) from dup_mv_abs group by k1 order by k1;" - explain { - sql("select sum(abs(k2)) from dup_mv_abs group by k3;") - contains "(dup_mv_abs)" - } + mv_rewrite_fail("select sum(abs(k2)) from dup_mv_abs group by k3;", "k12a") order_qt_select_group_mv_not "select sum(abs(k2)) from dup_mv_abs group by k3 order by k3;" sql """set enable_stats=true;""" - explain { - sql("select k1,abs(k2) from dup_mv_abs order by k1;") - contains "(k12a)" - } - - explain { - sql("select abs(k2) from dup_mv_abs order by k1;") - contains "(k12a)" - } - - explain { - sql("select abs(k2)+1 from dup_mv_abs order by k1;") - contains "(k12a)" - } - - explain { - sql("select sum(abs(k2)) from dup_mv_abs group by k1 order by k1;") - contains "(k12a)" - } - - explain { - sql("select sum(abs(k2)+1) from dup_mv_abs group by k1 order by k1;") - contains "(k12a)" - } - - explain { - sql("select sum(abs(k2)) from dup_mv_abs group by k3;") - contains "(dup_mv_abs)" - } + mv_rewrite_success("select k1,abs(k2) from dup_mv_abs order by k1;", "k12a") + + mv_rewrite_success("select abs(k2) from dup_mv_abs order by k1;", "k12a") + + mv_rewrite_success("select abs(k2)+1 from dup_mv_abs order by k1;", "k12a") + + mv_rewrite_success("select sum(abs(k2)) from dup_mv_abs group by k1 order by k1;", "k12a") + + mv_rewrite_success("select sum(abs(k2)+1) from dup_mv_abs group by k1 order by k1;", "k12a") + + mv_rewrite_fail("select sum(abs(k2)) from dup_mv_abs group by k3;", "k12a") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bin.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bin.groovy index 2b9c46a0374e13..788647ae224d98 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bin.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bin.groovy @@ -50,70 +50,34 @@ suite ("dup_mv_bin") { order_qt_select_star "select * from dup_mv_bin order by k1;" - explain { - sql("select k1,bin(k2) from dup_mv_bin order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select k1,bin(k2) from dup_mv_bin order by k1;", "k12b") order_qt_select_mv "select k1,bin(k2) from dup_mv_bin order by k1;" - explain { - sql("select bin(k2) from dup_mv_bin order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select bin(k2) from dup_mv_bin order by k1;", "k12b") order_qt_select_mv_sub "select bin(k2) from dup_mv_bin order by k1;" - explain { - sql("select bin(k2)+1 from dup_mv_bin order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select bin(k2)+1 from dup_mv_bin order by k1;", "k12b") order_qt_select_mv_sub_add "select concat(bin(k2),'a') from dup_mv_bin order by k1;" - explain { - sql("select group_concat(bin(k2)) from dup_mv_bin group by k1 order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select group_concat(bin(k2)) from dup_mv_bin group by k1 order by k1;", "k12b") order_qt_select_group_mv "select group_concat(bin(k2)) from dup_mv_bin group by k1 order by k1;" - explain { - sql("select group_concat(concat(bin(k2),'a')) from dup_mv_bin group by k1 order by k1;") - contains "(k12b)" - } + mv_rewrite_success("select group_concat(concat(bin(k2),'a')) from dup_mv_bin group by k1 order by k1;", "k12b") order_qt_select_group_mv_add "select group_concat(concat(bin(k2),'a')) from dup_mv_bin group by k1 order by k1;" - explain { - sql("select group_concat(bin(k2)) from dup_mv_bin group by k3;") - contains "(dup_mv_bin)" - } + mv_rewrite_fail("select group_concat(bin(k2)) from dup_mv_bin group by k3;", "k12b") order_qt_select_group_mv_not "select group_concat(bin(k2)) from dup_mv_bin group by k3 order by k3;" sql """set enable_stats=true;""" - explain { - sql("select k1,bin(k2) from dup_mv_bin order by k1;") - contains "(k12b)" - } - - explain { - sql("select bin(k2) from dup_mv_bin order by k1;") - contains "(k12b)" - } - - explain { - sql("select bin(k2)+1 from dup_mv_bin order by k1;") - contains "(k12b)" - } - - explain { - sql("select group_concat(bin(k2)) from dup_mv_bin group by k1 order by k1;") - contains "(k12b)" - } - - explain { - sql("select group_concat(concat(bin(k2),'a')) from dup_mv_bin group by k1 order by k1;") - contains "(k12b)" - } - - explain { - sql("select group_concat(bin(k2)) from dup_mv_bin group by k3;") - contains "(dup_mv_bin)" - } + mv_rewrite_success("select k1,bin(k2) from dup_mv_bin order by k1;", "k12b") + + mv_rewrite_success("select bin(k2) from dup_mv_bin order by k1;", "k12b") + + mv_rewrite_success("select bin(k2)+1 from dup_mv_bin order by k1;", "k12b") + + mv_rewrite_success("select group_concat(bin(k2)) from dup_mv_bin group by k1 order by k1;", "k12b") + + mv_rewrite_success("select group_concat(concat(bin(k2),'a')) from dup_mv_bin group by k1 order by k1;", "k12b") + + mv_rewrite_fail("select group_concat(bin(k2)) from dup_mv_bin group by k3;", "k12b") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bm_hash.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bm_hash.groovy index 585338ef8dd151..d049a0aeb7c1b0 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bm_hash.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_bm_hash.groovy @@ -41,17 +41,11 @@ suite ("dup_mv_bm_hash") { sql "analyze table dup_mv_bm_hash with sync;" sql """set enable_stats=false;""" - explain { - sql("select bitmap_union_count(to_bitmap(k2)) from dup_mv_bm_hash group by k1 order by k1;") - contains "(dup_mv_bm_hash_mv1)" - } + mv_rewrite_success("select bitmap_union_count(to_bitmap(k2)) from dup_mv_bm_hash group by k1 order by k1;", "dup_mv_bm_hash_mv1") order_qt_select_mv "select bitmap_union_count(to_bitmap(k2)) from dup_mv_bm_hash group by k1 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select bitmap_union_count(to_bitmap(k2)) from dup_mv_bm_hash group by k1 order by k1;") - contains "(dup_mv_bm_hash_mv1)" - } + mv_rewrite_success("select bitmap_union_count(to_bitmap(k2)) from dup_mv_bm_hash group by k1 order by k1;", "dup_mv_bm_hash_mv1") createMV("create materialized view dup_mv_bm_hash_mv2 as select k1,bitmap_union(bitmap_hash(k3)) from dup_mv_bm_hash group by k1;") @@ -62,15 +56,9 @@ suite ("dup_mv_bm_hash") { order_qt_select_star "select * from dup_mv_bm_hash order by k1,k2,k3;" - explain { - sql("select k1,bitmap_union_count(bitmap_hash(k3)) from dup_mv_bm_hash group by k1;") - contains "(dup_mv_bm_hash_mv2)" - } + mv_rewrite_success("select k1,bitmap_union_count(bitmap_hash(k3)) from dup_mv_bm_hash group by k1;", "dup_mv_bm_hash_mv2") order_qt_select_mv_sub "select k1,bitmap_union_count(bitmap_hash(k3)) from dup_mv_bm_hash group by k1 order by k1;" sql """set enable_stats=false;""" - explain { - sql("select k1,bitmap_union_count(bitmap_hash(k3)) from dup_mv_bm_hash group by k1;") - contains "(dup_mv_bm_hash_mv2)" - } + mv_rewrite_success("select k1,bitmap_union_count(bitmap_hash(k3)) from dup_mv_bm_hash group by k1;", "dup_mv_bm_hash_mv2") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_plus.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_plus.groovy index abcdc9c4c0062c..b661e75ad967ab 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_plus.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_plus.groovy @@ -49,16 +49,10 @@ suite ("dup_mv_plus") { order_qt_select_star "select * from dup_mv_plus order by k1;" - explain { - sql("select k1,k2+1 from dup_mv_plus order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select k1,k2+1 from dup_mv_plus order by k1;", "k12p") order_qt_select_mv "select k1,k2+1 from dup_mv_plus order by k1;" - explain { - sql("select k2+1 from dup_mv_plus order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select k2+1 from dup_mv_plus order by k1;", "k12p") order_qt_select_mv_sub "select k2+1 from dup_mv_plus order by k1;" /* @@ -71,16 +65,10 @@ suite ("dup_mv_plus") { qt_select_mv_sub_add "select k2+1-1 from dup_mv_plus order by k1;" */ - explain { - sql("select sum(k2+1) from dup_mv_plus group by k1 order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k2+1) from dup_mv_plus group by k1 order by k1;", "k12p") order_qt_select_group_mv "select sum(k2+1) from dup_mv_plus group by k1 order by k1;" - explain { - sql("select sum(k1) from dup_mv_plus group by k2+1 order by k2+1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k1) from dup_mv_plus group by k2+1 order by k2+1;", "k12p") order_qt_select_group_mv "select sum(k1) from dup_mv_plus group by k2+1 order by k2+1;" /* @@ -91,47 +79,23 @@ suite ("dup_mv_plus") { qt_select_group_mv_add "select sum(k2+1-1) from dup_mv_plus group by k1 order by k1;" */ - explain { - sql("select sum(k2) from dup_mv_plus group by k3;") - contains "(dup_mv_plus)" - } + mv_rewrite_fail("select sum(k2) from dup_mv_plus group by k3;", "k12p") order_qt_select_group_mv_not "select sum(k2) from dup_mv_plus group by k3 order by k3;" - explain { - sql("select k1,k2+1 from dup_mv_plus order by k2;") - contains "(dup_mv_plus)" - } + mv_rewrite_fail("select k1,k2+1 from dup_mv_plus order by k2;", "k12p") order_qt_select_mv "select k1,k2+1 from dup_mv_plus order by k2;" sql """set enable_stats=true;""" - explain { - sql("select k1,k2+1 from dup_mv_plus order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select k1,k2+1 from dup_mv_plus order by k1;", "k12p") - explain { - sql("select k2+1 from dup_mv_plus order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select k2+1 from dup_mv_plus order by k1;", "k12p") - explain { - sql("select sum(k2+1) from dup_mv_plus group by k1 order by k1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k2+1) from dup_mv_plus group by k1 order by k1;", "k12p") - explain { - sql("select sum(k1) from dup_mv_plus group by k2+1 order by k2+1;") - contains "(k12p)" - } + mv_rewrite_success("select sum(k1) from dup_mv_plus group by k2+1 order by k2+1;", "k12p") - explain { - sql("select sum(k2) from dup_mv_plus group by k3;") - contains "(dup_mv_plus)" - } + mv_rewrite_success("select sum(k2+1) from dup_mv_plus group by k1 order by k1;", "k12p") - explain { - sql("select k1,k2+1 from dup_mv_plus order by k2;") - contains "(dup_mv_plus)" - } + mv_rewrite_success("select sum(k1) from dup_mv_plus group by k2+1 order by k2+1;", "k12p") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_year.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_year.groovy index d99b11187f1708..c5098c55074c7d 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_year.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/dup_mv_year.groovy @@ -41,17 +41,11 @@ suite ("dup_mv_year") { sql """set enable_stats=false;""" - explain { - sql("select k1,year(k2) from dup_mv_year order by k1;") - contains "(k12y)" - } + mv_rewrite_success("select k1,year(k2) from dup_mv_year order by k1;", "k12y") order_qt_select_mv "select k1,year(k2) from dup_mv_year order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,year(k2) from dup_mv_year order by k1;") - contains "(k12y)" - } + mv_rewrite_success("select k1,year(k2) from dup_mv_year order by k1;", "k12y") createMV "create materialized view k13y as select k1,year(k3) from dup_mv_year;" @@ -60,15 +54,9 @@ suite ("dup_mv_year") { order_qt_select_star "select * from dup_mv_year order by k1;" - explain { - sql("select year(k3) from dup_mv_year order by k1;") - contains "(k13y)" - } + mv_rewrite_success("select year(k3) from dup_mv_year order by k1;", "k13y") order_qt_select_mv_sub "select year(k3) from dup_mv_year order by k1;" sql """set enable_stats=false;""" - explain { - sql("select year(k3) from dup_mv_year order by k1;") - contains "(k13y)" - } + mv_rewrite_success("select year(k3) from dup_mv_year order by k1;", "k13y") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot1.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot1.groovy index 75251670bb54a0..7e317d501bea07 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot1.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot1.groovy @@ -48,15 +48,9 @@ suite ("multi_slot1") { order_qt_select_star "select * from multi_slot1 order by k1;" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot1 order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot1 order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") order_qt_select_mv "select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot1 order by abs(k1)+k2+1,abs(k2+2)+k3+3;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot1 order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot1 order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot2.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot2.groovy index 9b731b8297c54b..6bbded534a77ee 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot2.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot2.groovy @@ -57,26 +57,17 @@ suite ("multi_slot2") { order_qt_select_star "select * from multi_slot2 order by k1;" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2+1 order by abs(k1)+k2+1") - contains "(k1a2p2ap3ps)" - } + mv_rewrite_success("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2+1 order by abs(k1)+k2+1", + "k1a2p2ap3ps") order_qt_select_mv "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2+1 order by abs(k1)+k2+1;" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2 order by abs(k1)+k2") - contains "(multi_slot2)" - } + mv_rewrite_fail("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2 order by abs(k1)+k2", "k1a2p2ap3ps") order_qt_select_base "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2 order by abs(k1)+k2;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2+1 order by abs(k1)+k2+1") - contains "(k1a2p2ap3ps)" - } + mv_rewrite_success("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2+1 order by abs(k1)+k2+1", + "k1a2p2ap3ps") + + mv_rewrite_fail("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2 order by abs(k1)+k2", "k1a2p2ap3ps") - explain { - sql("select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot2 group by abs(k1)+k2 order by abs(k1)+k2") - contains "(multi_slot2)" - } } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot3.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot3.groovy index b8828621da0e01..c6016296e8b352 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot3.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot3.groovy @@ -49,15 +49,9 @@ suite ("multi_slot3") { order_qt_select_star "select * from multi_slot3 order by k1;" - explain { - sql("select k1+1,abs(k2+2)+k3+3 from multi_slot3 order by k1+1;") - contains "(k1p2ap3p)" - } + mv_rewrite_success("select k1+1,abs(k2+2)+k3+3 from multi_slot3 order by k1+1;", "k1p2ap3p") order_qt_select_mv "select k1+1,abs(k2+2)+k3+3 from multi_slot3 order by k1+1;" sql """set enable_stats=true;""" - explain { - sql("select k1+1,abs(k2+2)+k3+3 from multi_slot3 order by k1+1;") - contains "(k1p2ap3p)" - } + mv_rewrite_success("select k1+1,abs(k2+2)+k3+3 from multi_slot3 order by k1+1;", "k1p2ap3p") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot4.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot4.groovy index 44b0b8a9ce7fe1..a09f3937aee302 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot4.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot4.groovy @@ -52,15 +52,9 @@ suite ("multi_slot4") { order_qt_select_star "select * from multi_slot4 order by k1;" - explain { - sql("select k1+1,sum(abs(k2+2)+k3+3) from multi_slot4 group by k1+1 order by k1+1;") - contains "(k1p2ap3ps)" - } + mv_rewrite_success("select k1+1,sum(abs(k2+2)+k3+3) from multi_slot4 group by k1+1 order by k1+1;", "k1p2ap3ps") order_qt_select_mv "select k1+1,sum(abs(k2+2)+k3+3) from multi_slot4 group by k1+1 order by k1+1;" sql """set enable_stats=true;""" - explain { - sql("select k1+1,sum(abs(k2+2)+k3+3) from multi_slot4 group by k1+1 order by k1+1;") - contains "(k1p2ap3ps)" - } + mv_rewrite_success("select k1+1,sum(abs(k2+2)+k3+3) from multi_slot4 group by k1+1 order by k1+1;", "k1p2ap3ps") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot5.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot5.groovy index b4430fe58d2ce6..55ea991913cb3e 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot5.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot5.groovy @@ -50,10 +50,7 @@ suite ("multi_slot5") { order_qt_select_star "select * from multi_slot5 order by k1,k4;" - explain { - sql("select k1,k2+k3 from multi_slot5 order by k1;") - contains "(k123p)" - } + mv_rewrite_success("select k1,k2+k3 from multi_slot5 order by k1;", "k123p") order_qt_select_mv "select k1,k2+k3 from multi_slot5 order by k1;" order_qt_select_mv "select lhs.k1,rhs.k2 from multi_slot5 as lhs right join multi_slot5 as rhs on lhs.k1=rhs.k1 order by lhs.k1;" @@ -61,8 +58,5 @@ suite ("multi_slot5") { order_qt_select_mv "select k1,version() from multi_slot5 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select k1,k2+k3 from multi_slot5 order by k1;") - contains "(k123p)" - } + mv_rewrite_success("select k1,k2+k3 from multi_slot5 order by k1;", "k123p") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot6.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot6.groovy index afc1bafdf567f5..9201a1cea4d321 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot6.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/multi_slot6.groovy @@ -80,15 +80,9 @@ suite ("multi_slot6") { } order_qt_select_mv "select abs(k1)+k2+1,sum(abs(k2+2)+k3+3) from multi_slot6 group by abs(k1)+k2+1 order by abs(k1)+k2+1;" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot6 order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot6 order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") order_qt_select_mv "select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot6 order by abs(k1)+k2+1,abs(k2+2)+k3+3;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot6 order by abs(k1)+k2+1,abs(k2+2)+k3+3") - contains "(k1a2p2ap3p)" - } + mv_rewrite_success("select abs(k1)+k2+1,abs(k2+2)+k3+3 from multi_slot6 order by abs(k1)+k2+1,abs(k2+2)+k3+3", "k1a2p2ap3p") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/mv_with_view.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/mv_with_view.groovy index c48c770cfba8e2..236bde3bf6c828 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/mv_with_view.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/mv_with_view.groovy @@ -43,10 +43,7 @@ suite ("mv_with_view") { sql "analyze table d_table with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from d_table order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from d_table order by k1;", "k312") qt_select_star "select * from d_table order by k1;" sql """ @@ -56,10 +53,7 @@ suite ("mv_with_view") { sql """ create view v_k312 as select k1,k3,k2 from d_table where k3 = 1; """ - explain { - sql("select * from v_k312 order by k1;") - contains "(k312)" - } + mv_rewrite_success("select * from v_k312 order by k1;", "k312") qt_select_mv "select * from v_k312 order by k1;" sql """ @@ -69,17 +63,11 @@ suite ("mv_with_view") { sql """ create view v_k124 as select k1,k2,k4 from d_table where k1 = 1; """ - explain { - sql("select * from v_k124 order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from v_k124 order by k1;", "k312") qt_select_mv "select * from v_k124 order by k1;" sql """set enable_stats=true;""" - explain { - sql("select * from d_table order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from d_table order by k1;", "k312") sql """ drop view if exists v_k312; @@ -88,10 +76,7 @@ suite ("mv_with_view") { sql """ create view v_k312 as select k1,k3,k2 from d_table where k3 = 1; """ - explain { - sql("select * from v_k312 order by k1;") - contains "(k312)" - } + mv_rewrite_success("select * from v_k312 order by k1;", "k312") sql """ drop view if exists v_k124; @@ -100,8 +85,5 @@ suite ("mv_with_view") { sql """ create view v_k124 as select k1,k2,k4 from d_table where k1 = 1; """ - explain { - sql("select * from v_k124 order by k1;") - contains "(d_table)" - } + mv_rewrite_fail("select * from v_k124 order by k1;", "k312") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/single_slot.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/single_slot.groovy index 955151165fca9e..d6cd0d5a24421a 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/single_slot.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/single_slot.groovy @@ -54,11 +54,9 @@ suite ("single_slot") { sql("select abs(k1)+1 t,sum(abs(k2+1)) from single_slot group by t order by t;") contains "(k1ap2spa)" } + mv_rewrite_success("select abs(k1)+1 t,sum(abs(k2+1)) from single_slot group by t order by t;", "k1ap2spa") order_qt_select_mv "select abs(k1)+1 t,sum(abs(k2+1)) from single_slot group by t order by t;" sql """set enable_stats=true;""" - explain { - sql("select abs(k1)+1 t,sum(abs(k2+1)) from single_slot group by t order by t;") - contains "(k1ap2spa)" - } + mv_rewrite_success("select abs(k1)+1 t,sum(abs(k2+1)) from single_slot group by t order by t;", "k1ap2spa") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/sum_devide_count.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/sum_devide_count.groovy index 2a44305c6aeb8c..031560a41ef502 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/sum_devide_count.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/sum_devide_count.groovy @@ -49,49 +49,25 @@ suite ("sum_devide_count") { qt_select_star "select * from sum_devide_count order by k1,k2,k3,k4;" - explain { - sql("select k1,k4,sum(k2)/count(k2) from sum_devide_count group by k1,k4 order by k1,k4;") - contains "(kavg)" - } + mv_rewrite_success("select k1,k4,sum(k2)/count(k2) from sum_devide_count group by k1,k4 order by k1,k4;", "kavg") order_qt_select_mv "select k1,k4,sum(k2)/count(k2) from sum_devide_count group by k1,k4 order by k1,k4;" - explain { - sql("select k1,sum(k2)/count(k2) from sum_devide_count group by k1 order by k1;") - contains "(kavg)" - } + mv_rewrite_success("select k1,sum(k2)/count(k2) from sum_devide_count group by k1 order by k1;", "kavg") order_qt_select_mv "select k1,sum(k2)/count(k2) from sum_devide_count group by k1 order by k1;" - explain { - sql("select k4,sum(k2)/count(k2) from sum_devide_count group by k4 order by k4;") - contains "(kavg)" - } + mv_rewrite_success("select k4,sum(k2)/count(k2) from sum_devide_count group by k4 order by k4;", "kavg") order_qt_select_mv "select k4,sum(k2)/count(k2) from sum_devide_count group by k4 order by k4;" - explain { - sql("select sum(k2)/count(k2) from sum_devide_count;") - contains "(kavg)" - } + mv_rewrite_success("select sum(k2)/count(k2) from sum_devide_count;", "kavg") order_qt_select_mv "select sum(k2)/count(k2) from sum_devide_count;" sql """set enable_stats=true;""" - explain { - sql("select k1,k4,sum(k2)/count(k2) from sum_devide_count group by k1,k4 order by k1,k4;") - contains "(kavg)" - } - - explain { - sql("select k1,sum(k2)/count(k2) from sum_devide_count group by k1 order by k1;") - contains "(kavg)" - } - - explain { - sql("select k4,sum(k2)/count(k2) from sum_devide_count group by k4 order by k4;") - contains "(kavg)" - } - - explain { - sql("select sum(k2)/count(k2) from sum_devide_count;") - contains "(kavg)" - } + mv_rewrite_success("select k1,k4,sum(k2)/count(k2) from sum_devide_count group by k1,k4 order by k1,k4;", "kavg") + + mv_rewrite_success("select k1,sum(k2)/count(k2) from sum_devide_count group by k1 order by k1;", "kavg") + + mv_rewrite_success("select k4,sum(k2)/count(k2) from sum_devide_count group by k4 order by k4;", "kavg") + + mv_rewrite_success("select sum(k2)/count(k2) from sum_devide_count;", "kavg") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy index 92f07c3011b0b6..df390b26551054 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy @@ -44,14 +44,9 @@ suite ("unique_mv") { sql "analyze table c5816_t with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT * FROM c5816_t WHERE call_uuid='adc';") - contains "(mv_1)" - } + mv_rewrite_success("SELECT * FROM c5816_t WHERE call_uuid='adc';", "mv_1") sql """set enable_stats=true;""" - explain { - sql("SELECT * FROM c5816_t WHERE call_uuid='adc';") - contains "(mv_1)" - } + mv_rewrite_success("SELECT * FROM c5816_t WHERE call_uuid='adc';", "mv_1") + } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/MVMultiUsage.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/MVMultiUsage.groovy index 4b80669275708d..9a5e42034be3cb 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/MVMultiUsage.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/MVMultiUsage.groovy @@ -46,10 +46,7 @@ suite ("MVMultiUsage") { sql "analyze table MVMultiUsage with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from MVMultiUsage order by empid;") - contains "(MVMultiUsage)" - } + mv_rewrite_fail("select * from MVMultiUsage order by empid;", "MVMultiUsage_mv") order_qt_select_star "select * from MVMultiUsage order by empid;" @@ -61,10 +58,7 @@ suite ("MVMultiUsage") { order_qt_select_mv "select * from (select deptno, empid from MVMultiUsage where deptno>100) A join (select deptno, empid from MVMultiUsage where deptno >200) B using (deptno) order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from MVMultiUsage order by empid;") - contains "(MVMultiUsage)" - } + mv_rewrite_fail("select * from MVMultiUsage order by empid;", "MVMultiUsage_mv") explain { sql("select * from (select deptno, empid from MVMultiUsage where deptno>100) A join (select deptno, empid from MVMultiUsage where deptno >200) B using (deptno);") contains "(MVMultiUsage_mv)" diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/MVWithAs.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/MVWithAs.groovy index a73f06c62a3ed6..246c97022e9e85 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/MVWithAs.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/MVWithAs.groovy @@ -31,6 +31,10 @@ suite ("MVWithAs") { """ sql """insert into MVWithAs values("2020-01-01",1,"a",1);""" + sql """insert into MVWithAs values("2020-01-01",1,"a",1);""" + sql """insert into MVWithAs values("2020-01-01",1,"a",1);""" + sql """insert into MVWithAs values("2020-01-02",2,"b",2);""" + sql """insert into MVWithAs values("2020-01-02",2,"b",2);""" sql """insert into MVWithAs values("2020-01-02",2,"b",2);""" createMV("create materialized view MVWithAs_mv as select user_id, count(tag_id) from MVWithAs group by user_id;") @@ -42,25 +46,14 @@ suite ("MVWithAs") { sql "analyze table MVWithAs with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from MVWithAs order by time_col;") - contains "(MVWithAs)" - } + mv_rewrite_fail("select * from MVWithAs order by time_col;", "MVWithAs_mv") order_qt_select_star "select * from MVWithAs order by time_col;" - explain { - sql("select count(tag_id) from MVWithAs t;") - contains "(MVWithAs_mv)" - } + mv_rewrite_success("select count(tag_id) from MVWithAs t;", "MVWithAs_mv") order_qt_select_mv "select count(tag_id) from MVWithAs t;" sql """set enable_stats=true;""" - explain { - sql("select * from MVWithAs order by time_col;") - contains "(MVWithAs)" - } - explain { - sql("select count(tag_id) from MVWithAs t;") - contains "(MVWithAs_mv)" - } + mv_rewrite_fail("select * from MVWithAs order by time_col;", "MVWithAs_mv") + + mv_rewrite_success("select count(tag_id) from MVWithAs t;", "MVWithAs_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggMVCalcAggFun.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggMVCalcAggFun.groovy index 4abfc3ce21c09e..1a7ccd851503d8 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggMVCalcAggFun.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggMVCalcAggFun.groovy @@ -48,26 +48,14 @@ suite ("aggMVCalcAggFun") { sql "analyze table aggMVCalcAggFun with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggMVCalcAggFun order by empid;") - contains "(aggMVCalcAggFun)" - } + mv_rewrite_fail("select * from aggMVCalcAggFun order by empid;", "aggMVCalcAggFunMv") order_qt_select_star "select * from aggMVCalcAggFun order by empid;" - - explain { - sql("select deptno, sum(salary + 1) from aggMVCalcAggFun where deptno > 10 group by deptno;") - notContains "(aggMVCalcAggFunMv)" - } + mv_rewrite_fail("select deptno, sum(salary + 1) from aggMVCalcAggFun where deptno > 10 group by deptno;", "aggMVCalcAggFunMv") order_qt_select_mv "select deptno, sum(salary + 1) from aggMVCalcAggFun where deptno > 10 group by deptno order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from aggMVCalcAggFun order by empid;") - contains "(aggMVCalcAggFun)" - } - explain { - sql("select deptno, sum(salary + 1) from aggMVCalcAggFun where deptno > 10 group by deptno;") - notContains "(aggMVCalcAggFunMv)" - } + mv_rewrite_fail("select * from aggMVCalcAggFun order by empid;", "aggMVCalcAggFunMv")\ + + mv_rewrite_fail("select deptno, sum(salary + 1) from aggMVCalcAggFun where deptno > 10 group by deptno;", "aggMVCalcAggFunMv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV1.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV1.groovy index a7261c18446908..0cb12cbcde0b51 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV1.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV1.groovy @@ -47,27 +47,14 @@ suite ("aggOnAggMV1") { sql "analyze table aggOnAggMV1 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV1 order by empid;") - contains "(aggOnAggMV1)" - } + mv_rewrite_fail("select * from aggOnAggMV1 order by empid;", "aggOnAggMV1_mv") order_qt_select_star "select * from aggOnAggMV1 order by empid;" - - explain { - sql("select sum(salary), deptno from aggOnAggMV1 group by deptno order by deptno;") - contains "(aggOnAggMV1_mv)" - } + mv_rewrite_success("select sum(salary), deptno from aggOnAggMV1 group by deptno order by deptno;", "aggOnAggMV1_mv") order_qt_select_mv "select sum(salary), deptno from aggOnAggMV1 group by deptno order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV1 order by empid;") - contains "(aggOnAggMV1)" - } - explain { - sql("select sum(salary), deptno from aggOnAggMV1 group by deptno order by deptno;") - contains "(aggOnAggMV1_mv)" - } + mv_rewrite_fail("select * from aggOnAggMV1 order by empid;", "aggOnAggMV1_mv") + mv_rewrite_success("select sum(salary), deptno from aggOnAggMV1 group by deptno order by deptno;", "aggOnAggMV1_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV10.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV10.groovy index cba0fdce39a9d7..bd826537ff88f7 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV10.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV10.groovy @@ -46,26 +46,16 @@ suite ("aggOnAggMV10") { sql "analyze table aggOnAggMV10 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV10 order by empid;") - contains "(aggOnAggMV10)" - } + mv_rewrite_fail("select * from aggOnAggMV10 order by empid;", "aggOnAggMV10_mv") order_qt_select_star "select * from aggOnAggMV10 order by empid;" - explain { - sql("select deptno, commission, sum(salary) + 1 from aggOnAggMV10 group by rollup (deptno, commission);") - contains "(aggOnAggMV10_mv)" - } + mv_rewrite_success("select deptno, commission, sum(salary) + 1 from aggOnAggMV10 group by rollup (deptno, commission);", + "aggOnAggMV10_mv") order_qt_select_mv "select deptno, commission, sum(salary) + 1 from aggOnAggMV10 group by rollup (deptno, commission) order by 1,2;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV10 order by empid;") - contains "(aggOnAggMV10)" - } + mv_rewrite_fail("select * from aggOnAggMV10 order by empid;", "aggOnAggMV10_mv") - explain { - sql("select deptno, commission, sum(salary) + 1 from aggOnAggMV10 group by rollup (deptno, commission);") - contains "(aggOnAggMV10_mv)" - } + mv_rewrite_success("select deptno, commission, sum(salary) + 1 from aggOnAggMV10 group by rollup (deptno, commission);", + "aggOnAggMV10_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV11.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV11.groovy index a8984f56327acd..793389ec68e4ae 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV11.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV11.groovy @@ -46,26 +46,16 @@ suite ("aggOnAggMV11") { sql "analyze table aggOnAggMV11 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV11 order by empid;") - contains "(aggOnAggMV11)" - } + mv_rewrite_fail("select * from aggOnAggMV11 order by empid;", "aggOnAggMV11_mv") order_qt_select_star "select * from aggOnAggMV11 order by empid;" - explain { - sql("select deptno, count(salary) + count(1) from aggOnAggMV11 group by deptno;") - contains "(aggOnAggMV11)" - } + mv_rewrite_fail("select deptno, count(salary) + count(1) from aggOnAggMV11 group by deptno;", + "aggOnAggMV11_mv") order_qt_select_mv "select deptno, count(salary) + count(1) from aggOnAggMV11 group by deptno order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV11 order by empid;") - contains "(aggOnAggMV11)" - } + mv_rewrite_fail("select * from aggOnAggMV11 order by empid;", "aggOnAggMV11_mv") - explain { - sql("select deptno, count(salary) + count(1) from aggOnAggMV11 group by deptno;") - contains "(aggOnAggMV11)" - } + mv_rewrite_fail("select deptno, count(salary) + count(1) from aggOnAggMV11 group by deptno;", + "aggOnAggMV11_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV2.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV2.groovy index 61287da9ba1ce2..32d897939ea652 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV2.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV2.groovy @@ -48,26 +48,15 @@ suite ("aggOnAggMV2") { sql "analyze table aggOnAggMV2 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV2 order by empid;") - contains "(aggOnAggMV2)" - } + mv_rewrite_fail("select * from aggOnAggMV2 order by empid;", "aggOnAggMV2_mv") order_qt_select_star "select * from aggOnAggMV2 order by empid, salary;" - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV2 group by deptno) a where (sum_salary * 2) > 3 order by deptno ;") - contains "(aggOnAggMV2_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV2 group by deptno) a where (sum_salary * 2) > 3 order by deptno ;", "aggOnAggMV2_mv") + order_qt_select_mv "select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV2 group by deptno) a where (sum_salary * 2) > 3 order by deptno ;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV2 order by empid;") - contains "(aggOnAggMV2)" - } - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV2 group by deptno) a where (sum_salary * 2) > 3 order by deptno ;") - contains "(aggOnAggMV2_mv)" - } + mv_rewrite_fail("select * from aggOnAggMV2 order by empid;", "aggOnAggMV2_mv") + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV2 group by deptno) a where (sum_salary * 2) > 3 order by deptno ;", "aggOnAggMV2_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV3.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV3.groovy index f4a6df2dbd7b2b..dfd0ce3e67503c 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV3.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV3.groovy @@ -48,28 +48,16 @@ suite ("aggOnAggMV3") { sql "analyze table aggOnAggMV3 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV3 order by empid;") - contains "(aggOnAggMV3)" - } + mv_rewrite_fail("select * from aggOnAggMV3 order by empid;", "aggOnAggMV3_mv") order_qt_select_star "select * from aggOnAggMV3 order by empid;" - - explain { - sql("select commission, sum(salary) from aggOnAggMV3 where commission * (deptno + commission) = 100 group by commission order by commission;") - contains "(aggOnAggMV3_mv)" - } + mv_rewrite_success("select commission, sum(salary) from aggOnAggMV3 where commission * (deptno + commission) = 100 group by commission order by commission;", + "aggOnAggMV3_mv") order_qt_select_mv "select commission, sum(salary) from aggOnAggMV3 where commission * (deptno + commission) = 100 group by commission order by commission;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV3 order by empid;") - contains "(aggOnAggMV3)" - } - - explain { - sql("select commission, sum(salary) from aggOnAggMV3 where commission * (deptno + commission) = 100 group by commission order by commission;") - contains "(aggOnAggMV3_mv)" - } + mv_rewrite_fail("select * from aggOnAggMV3 order by empid;", "aggOnAggMV3_mv") + mv_rewrite_success("select commission, sum(salary) from aggOnAggMV3 where commission * (deptno + commission) = 100 group by commission order by commission;", + "aggOnAggMV3_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV5.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV5.groovy index 868f6e8c31ece0..481d8f19b5a133 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV5.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV5.groovy @@ -43,7 +43,7 @@ suite ("aggOnAggMV5") { sql "analyze table aggOnAggMV5 with sync;" - mv_rewrite_all_fail("select * from aggOnAggMV5 order by empid;") + mv_rewrite_fail("select * from aggOnAggMV5 order by empid;", "aggOnAggMV5_mv") order_qt_select_star "select * from aggOnAggMV5 order by empid;" diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV6.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV6.groovy index c96f045fb796d1..abd66e1ab13ccd 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV6.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV6.groovy @@ -46,26 +46,16 @@ suite ("aggOnAggMV6") { sql "analyze table aggOnAggMV6 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV6 order by empid;") - contains "(aggOnAggMV6)" - } + mv_rewrite_fail("select * from aggOnAggMV6 order by empid;", "aggOnAggMV6_mv") order_qt_select_star "select * from aggOnAggMV6 order by empid;" - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV6 where deptno>=20 group by deptno) a where sum_salary>10;") - contains "(aggOnAggMV6_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV6 where deptno>=20 group by deptno) a where sum_salary>10;", + "aggOnAggMV6_mv") order_qt_select_mv "select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV6 where deptno>=20 group by deptno) a where sum_salary>10 order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV6 order by empid;") - contains "(aggOnAggMV6)" - } + mv_rewrite_fail("select * from aggOnAggMV6 order by empid;", "aggOnAggMV6_mv") - explain { - sql("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV6 where deptno>=20 group by deptno) a where sum_salary>10;") - contains "(aggOnAggMV6_mv)" - } + mv_rewrite_success("select * from (select deptno, sum(salary) as sum_salary from aggOnAggMV6 where deptno>=20 group by deptno) a where sum_salary>10;", + "aggOnAggMV6_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV7.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV7.groovy index 453ce4fc2d5b92..53b75d03d85167 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV7.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/aggOnAggMV7.groovy @@ -46,26 +46,16 @@ suite ("aggOnAggMV7") { sql "analyze table aggOnAggMV7 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from aggOnAggMV7 order by empid;") - contains "(aggOnAggMV7)" - } + mv_rewrite_fail("select * from aggOnAggMV7 order by empid;", "aggOnAggMV7_mv") order_qt_select_star "select * from aggOnAggMV7 order by empid;" - explain { - sql("select deptno, sum(salary) from aggOnAggMV7 where deptno>=20 group by deptno;") - contains "(aggOnAggMV7_mv)" - } + mv_rewrite_success("select deptno, sum(salary) from aggOnAggMV7 where deptno>=20 group by deptno;", + "aggOnAggMV7_mv") order_qt_select_mv "select deptno, sum(salary) from aggOnAggMV7 where deptno>=20 group by deptno order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from aggOnAggMV7 order by empid;") - contains "(aggOnAggMV7)" - } + mv_rewrite_fail("select * from aggOnAggMV7 order by empid;", "aggOnAggMV7_mv") - explain { - sql("select deptno, sum(salary) from aggOnAggMV7 where deptno>=20 group by deptno;") - contains "(aggOnAggMV7_mv)" - } + mv_rewrite_success("select deptno, sum(salary) from aggOnAggMV7 where deptno>=20 group by deptno;", + "aggOnAggMV7_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/bitmapUnionIn.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/bitmapUnionIn.groovy index 3f5070673a419c..13e2097cdb46ba 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/bitmapUnionIn.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/bitmapUnionIn.groovy @@ -42,26 +42,16 @@ suite ("bitmapUnionIn") { sql "analyze table bitmapUnionIn with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from bitmapUnionIn order by time_col;") - contains "(bitmapUnionIn)" - } + mv_rewrite_fail("select * from bitmapUnionIn order by time_col;", "bitmapUnionIn_mv") order_qt_select_star "select * from bitmapUnionIn order by time_col,tag_id;" - explain { - sql("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from bitmapUnionIn group by user_id having a>1 order by a;") - contains "(bitmapUnionIn_mv)" - } + mv_rewrite_success("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from bitmapUnionIn group by user_id having a>1 order by a;", + "bitmapUnionIn_mv") order_qt_select_mv "select user_id, bitmap_union_count(to_bitmap(tag_id)) a from bitmapUnionIn group by user_id having a>1 order by a;" sql """set enable_stats=true;""" - explain { - sql("select * from bitmapUnionIn order by time_col;") - contains "(bitmapUnionIn)" - } + mv_rewrite_fail("select * from bitmapUnionIn order by time_col;", "bitmapUnionIn_mv") - explain { - sql("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from bitmapUnionIn group by user_id having a>1 order by a;") - contains "(bitmapUnionIn_mv)" - } + mv_rewrite_success("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from bitmapUnionIn group by user_id having a>1 order by a;", + "bitmapUnionIn_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/incMVReInSub.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/incMVReInSub.groovy index 2dabe312cbe29e..c28dac1d227aab 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/incMVReInSub.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/incMVReInSub.groovy @@ -43,26 +43,17 @@ suite ("incMVReInSub") { sql "analyze table incMVReInSub with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from incMVReInSub order by time_col;") - contains "(incMVReInSub)" - } + mv_rewrite_fail("select * from incMVReInSub order by time_col;", "incMVReInSub_mv") order_qt_select_star "select * from incMVReInSub order by time_col, user_id, user_name, tag_id;" - explain { - sql("select user_id, bitmap_union(to_bitmap(tag_id)) from incMVReInSub where user_name in (select user_name from incMVReInSub group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;") - contains "(incMVReInSub)" - } + mv_rewrite_fail("select user_id, bitmap_union(to_bitmap(tag_id)) from incMVReInSub where user_name in (select user_name from incMVReInSub group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;", + "incMVReInSub_mv") + order_qt_select_mv "select user_id, bitmap_union(to_bitmap(tag_id)) from incMVReInSub where user_name in (select user_name from incMVReInSub group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;" sql """set enable_stats=true;""" - explain { - sql("select * from incMVReInSub order by time_col;") - contains "(incMVReInSub)" - } + mv_rewrite_fail("select * from incMVReInSub order by time_col;", "incMVReInSub_mv") - explain { - sql("select user_id, bitmap_union(to_bitmap(tag_id)) from incMVReInSub where user_name in (select user_name from incMVReInSub group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;") - contains "(incMVReInSub)" - } + mv_rewrite_fail("select user_id, bitmap_union(to_bitmap(tag_id)) from incMVReInSub where user_name in (select user_name from incMVReInSub group by user_name having bitmap_union_count(to_bitmap(tag_id)) >1 ) group by user_id order by user_id;", + "incMVReInSub_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/incRewriteCD.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/incRewriteCD.groovy index 74a20f9efbf999..ee8e688c0e7313 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/incRewriteCD.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/incRewriteCD.groovy @@ -43,26 +43,14 @@ suite ("incRewriteCD") { sql "analyze table incRewriteCD with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from incRewriteCD order by time_col;") - contains "(incRewriteCD)" - } + mv_rewrite_fail("select * from incRewriteCD order by time_col;", "incRewriteCD_mv") order_qt_select_star "select * from incRewriteCD order by time_col,tag_id;" - explain { - sql("select user_name, count(distinct tag_id) from incRewriteCD group by user_name;") - contains "(incRewriteCD)" - } + mv_rewrite_fail("select user_name, count(distinct tag_id) from incRewriteCD group by user_name;", "incRewriteCD_mv") order_qt_select_mv "select user_name, count(distinct tag_id) from incRewriteCD group by user_name order by user_name;" sql """set enable_stats=true;""" - explain { - sql("select * from incRewriteCD order by time_col;") - contains "(incRewriteCD)" - } + mv_rewrite_fail("select * from incRewriteCD order by time_col;", "incRewriteCD_mv") - explain { - sql("select user_name, count(distinct tag_id) from incRewriteCD group by user_name;") - contains "(incRewriteCD)" - } + mv_rewrite_fail("select user_name, count(distinct tag_id) from incRewriteCD group by user_name;", "incRewriteCD_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnCalcToJoin.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnCalcToJoin.groovy index ea7f8a6ab5bca5..8ed3e09bdf0df3 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnCalcToJoin.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnCalcToJoin.groovy @@ -58,16 +58,10 @@ suite ("joinOnCalcToJoin") { sql "analyze table joinOnCalcToJoin_1 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from (select empid, deptno from joinOnCalcToJoin where empid = 0) A join (select deptno, cost from joinOnCalcToJoin_1 where deptno > 0) B on A.deptno = B.deptno;") - contains "(joinOnLeftPToJoin_mv)" - contains "(joinOnLeftPToJoin_1_mv)" - } + mv_rewrite_all_success("select * from (select empid, deptno from joinOnCalcToJoin where empid = 0) A join (select deptno, cost from joinOnCalcToJoin_1 where deptno > 0) B on A.deptno = B.deptno;", + ["joinOnLeftPToJoin_mv", "joinOnLeftPToJoin_1_mv"]) sql """set enable_stats=true;""" - explain { - sql("select * from (select empid, deptno from joinOnCalcToJoin where empid = 0) A join (select deptno, cost from joinOnCalcToJoin_1 where deptno > 0) B on A.deptno = B.deptno;") - contains "(joinOnLeftPToJoin_mv)" - contains "(joinOnLeftPToJoin_1_mv)" - } + mv_rewrite_all_success("select * from (select empid, deptno from joinOnCalcToJoin where empid = 0) A join (select deptno, cost from joinOnCalcToJoin_1 where deptno > 0) B on A.deptno = B.deptno;", + ["joinOnLeftPToJoin_mv", "joinOnLeftPToJoin_1_mv"]) } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnLeftPToJoin.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnLeftPToJoin.groovy index 97e4ceba5a0c7a..f2f7a014d98fc8 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnLeftPToJoin.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/joinOnLeftPToJoin.groovy @@ -58,17 +58,12 @@ suite ("joinOnLeftPToJoin") { sql "analyze table joinOnLeftPToJoin_1 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from (select deptno , sum(salary) from joinOnLeftPToJoin group by deptno) A join (select deptno, max(cost) from joinOnLeftPToJoin_1 group by deptno ) B on A.deptno = B.deptno;") - contains "(joinOnLeftPToJoin_mv)" - contains "(joinOnLeftPToJoin_1_mv)" - } + mv_rewrite_all_success("select * from (select deptno , sum(salary) from joinOnLeftPToJoin group by deptno) A join (select deptno, max(cost) from joinOnLeftPToJoin_1 group by deptno ) B on A.deptno = B.deptno;", + ["joinOnLeftPToJoin_mv", "joinOnLeftPToJoin_1_mv"]) + order_qt_select_mv "select * from (select deptno , sum(salary) from joinOnLeftPToJoin group by deptno) A join (select deptno, max(cost) from joinOnLeftPToJoin_1 group by deptno ) B on A.deptno = B.deptno order by A.deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from (select deptno , sum(salary) from joinOnLeftPToJoin group by deptno) A join (select deptno, max(cost) from joinOnLeftPToJoin_1 group by deptno ) B on A.deptno = B.deptno;") - contains "(joinOnLeftPToJoin_mv)" - contains "(joinOnLeftPToJoin_1_mv)" - } + mv_rewrite_all_success("select * from (select deptno , sum(salary) from joinOnLeftPToJoin group by deptno) A join (select deptno, max(cost) from joinOnLeftPToJoin_1 group by deptno ) B on A.deptno = B.deptno;", + ["joinOnLeftPToJoin_mv", "joinOnLeftPToJoin_1_mv"]) } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/onlyGroupBy.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/onlyGroupBy.groovy index 1f11ed5dd53e44..698f4ae13f328d 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/onlyGroupBy.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/onlyGroupBy.groovy @@ -44,14 +44,8 @@ suite ("onlyGroupBy") { sql "analyze table onlyGroupBy with sync;" sql """set enable_stats=false;""" - explain { - sql("select deptno from onlyGroupBy group by deptno;") - contains "(onlyGroupBy_mv)" - } + mv_rewrite_success("select deptno from onlyGroupBy group by deptno;", "onlyGroupBy_mv") sql """set enable_stats=true;""" - explain { - sql("select deptno from onlyGroupBy group by deptno;") - contains "(onlyGroupBy_mv)" - } + mv_rewrite_success("select deptno from onlyGroupBy group by deptno;", "onlyGroupBy_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/orderByOnPView.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/orderByOnPView.groovy index ed86c1ad6efa3a..7f455da429e6c3 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/orderByOnPView.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/orderByOnPView.groovy @@ -47,26 +47,14 @@ suite ("orderByOnPView") { sql "analyze table orderByOnPView with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from orderByOnPView where time_col='2020-01-01' order by empid;") - contains "(orderByOnPView)" - } + mv_rewrite_fail("select * from orderByOnPView where time_col='2020-01-01' order by empid;", "orderByOnPView_mv") order_qt_select_star "select * from orderByOnPView order by empid;" - - explain { - sql("select empid from orderByOnPView where deptno = 0 order by deptno;") - contains "(orderByOnPView_mv)" - } + mv_rewrite_success("select empid from orderByOnPView where deptno = 0 order by deptno;", "orderByOnPView_mv") order_qt_select_mv "select empid from orderByOnPView order by deptno;" sql """set enable_stats=true;""" - explain { - sql("select * from orderByOnPView where time_col='2020-01-01' order by empid;") - contains "(orderByOnPView)" - } - explain { - sql("select empid from orderByOnPView where deptno = 0 order by deptno;") - contains "(orderByOnPView_mv)" - } + mv_rewrite_fail("select * from orderByOnPView where time_col='2020-01-01' order by empid;", "orderByOnPView_mv") + + mv_rewrite_success("select empid from orderByOnPView where deptno = 0 order by deptno;", "orderByOnPView_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV1.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV1.groovy index 5dc9cb3223791e..384137471d827f 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV1.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV1.groovy @@ -45,27 +45,14 @@ suite ("projectMV1") { sql "analyze table projectMV1 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from projectMV1 where time_col='2020-01-01' order by empid;") - contains "(projectMV1)" - } + mv_rewrite_fail("select * from projectMV1 where time_col='2020-01-01' order by empid;", "projectMV1_mv") order_qt_select_star "select * from projectMV1 order by empid;" - - explain { - sql("select empid, deptno from projectMV1 where deptno=0 order by empid;") - contains "(projectMV1_mv)" - } + mv_rewrite_success("select empid, deptno from projectMV1 where deptno=0 order by empid;", "projectMV1_mv") order_qt_select_mv "select empid, deptno from projectMV1 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from projectMV1 where time_col='2020-01-01' order by empid;") - contains "(projectMV1)" - } + mv_rewrite_fail("select * from projectMV1 where time_col='2020-01-01' order by empid;", "projectMV1_mv") - explain { - sql("select empid, deptno from projectMV1 where deptno=0 order by empid;") - contains "(projectMV1_mv)" - } + mv_rewrite_success("select empid, deptno from projectMV1 where deptno=0 order by empid;", "projectMV1_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV2.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV2.groovy index 256b8e37a0c041..672bda198b01aa 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV2.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV2.groovy @@ -45,38 +45,19 @@ suite ("projectMV2") { sql "analyze table projectMV2 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from projectMV2 order by empid;") - contains "(projectMV2)" - } + mv_rewrite_fail("select * from projectMV2 order by empid;", "projectMV2_mv") order_qt_select_star "select * from projectMV2 order by empid;" - - explain { - sql("select empid + 1 from projectMV2 where deptno = 1 order by empid;") - contains "(projectMV2_mv)" - } + mv_rewrite_success("select empid + 1 from projectMV2 where deptno = 1 order by empid;", "projectMV2_mv") order_qt_select_mv "select empid + 1 from projectMV2 where deptno = 1 order by empid;" - explain { - sql("select name from projectMV2 where deptno -1 = 0 order by empid;") - contains "(projectMV2)" - } + mv_rewrite_fail("select name from projectMV2 where deptno -1 = 0 order by empid;", "projectMV2_mv") order_qt_select_base "select name from projectMV2 where deptno -1 = 0 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from projectMV2 order by empid;") - contains "(projectMV2)" - } + mv_rewrite_fail("select * from projectMV2 order by empid;", "projectMV2_mv") - explain { - sql("select empid + 1 from projectMV2 where deptno = 1 order by empid;") - contains "(projectMV2_mv)" - } + mv_rewrite_success("select empid + 1 from projectMV2 where deptno = 1 order by empid;", "projectMV2_mv") - explain { - sql("select name from projectMV2 where deptno -1 = 0 order by empid;") - contains "(projectMV2)" - } + mv_rewrite_fail("select name from projectMV2 where deptno -1 = 0 order by empid;", "projectMV2_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV3.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV3.groovy index c8ac65194e8be4..37b73a9a81aff4 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV3.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV3.groovy @@ -47,37 +47,19 @@ suite ("projectMV3") { sql "analyze table projectMV3 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from projectMV3 order by empid;") - contains "(projectMV3)" - } + mv_rewrite_fail("select * from projectMV3 order by empid;", "projectMV3_mv") order_qt_select_star "select * from projectMV3 order by empid;" - - explain { - sql("select empid + 1, name from projectMV3 where deptno = 1 order by empid;") - contains "(projectMV3_mv)" - } + mv_rewrite_success("select empid + 1, name from projectMV3 where deptno = 1 order by empid;", "projectMV3_mv") order_qt_select_mv "select empid + 1, name from projectMV3 where deptno = 1 order by empid;" - explain { - sql("select name from projectMV3 where deptno = 0 order by empid;") - contains "(projectMV3_mv)" - } + mv_rewrite_success("select name from projectMV3 where deptno = 0 order by empid;", "projectMV3_mv") order_qt_select_mv2 "select name from projectMV3 where deptno -1 = 0 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from projectMV3 order by empid;") - contains "(projectMV3)" - } + mv_rewrite_fail("select * from projectMV3 order by empid;", "projectMV3_mv") + + mv_rewrite_success("select empid + 1, name from projectMV3 where deptno = 1 order by empid;", "projectMV3_mv") - explain { - sql("select empid + 1, name from projectMV3 where deptno = 1 order by empid;") - contains "(projectMV3_mv)" - } - explain { - sql("select name from projectMV3 where deptno = 0 order by empid;") - contains "(projectMV3_mv)" - } + mv_rewrite_success("select name from projectMV3 where deptno = 0 order by empid;", "projectMV3_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV4.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV4.groovy index f9f4db11b1da58..ea87551dfa1249 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV4.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/projectMV4.groovy @@ -47,38 +47,19 @@ suite ("projectMV4") { sql "analyze table projectMV4 with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from projectMV4 order by empid;") - contains "(projectMV4)" - } + mv_rewrite_fail("select * from projectMV4 order by empid;", "projectMV4_mv") order_qt_select_star "select * from projectMV4 order by empid;" - - explain { - sql("select name from projectMV4 where deptno > 1 and salary > 1 and name = 'a' order by name;") - contains "(projectMV4_mv)" - } + mv_rewrite_success("select name from projectMV4 where deptno > 1 and salary > 1 and name = 'a' order by name;", "projectMV4_mv") order_qt_select_mv "select name from projectMV4 where deptno > 1 and salary > 1 order by name;" - explain { - sql("select empid from projectMV4 where deptno > 1 and empid > 1 and time_col = '2020-01-01' order by empid;") - contains "(projectMV4)" - } + mv_rewrite_fail("select empid from projectMV4 where deptno > 1 and empid > 1 and time_col = '2020-01-01' order by empid;", "projectMV4_mv") order_qt_select_base "select empid from projectMV4 where deptno > 1 and empid > 1 order by empid;" sql """set enable_stats=true;""" - explain { - sql("select * from projectMV4 order by empid;") - contains "(projectMV4)" - } + mv_rewrite_fail("select * from projectMV4 order by empid;", "projectMV4_mv") - explain { - sql("select name from projectMV4 where deptno > 1 and salary > 1 and name = 'a' order by name;") - contains "(projectMV4_mv)" - } + mv_rewrite_success("select name from projectMV4 where deptno > 1 and salary > 1 and name = 'a' order by name;", "projectMV4_mv") - explain { - sql("select empid from projectMV4 where deptno > 1 and empid > 1 and time_col = '2020-01-01' order by empid;") - contains "(projectMV4)" - } + mv_rewrite_fail("select empid from projectMV4 where deptno > 1 and empid > 1 and time_col = '2020-01-01' order by empid;", "projectMV4_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/subQuery.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/subQuery.groovy index 76c50398e38aac..25300c9d602681 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/subQuery.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/subQuery.groovy @@ -47,10 +47,7 @@ suite ("subQuery") { sql "analyze table subQuery with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from subQuery order by empid;") - contains "(subQuery)" - } + mv_rewrite_fail("select * from subQuery order by empid;", "subQuery_mv") order_qt_select_star "select * from subQuery order by empid;" /* @@ -64,8 +61,5 @@ suite ("subQuery") { sql """set enable_stats=true;""" - explain { - sql("select * from subQuery order by empid;") - contains "(subQuery)" - } + mv_rewrite_fail("select * from subQuery order by empid;", "subQuery_mv") } diff --git a/regression-test/suites/nereids_syntax_p0/mv/ut/unionDis.groovy b/regression-test/suites/nereids_syntax_p0/mv/ut/unionDis.groovy index 8b36da10c121f6..0f57b5c6c1687e 100644 --- a/regression-test/suites/nereids_syntax_p0/mv/ut/unionDis.groovy +++ b/regression-test/suites/nereids_syntax_p0/mv/ut/unionDis.groovy @@ -46,10 +46,7 @@ suite ("unionDis") { sql "analyze table unionDis with sync;" sql """set enable_stats=false;""" - explain { - sql("select * from unionDis order by empid;") - contains "(unionDis)" - } + mv_rewrite_fail("select * from unionDis order by empid;", "unionDis_mv") order_qt_select_star "select * from unionDis order by empid;" @@ -61,15 +58,11 @@ suite ("unionDis") { order_qt_select_mv "select * from (select empid, deptno from unionDis where empid >1 union select empid, deptno from unionDis where empid <0) t order by 1;" sql """set enable_stats=true;""" - explain { - sql("select * from unionDis order by empid;") - contains "(unionDis)" - } + mv_rewrite_fail("select * from unionDis order by empid;", "unionDis_mv") explain { sql("select empid, deptno from unionDis where empid >1 union select empid, deptno from unionDis where empid <0 order by empid;") contains "(unionDis_mv)" notContains "(unionDis)" } - } diff --git a/regression-test/suites/nereids_syntax_p0/rollup/agg.groovy b/regression-test/suites/nereids_syntax_p0/rollup/agg.groovy index 6a213a85458314..0f682cacd8be96 100644 --- a/regression-test/suites/nereids_syntax_p0/rollup/agg.groovy +++ b/regression-test/suites/nereids_syntax_p0/rollup/agg.groovy @@ -76,16 +76,11 @@ suite("agg") { sql "analyze table ${tbName} with sync;" sql """set enable_stats=false;""" - - explain { - sql("SELECT citycode,SUM(pv) FROM ${tbName} GROUP BY citycode") - contains("(rollup_city)") - } + + mv_rewrite_success("SELECT citycode,SUM(pv) FROM ${tbName} GROUP BY citycode", "rollup_city") sql """set enable_stats=true;""" - explain { - sql("SELECT citycode,SUM(pv) FROM ${tbName} GROUP BY citycode") - contains("(rollup_city)") - } + mv_rewrite_success("SELECT citycode,SUM(pv) FROM ${tbName} GROUP BY citycode", "rollup_city") + qt_sql "SELECT citycode,SUM(pv) FROM ${tbName} GROUP BY citycode" sql "ALTER TABLE ${tbName} DROP ROLLUP rollup_city;" sql "DROP TABLE ${tbName} FORCE;" diff --git a/regression-test/suites/nereids_syntax_p0/rollup/agg_date.groovy b/regression-test/suites/nereids_syntax_p0/rollup/agg_date.groovy index 0cb949f0721d48..b711728f769129 100644 --- a/regression-test/suites/nereids_syntax_p0/rollup/agg_date.groovy +++ b/regression-test/suites/nereids_syntax_p0/rollup/agg_date.groovy @@ -85,15 +85,11 @@ suite("agg_date", "rollup") { sql "analyze table ${tbName} with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT datek1,datetimek1,datetimek2,datetimek3,max(datev1),max(datetimev1),max(datetimev2),max(datetimev3) FROM ${tbName} GROUP BY datek1,datetimek1,datetimek2,datetimek3") - contains("(rollup_date)") - } + mv_rewrite_success("SELECT datek1,datetimek1,datetimek2,datetimek3,max(datev1),max(datetimev1),max(datetimev2),max(datetimev3) FROM ${tbName} GROUP BY datek1,datetimek1,datetimek2,datetimek3", + "rollup_date") sql """set enable_stats=true;""" - explain { - sql("SELECT datek1,datetimek1,datetimek2,datetimek3,max(datev1),max(datetimev1),max(datetimev2),max(datetimev3) FROM ${tbName} GROUP BY datek1,datetimek1,datetimek2,datetimek3") - contains("(rollup_date)") - } + mv_rewrite_success("SELECT datek1,datetimek1,datetimek2,datetimek3,max(datev1),max(datetimev1),max(datetimev2),max(datetimev3) FROM ${tbName} GROUP BY datek1,datetimek1,datetimek2,datetimek3", + "rollup_date") qt_sql """ SELECT datek1,datetimek1,datetimek2,datetimek3,max(datev1),max(datetimev1),max(datetimev2),max(datetimev3) FROM ${tbName} GROUP BY datek1,datetimek1,datetimek2,datetimek3 order by datek1 desc; """ sql "ALTER TABLE ${tbName} DROP ROLLUP rollup_date;" diff --git a/regression-test/suites/nereids_syntax_p0/rollup/date.groovy b/regression-test/suites/nereids_syntax_p0/rollup/date.groovy index c91c219c5f9669..1415a442952ab6 100644 --- a/regression-test/suites/nereids_syntax_p0/rollup/date.groovy +++ b/regression-test/suites/nereids_syntax_p0/rollup/date.groovy @@ -53,39 +53,21 @@ suite("date", "rollup") { sql "analyze table ${tbName1} with sync;" sql """set enable_stats=false;""" - explain{ - sql("SELECT store_id, max(sale_date1) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max1)") - } - explain{ - sql("SELECT store_id, max(sale_datetime1) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max2)") - } - explain{ - sql("SELECT store_id, max(sale_datetime2) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max3)") - } - explain{ - sql("SELECT store_id, max(sale_datetime3) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max4)") - } + mv_rewrite_success("SELECT store_id, max(sale_date1) FROM ${tbName1} GROUP BY store_id", "amt_max1") + + mv_rewrite_success("SELECT store_id, max(sale_datetime1) FROM ${tbName1} GROUP BY store_id", "amt_max2") + + mv_rewrite_success("SELECT store_id, max(sale_datetime2) FROM ${tbName1} GROUP BY store_id", "amt_max3") + + mv_rewrite_success("SELECT store_id, max(sale_datetime3) FROM ${tbName1} GROUP BY store_id", "amt_max4") sql """set enable_stats=true;""" - explain{ - sql("SELECT store_id, max(sale_date1) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max1)") - } - explain{ - sql("SELECT store_id, max(sale_datetime1) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max2)") - } - explain{ - sql("SELECT store_id, max(sale_datetime2) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max3)") - } - explain{ - sql("SELECT store_id, max(sale_datetime3) FROM ${tbName1} GROUP BY store_id") - contains("(amt_max4)") - } + mv_rewrite_success("SELECT store_id, max(sale_date1) FROM ${tbName1} GROUP BY store_id", "amt_max1") + + mv_rewrite_success("SELECT store_id, max(sale_datetime1) FROM ${tbName1} GROUP BY store_id", "amt_max2") + + mv_rewrite_success("SELECT store_id, max(sale_datetime2) FROM ${tbName1} GROUP BY store_id", "amt_max3") + + mv_rewrite_success("SELECT store_id, max(sale_datetime3) FROM ${tbName1} GROUP BY store_id", "amt_max4") qt_sql """ SELECT store_id, max(sale_date1) FROM ${tbName1} GROUP BY store_id """ qt_sql """ SELECT store_id, max(sale_datetime1) FROM ${tbName1} GROUP BY store_id """ diff --git a/regression-test/suites/nereids_syntax_p0/rollup/hll/hll.groovy b/regression-test/suites/nereids_syntax_p0/rollup/hll/hll.groovy index 4f0b6a21f9994e..2ba3540832945a 100644 --- a/regression-test/suites/nereids_syntax_p0/rollup/hll/hll.groovy +++ b/regression-test/suites/nereids_syntax_p0/rollup/hll/hll.groovy @@ -42,10 +42,10 @@ suite("hll", "rollup") { sql("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll1 GROUP BY store_id;") contains "(amt_count)" } + mv_rewrite_success("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll1 GROUP BY store_id;", + "amt_count") sql """set enable_stats=true;""" - explain { - sql("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll1 GROUP BY store_id;") - contains "(amt_count)" - } + mv_rewrite_success("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll1 GROUP BY store_id;", + "amt_count") } diff --git a/regression-test/suites/nereids_syntax_p0/rollup/hll_with_light_sc/hll_with_light_sc.groovy b/regression-test/suites/nereids_syntax_p0/rollup/hll_with_light_sc/hll_with_light_sc.groovy index cfc9e8501321c4..51599f294d1e62 100644 --- a/regression-test/suites/nereids_syntax_p0/rollup/hll_with_light_sc/hll_with_light_sc.groovy +++ b/regression-test/suites/nereids_syntax_p0/rollup/hll_with_light_sc/hll_with_light_sc.groovy @@ -39,14 +39,10 @@ suite("hll_with_light_sc", "rollup") { sql "analyze table test_materialized_view_hll_with_light_sc1 with sync;" sql """set enable_stats=false;""" - explain { - sql("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll_with_light_sc1 GROUP BY store_id;") - contains "(amt_count1)" - } + mv_rewrite_success("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll_with_light_sc1 GROUP BY store_id;", + "amt_count1") sql """set enable_stats=true;""" - explain { - sql("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll_with_light_sc1 GROUP BY store_id;") - contains "(amt_count1)" - } + mv_rewrite_success("SELECT store_id, hll_union_agg(hll_hash(sale_amt)) FROM test_materialized_view_hll_with_light_sc1 GROUP BY store_id;", + "amt_count1") } diff --git a/regression-test/suites/nereids_syntax_p1/mv/aggregate/agg_sync_mv.groovy b/regression-test/suites/nereids_syntax_p1/mv/aggregate/agg_sync_mv.groovy index c79d9f96ddf8c4..361ff9cc39981b 100644 --- a/regression-test/suites/nereids_syntax_p1/mv/aggregate/agg_sync_mv.groovy +++ b/regression-test/suites/nereids_syntax_p1/mv/aggregate/agg_sync_mv.groovy @@ -25,10 +25,7 @@ suite("agg_sync_mv") { qt_select_any_value """select id, any_value(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync1 on agg_mv_test;""" createMV("""create materialized view mv_sync1 as select id, any_value(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, any_value(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync1)" - } + mv_rewrite_success("select id, any_value(kint) from agg_mv_test group by id order by id;", "mv_sync1") qt_select_any_value_mv """select id, any_value(kint) from agg_mv_test group by id order by id;""" // sum_foreach is not supported in old planner @@ -44,308 +41,207 @@ suite("agg_sync_mv") { qt_select_approx_count_distinct """select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync3 on agg_mv_test;""" createMV("""create materialized view mv_sync3 as select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync3)" - } + mv_rewrite_success("select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;", "mv_sync3") qt_select_approx_count_distinct_mv """select id, approx_count_distinct(kint) from agg_mv_test group by id order by id;""" qt_select_collect_set """select id, collect_set(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync4 on agg_mv_test;""" createMV("""create materialized view mv_sync4 as select id, collect_set(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, collect_set(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync4)" - } + mv_rewrite_success("select id, collect_set(kint) from agg_mv_test group by id order by id;", "mv_sync4") qt_select_collect_set_mv """select id, collect_set(kint) from agg_mv_test group by id order by id;""" qt_select_collect_list """select id, collect_list(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync5 on agg_mv_test;""" createMV("""create materialized view mv_sync5 as select id, collect_list(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, collect_list(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync5)" - } + mv_rewrite_success("select id, collect_list(kint) from agg_mv_test group by id order by id;", "mv_sync5") qt_select_collect_list_mv """select id, collect_list(kint) from agg_mv_test group by id order by id;""" qt_select_corr """select id, corr(kint, kbint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync6 on agg_mv_test;""" createMV("""create materialized view mv_sync6 as select id, corr(kint, kbint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, corr(kint, kbint) from agg_mv_test group by id order by id;") - contains "(mv_sync6)" - } + mv_rewrite_success("select id, corr(kint, kbint) from agg_mv_test group by id order by id;", "mv_sync6") qt_select_corr_mv """select id, corr(kint, kbint) from agg_mv_test group by id order by id;""" qt_select_percentile_array """select id, percentile_array(kint, [0.5,0.55,0.805]) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync7 on agg_mv_test;""" createMV("""create materialized view mv_sync7 as select id, percentile_array(kint, [0.5,0.55,0.805]) from agg_mv_test group by id order by id;""") - explain { - sql("select id, percentile_array(kint, [0.5,0.55,0.805]) from agg_mv_test group by id order by id;") - contains "(mv_sync7)" - } + mv_rewrite_success("select id, percentile_array(kint, [0.5,0.55,0.805]) from agg_mv_test group by id order by id;", "mv_sync7") qt_select_percentile_array_mv """select id, percentile_array(kint, [0.5,0.55,0.805]) from agg_mv_test group by id order by id;""" qt_select_quantile_union """select id, quantile_union(to_quantile_state(kbint, 2048)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync8 on agg_mv_test;""" createMV("""create materialized view mv_sync8 as select id, quantile_union(to_quantile_state(kbint, 2048)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, quantile_union(to_quantile_state(kbint, 2048)) from agg_mv_test group by id order by id;") - contains "(mv_sync8)" - } + mv_rewrite_success("select id, quantile_union(to_quantile_state(kbint, 2048)) from agg_mv_test group by id order by id;", + "mv_sync8") qt_select_quantile_union_mv """select id, quantile_union(to_quantile_state(kbint, 2048)) from agg_mv_test group by id order by id;""" qt_select_count_by_enum """select id, count_by_enum(kstr) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync9 on agg_mv_test;""" createMV("""create materialized view mv_sync9 as select id, count_by_enum(kstr) from agg_mv_test group by id order by id;""") - explain { - sql("select id, count_by_enum(kstr) from agg_mv_test group by id order by id;") - contains "(mv_sync9)" - } + mv_rewrite_success("select id, count_by_enum(kstr) from agg_mv_test group by id order by id;", "mv_sync9") qt_select_count_by_enum_mv """select id, count_by_enum(kstr) from agg_mv_test group by id order by id;""" qt_select_avg_weighted """select id, avg_weighted(ktint, kdbl) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync10 on agg_mv_test;""" createMV("""create materialized view mv_sync10 as select id, avg_weighted(ktint, kdbl) from agg_mv_test group by id order by id;""") - explain { - sql("select id, avg_weighted(ktint, kdbl) from agg_mv_test group by id order by id;") - contains "(mv_sync10)" - } + mv_rewrite_success("select id, avg_weighted(ktint, kdbl) from agg_mv_test group by id order by id;", "mv_sync10") qt_select_avg_weighted_mv """select id, avg_weighted(ktint, kdbl) from agg_mv_test group by id order by id;""" qt_select_bitmap_intersect """select id, bitmap_intersect(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync11 on agg_mv_test;""" createMV("""create materialized view mv_sync11 as select id, bitmap_intersect(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, bitmap_intersect(bitmap_hash(kbint)) from agg_mv_test group by id order by id;") - contains "(mv_sync11)" - } + mv_rewrite_success("select id, bitmap_intersect(bitmap_hash(kbint)) from agg_mv_test group by id order by id;", "mv_sync11") qt_select_bitmap_intersect_mv """select id, bitmap_intersect(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" qt_select_bitmap_agg """select id, bitmap_agg(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync12 on agg_mv_test;""" createMV("""create materialized view mv_sync12 as select id, bitmap_agg(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, bitmap_agg(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync12)" - } + mv_rewrite_success("select id, bitmap_agg(kint) from agg_mv_test group by id order by id;", "mv_sync12") qt_select_bitmap_agg_mv """select id, bitmap_agg(kint) from agg_mv_test group by id order by id;""" qt_select_bitmap_union """select id, bitmap_union(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync13 on agg_mv_test;""" createMV("""create materialized view mv_sync13 as select id, bitmap_union(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, bitmap_union(bitmap_hash(kbint)) from agg_mv_test group by id order by id;") - contains "(mv_sync13)" - } + mv_rewrite_success("select id, bitmap_union(bitmap_hash(kbint)) from agg_mv_test group by id order by id;", "mv_sync13") qt_select_bitmap_union_mv """select id, bitmap_union(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" qt_select_bitmap_union_count """select id, bitmap_union_count(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync14 on agg_mv_test;""" createMV("""create materialized view mv_sync14 as select id, bitmap_union_count(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, bitmap_union_count(bitmap_hash(kbint)) from agg_mv_test group by id order by id;") - contains "(mv_sync14)" - } + mv_rewrite_success("select id, bitmap_union_count(bitmap_hash(kbint)) from agg_mv_test group by id order by id;", "mv_sync14") qt_select_bitmap_union_count_mv """select id, bitmap_union_count(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" qt_select_bitmap_union_int """select id, bitmap_union_int(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync15 on agg_mv_test;""" createMV("""create materialized view mv_sync15 as select id, bitmap_union_int(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, bitmap_union_int(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync15)" - } + mv_rewrite_success("select id, bitmap_union_int(kint) from agg_mv_test group by id order by id;", "mv_sync15") qt_select_bitmap_union_int_mv """select id, bitmap_union_int(kint) from agg_mv_test group by id order by id;""" qt_select_group_array_intersect """select id, group_array_intersect(kaint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync16 on agg_mv_test;""" createMV("""create materialized view mv_sync16 as select id, group_array_intersect(kaint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, group_array_intersect(kaint) from agg_mv_test group by id order by id;") - contains "(mv_sync16)" - } + mv_rewrite_success("select id, group_array_intersect(kaint) from agg_mv_test group by id order by id;", "mv_sync16") qt_select_group_array_intersect_mv """select id, group_array_intersect(kaint) from agg_mv_test group by id order by id;""" qt_select_group_bit_and """select id, group_bit_and(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync17 on agg_mv_test;""" createMV("""create materialized view mv_sync17 as select id, group_bit_and(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, group_bit_and(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync17)" - } + mv_rewrite_success("select id, group_bit_and(kint) from agg_mv_test group by id order by id;", "mv_sync17") qt_select_group_bit_and_mv """select id, group_bit_and(kint) from agg_mv_test group by id order by id;""" qt_select_group_bit_or """select id, group_bit_or(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync18 on agg_mv_test;""" createMV("""create materialized view mv_sync18 as select id, group_bit_or(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, group_bit_or(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync18)" - } + mv_rewrite_success("select id, group_bit_or(kint) from agg_mv_test group by id order by id;", "mv_sync18") qt_select_group_bit_or_mv """select id, group_bit_or(kint) from agg_mv_test group by id order by id;""" qt_select_group_bit_xor """select id, group_bit_xor(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync19 on agg_mv_test;""" createMV("""create materialized view mv_sync19 as select id, group_bit_xor(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, group_bit_xor(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync19)" - } + mv_rewrite_success("select id, group_bit_xor(kint) from agg_mv_test group by id order by id;", "mv_sync19") qt_select_group_bit_xor_mv """select id, group_bit_xor(kint) from agg_mv_test group by id order by id;""" qt_select_group_bitmap_xor """select id, group_bitmap_xor(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync20 on agg_mv_test;""" createMV("""create materialized view mv_sync20 as select id, group_bitmap_xor(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, group_bitmap_xor(bitmap_hash(kbint)) from agg_mv_test group by id order by id;") - contains "(mv_sync20)" - } + mv_rewrite_success("select id, group_bitmap_xor(bitmap_hash(kbint)) from agg_mv_test group by id order by id;", "mv_sync20") qt_select_group_bitmap_xor_mv """select id, group_bitmap_xor(bitmap_hash(kbint)) from agg_mv_test group by id order by id;""" qt_select_hll_union_agg """select id, hll_union_agg(hll_hash(kbint)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync21 on agg_mv_test;""" createMV("""create materialized view mv_sync21 as select id, hll_union_agg(hll_hash(kbint)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, hll_union_agg(hll_hash(kbint)) from agg_mv_test group by id order by id;") - contains "(mv_sync21)" - } + mv_rewrite_success("select id, hll_union_agg(hll_hash(kbint)) from agg_mv_test group by id order by id;", "mv_sync21") qt_select_hll_union_agg_mv """select id, hll_union_agg(hll_hash(kbint)) from agg_mv_test group by id order by id;""" qt_select_hll_union """select id, hll_union(hll_hash(kbint)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync22 on agg_mv_test;""" createMV("""create materialized view mv_sync22 as select id, hll_union(hll_hash(kbint)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, hll_union(hll_hash(kbint)) from agg_mv_test group by id order by id;") - contains "(mv_sync22)" - } + mv_rewrite_success("select id, hll_union(hll_hash(kbint)) from agg_mv_test group by id order by id;", "mv_sync22") qt_select_hll_union_mv """select id, hll_union(hll_hash(kbint)) from agg_mv_test group by id order by id;""" qt_select_intersect_count """select id, intersect_count(bitmap_hash(kbint), kint, 3, 4) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync23 on agg_mv_test;""" createMV("""create materialized view mv_sync23 as select id, intersect_count(bitmap_hash(kbint), kint, 3, 4) from agg_mv_test group by id order by id;""") - explain { - sql("select id, intersect_count(bitmap_hash(kbint), kint, 3, 4) from agg_mv_test group by id order by id;") - contains "(mv_sync23)" - } + mv_rewrite_success("select id, intersect_count(bitmap_hash(kbint), kint, 3, 4) from agg_mv_test group by id order by id;", "mv_sync23") qt_select_intersect_count_mv """select id, intersect_count(bitmap_hash(kbint), kint, 3, 4) from agg_mv_test group by id order by id;""" qt_select_group_concat """select id, group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync24 on agg_mv_test;""" createMV("""create materialized view mv_sync24 as select id, group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;") - contains "(mv_sync24)" - } + mv_rewrite_success("select id, group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;", "mv_sync24") qt_select_group_concat_mv """select id, group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;""" qt_select_multi_distinct_group_concat """select id, multi_distinct_group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync25 on agg_mv_test;""" createMV("""create materialized view mv_sync25 as select id, multi_distinct_group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;""") - explain { - sql("select id, multi_distinct_group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;") - contains "(mv_sync25)" - } + mv_rewrite_success("select id, multi_distinct_group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;", "mv_sync25") qt_select_multi_distinct_group_concat_mv """select id, multi_distinct_group_concat(cast(abs(kint) as varchar)) from agg_mv_test group by id order by id;""" qt_select_multi_distinct_sum0 """select id, multi_distinct_sum0(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync26 on agg_mv_test;""" createMV("""create materialized view mv_sync26 as select id, multi_distinct_sum0(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, multi_distinct_sum0(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync26)" - } + mv_rewrite_success("select id, multi_distinct_sum0(kint) from agg_mv_test group by id order by id;", "mv_sync26") qt_select_multi_distinct_sum0_mv """select id, multi_distinct_sum0(kint) from agg_mv_test group by id order by id;""" qt_select_multi_distinct_sum """select id, multi_distinct_sum(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync27 on agg_mv_test;""" createMV("""create materialized view mv_sync27 as select id, multi_distinct_sum(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, multi_distinct_sum(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync27)" - } + mv_rewrite_success("select id, multi_distinct_sum(kint) from agg_mv_test group by id order by id;", "mv_sync27") qt_select_multi_distinct_sum_mv """select id, multi_distinct_sum(kint) from agg_mv_test group by id order by id;""" qt_select_histogram """select id, histogram(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync28 on agg_mv_test;""" createMV("""create materialized view mv_sync28 as select id, histogram(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, histogram(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync28)" - } + mv_rewrite_success("select id, histogram(kint) from agg_mv_test group by id order by id;", "mv_sync28") qt_select_histogram_mv """select id, histogram(kint) from agg_mv_test group by id order by id;""" qt_select_max_by """select id, max_by(kint, kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync29 on agg_mv_test;""" createMV("""create materialized view mv_sync29 as select id, max_by(kint, kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, max_by(kint, kint) from agg_mv_test group by id order by id;") - contains "(mv_sync29)" - } + mv_rewrite_success("select id, max_by(kint, kint) from agg_mv_test group by id order by id;", "mv_sync29") qt_select_max_by_mv """select id, max_by(kint, kint) from agg_mv_test group by id order by id;""" qt_select_min_by """select id, min_by(kint, kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync30 on agg_mv_test;""" createMV("""create materialized view mv_sync30 as select id, min_by(kint, kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, min_by(kint, kint) from agg_mv_test group by id order by id;") - contains "(mv_sync30)" - } + mv_rewrite_success("select id, min_by(kint, kint) from agg_mv_test group by id order by id;", "mv_sync30") qt_select_min_by_mv """select id, min_by(kint, kint) from agg_mv_test group by id order by id;""" qt_select_multi_distinct_count """select id, multi_distinct_count(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync31 on agg_mv_test;""" createMV("""create materialized view mv_sync31 as select id, multi_distinct_count(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, multi_distinct_count(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync31)" - } + mv_rewrite_success("select id, multi_distinct_count(kint) from agg_mv_test group by id order by id;", "mv_sync31") qt_select_multi_distinct_count_mv """select id, multi_distinct_count(kint) from agg_mv_test group by id order by id;""" qt_select_ndv """select id, ndv(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync32 on agg_mv_test;""" createMV("""create materialized view mv_sync32 as select id, ndv(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, ndv(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync32)" - } + mv_rewrite_success("select id, ndv(kint) from agg_mv_test group by id order by id;", "mv_sync32") qt_select_ndv_mv """select id, ndv(kint) from agg_mv_test group by id order by id;""" qt_select_covar """select id, covar(kint, kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync33 on agg_mv_test;""" createMV("""create materialized view mv_sync33 as select id, covar(kint, kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, covar(kint, kint) from agg_mv_test group by id order by id;") - contains "(mv_sync33)" - } + mv_rewrite_success("select id, covar(kint, kint) from agg_mv_test group by id order by id;", "mv_sync33") qt_select_covar_mv """select id, covar(kint, kint) from agg_mv_test group by id order by id;""" qt_select_covar_samp """select id, covar_samp(kint, kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync34 on agg_mv_test;""" createMV("""create materialized view mv_sync34 as select id, covar_samp(kint, kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, covar_samp(kint, kint) from agg_mv_test group by id order by id;") - contains "(mv_sync34)" - } + mv_rewrite_success("select id, covar_samp(kint, kint) from agg_mv_test group by id order by id;", "mv_sync34") qt_select_covar_samp_mv """select id, covar_samp(kint, kint) from agg_mv_test group by id order by id;""" qt_select_percentile """select id, percentile(kbint, 0.6) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync35 on agg_mv_test;""" createMV("""create materialized view mv_sync35 as select id, percentile(kbint, 0.6) from agg_mv_test group by id order by id;""") - explain { - sql("select id, percentile(kbint, 0.6) from agg_mv_test group by id order by id;") - contains "(mv_sync35)" - } + mv_rewrite_success("select id, percentile(kbint, 0.6) from agg_mv_test group by id order by id;", "mv_sync35") qt_select_percentile_mv """select id, percentile(kbint, 0.6) from agg_mv_test group by id order by id;""" qt_select_percentile_approx """select id, percentile_approx(kbint, 0.6) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync36 on agg_mv_test;""" createMV("""create materialized view mv_sync36 as select id, percentile_approx(kbint, 0.6) from agg_mv_test group by id order by id;""") - explain { - sql("select id, percentile_approx(kbint, 0.6) from agg_mv_test group by id order by id;") - contains "(mv_sync36)" - } + mv_rewrite_success("select id, percentile_approx(kbint, 0.6) from agg_mv_test group by id order by id;", "mv_sync36") qt_select_percentile_approx_mv """select id, percentile_approx(kbint, 0.6) from agg_mv_test group by id order by id;""" // percentile_approx_weighted is not supported in old planner @@ -361,127 +257,85 @@ suite("agg_sync_mv") { qt_select_sequence_count """select id, sequence_count('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync38 on agg_mv_test;""" createMV("""create materialized view mv_sync38 as select id, sequence_count('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;""") - explain { - sql("select id, sequence_count('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;") - contains "(mv_sync38)" - } + mv_rewrite_success("select id, sequence_count('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;", "mv_sync38") qt_select_sequence_count_mv """select id, sequence_count('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;""" qt_select_sequence_match """select id, sequence_match('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync39 on agg_mv_test;""" createMV("""create materialized view mv_sync39 as select id, sequence_match('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;""") - explain { - sql("select id, sequence_match('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;") - contains "(mv_sync39)" - } + mv_rewrite_success("select id, sequence_match('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;", "mv_sync39") qt_select_sequence_match_mv """select id, sequence_match('(?1)(?2)', kdtv2, kint = 1, kint = 2) from agg_mv_test group by id order by id;""" qt_select_stddev """select id, stddev(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync40 on agg_mv_test;""" createMV("""create materialized view mv_sync40 as select id, stddev(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, stddev(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync40)" - } + mv_rewrite_success("select id, stddev(kint) from agg_mv_test group by id order by id;", "mv_sync40") qt_select_stddev_mv """select id, stddev(kint) from agg_mv_test group by id order by id;""" qt_select_stddev_pop """select id, stddev_pop(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync41 on agg_mv_test;""" createMV("""create materialized view mv_sync41 as select id, stddev_pop(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, stddev_pop(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync41)" - } + mv_rewrite_success("select id, stddev_pop(kint) from agg_mv_test group by id order by id;", "mv_sync41") qt_select_stddev_pop_mv """select id, stddev_pop(kint) from agg_mv_test group by id order by id;""" qt_select_stddev_samp """select id, stddev_samp(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync42 on agg_mv_test;""" createMV("""create materialized view mv_sync42 as select id, stddev_samp(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, stddev_samp(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync42)" - } + mv_rewrite_success("select id, stddev_samp(kint) from agg_mv_test group by id order by id;", "mv_sync42") qt_select_stddev_samp_mv """select id, stddev_samp(kint) from agg_mv_test group by id order by id;""" qt_select_sum0 """select id, sum0(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync43 on agg_mv_test;""" createMV("""create materialized view mv_sync43 as select id, sum0(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, sum0(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync43)" - } + mv_rewrite_success("select id, sum0(kint) from agg_mv_test group by id order by id;", "mv_sync43") qt_select_sum0_mv """select id, sum0(kint) from agg_mv_test group by id order by id;""" qt_select_topn """select id, topn(kvchrs1, 3) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync44 on agg_mv_test;""" createMV("""create materialized view mv_sync44 as select id, topn(kvchrs1, 3) from agg_mv_test group by id order by id;""") - explain { - sql("select id, topn(kvchrs1, 3) from agg_mv_test group by id order by id;") - contains "(mv_sync44)" - } + mv_rewrite_success("select id, topn(kvchrs1, 3) from agg_mv_test group by id order by id;", "mv_sync44") qt_select_topn_mv """select id, topn(kvchrs1, 3) from agg_mv_test group by id order by id;""" qt_select_topn_array """select id, topn_array(kvchrs1, 3) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync45 on agg_mv_test;""" createMV("""create materialized view mv_sync45 as select id, topn_array(kvchrs1, 3) from agg_mv_test group by id order by id;""") - explain { - sql("select id, topn_array(kvchrs1, 3) from agg_mv_test group by id order by id;") - contains "(mv_sync45)" - } + mv_rewrite_success("select id, topn_array(kvchrs1, 3) from agg_mv_test group by id order by id;", "mv_sync45") qt_select_topn_array_mv """select id, topn_array(kvchrs1, 3) from agg_mv_test group by id order by id;""" qt_select_topn_weighted """select id, topn_weighted(kvchrs1, ktint, 3) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync46 on agg_mv_test;""" createMV("""create materialized view mv_sync46 as select id, topn_weighted(kvchrs1, ktint, 3) from agg_mv_test group by id order by id;""") - explain { - sql("select id, topn_weighted(kvchrs1, ktint, 3) from agg_mv_test group by id order by id;") - contains "(mv_sync46)" - } + mv_rewrite_success("select id, topn_weighted(kvchrs1, ktint, 3) from agg_mv_test group by id order by id;", "mv_sync46") qt_select_topn_weighted_mv """select id, topn_weighted(kvchrs1, ktint, 3) from agg_mv_test group by id order by id;""" qt_select_variance """select id, variance(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync47 on agg_mv_test;""" createMV("""create materialized view mv_sync47 as select id, variance(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, variance(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync47)" - } + mv_rewrite_success("select id, variance(kint) from agg_mv_test group by id order by id;", "mv_sync47") qt_select_variance_mv """select id, variance(kint) from agg_mv_test group by id order by id;""" qt_select_var_pop """select id, var_pop(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync48 on agg_mv_test;""" createMV("""create materialized view mv_sync48 as select id, var_pop(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, var_pop(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync47)" - } + mv_rewrite_success("select id, var_pop(kint) from agg_mv_test group by id order by id;", "mv_sync47") qt_select_var_pop_mv """select id, var_pop(kint) from agg_mv_test group by id order by id;""" qt_select_variance_samp """select id, variance_samp(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync49 on agg_mv_test;""" createMV("""create materialized view mv_sync49 as select id, variance_samp(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, variance_samp(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync49)" - } + mv_rewrite_success("select id, variance_samp(kint) from agg_mv_test group by id order by id;", "mv_sync49") qt_select_variance_samp_mv """select id, variance_samp(kint) from agg_mv_test group by id order by id;""" qt_select_var_samp """select id, var_samp(kint) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync50 on agg_mv_test;""" createMV("""create materialized view mv_sync50 as select id, var_samp(kint) from agg_mv_test group by id order by id;""") - explain { - sql("select id, var_samp(kint) from agg_mv_test group by id order by id;") - contains "(mv_sync50)" - } + mv_rewrite_success("select id, var_samp(kint) from agg_mv_test group by id order by id;", "mv_sync50") qt_select_var_samp_mv """select id, var_samp(kint) from agg_mv_test group by id order by id;""" qt_select_window_funnel """select id, window_funnel(3600 * 3, 'default', kdtm, kint = 1, kint = 2) from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync51 on agg_mv_test;""" createMV("""create materialized view mv_sync51 as select id, window_funnel(3600 * 3, 'default', kdtm, kint = 1, kint = 2) from agg_mv_test group by id order by id;""") - explain { - sql("select id, window_funnel(3600 * 3, 'default', kdtm, kint = 1, kint = 2) from agg_mv_test group by id order by id;") - contains "(mv_sync51)" - } + mv_rewrite_success("select id, window_funnel(3600 * 3, 'default', kdtm, kint = 1, kint = 2) from agg_mv_test group by id order by id;", "mv_sync51") qt_select_window_funnel_mv """select id, window_funnel(3600 * 3, 'default', kdtm, kint = 1, kint = 2) from agg_mv_test group by id order by id;""" // map_agg is not supported yet @@ -507,10 +361,7 @@ suite("agg_sync_mv") { qt_select_retention """select id, retention(kdtm = '2012-03-11', kdtm = '2012-03-12') from agg_mv_test group by id order by id;""" sql """drop materialized view if exists mv_sync54 on agg_mv_test;""" createMV("""create materialized view mv_sync54 as select id, retention(kdtm = '2012-03-11', kdtm = '2012-03-12') from agg_mv_test group by id order by id;""") - explain { - sql("select id, retention(kdtm = '2012-03-11', kdtm = '2012-03-12') from agg_mv_test group by id order by id;") - contains "(mv_sync54)" - } + mv_rewrite_success("select id, retention(kdtm = '2012-03-11', kdtm = '2012-03-12') from agg_mv_test group by id order by id;", "mv_sync54") qt_select_retention_mv """select id, retention(kdtm = '2012-03-11', kdtm = '2012-03-12') from agg_mv_test group by id order by id;"""