This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 0fdb1ee0825 [fix](mtmv) Disable sql_limit variable when query rewrite by materialize view (#40106) 0fdb1ee0825 is described below commit 0fdb1ee082535ffab81071e284ce780086379148 Author: seawinde <149132972+seawi...@users.noreply.github.com> AuthorDate: Fri Oct 11 16:13:37 2024 +0800 [fix](mtmv) Disable sql_limit variable when query rewrite by materialize view (#40106) In BI or some other SQL client,it will set `sql_select_limit` or `default_order_by_limit` session variables automatically. This will make mistake when query rewrite by materialized view, Because after query rewrite by materialized view, the rewritten plan would be optimized by rules again which should add limit on SQL. This pr fix this. --- .../java/org/apache/doris/mtmv/MTMVPlanUtil.java | 5 + .../exploration/mv/MaterializedViewUtils.java | 12 + .../trees/plans/logical/LogicalOlapScan.java | 29 +- .../data/mtmv_p0/limit/refresh_with_sql_limit.out | 41 +++ .../mv/with_sql_limit/query_with_sql_limit.out | 19 ++ .../org/apache/doris/regression/suite/Suite.groovy | 5 + .../mtmv_p0/limit/refresh_with_sql_limit.groovy | 115 ++++++++ .../mv/with_sql_limit/query_with_sql_limit.groovy | 321 +++++++++++++++++++++ 8 files changed, 540 insertions(+), 7 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java index 8cb3a31f2da..0a93af5676f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java @@ -30,6 +30,7 @@ import org.apache.doris.nereids.exceptions.ParseException; import org.apache.doris.nereids.glue.LogicalPlanAdapter; import org.apache.doris.nereids.parser.NereidsParser; import org.apache.doris.nereids.properties.PhysicalProperties; +import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel; import org.apache.doris.nereids.trees.plans.commands.info.CreateMTMVInfo; @@ -39,6 +40,7 @@ import org.apache.doris.nereids.trees.plans.visitor.TableCollector.TableCollecto import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.SessionVariable; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import java.util.List; @@ -55,6 +57,9 @@ public class MTMVPlanUtil { ctx.getState().reset(); ctx.setThreadLocalInfo(); ctx.getSessionVariable().allowModifyMaterializedViewData = true; + // Disable add default limit rule to avoid refresh data wrong + ctx.getSessionVariable().setDisableNereidsRules( + String.join(",", ImmutableSet.of(RuleType.ADD_DEFAULT_LIMIT.name()))); Optional<String> workloadGroup = mtmv.getWorkloadGroup(); if (workloadGroup.isPresent()) { ctx.getSessionVariable().setWorkloadGroup(workloadGroup.get()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java index 7bad7f6db28..2d483c45185 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java @@ -73,6 +73,7 @@ import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionColl import org.apache.doris.nereids.util.ExpressionUtils; import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.OriginStatement; +import org.apache.doris.qe.SessionVariable; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; @@ -267,11 +268,22 @@ public class MaterializedViewUtils { CascadesContext rewrittenPlanContext = CascadesContext.initContext( cascadesContext.getStatementContext(), rewrittenPlan, cascadesContext.getCurrentJobContext().getRequiredProperties()); + // Tmp old disable rule variable + Set<String> oldDisableRuleNames = rewrittenPlanContext.getStatementContext().getConnectContext() + .getSessionVariable() + .getDisableNereidsRuleNames(); + rewrittenPlanContext.getStatementContext().getConnectContext().getSessionVariable() + .setDisableNereidsRules(String.join(",", ImmutableSet.of(RuleType.ADD_DEFAULT_LIMIT.name()))); + rewrittenPlanContext.getStatementContext().invalidCache(SessionVariable.DISABLE_NEREIDS_RULES); try { rewrittenPlanContext.getConnectContext().setSkipAuth(true); rewrittenPlan = planRewriter.apply(rewrittenPlanContext); } finally { rewrittenPlanContext.getConnectContext().setSkipAuth(false); + // Recover old disable rules variable + rewrittenPlanContext.getStatementContext().getConnectContext().getSessionVariable() + .setDisableNereidsRules(String.join(",", oldDisableRuleNames)); + rewrittenPlanContext.getStatementContext().invalidCache(SessionVariable.DISABLE_NEREIDS_RULES); } Map<ExprId, Slot> exprIdToNewRewrittenSlot = Maps.newLinkedHashMap(); for (Slot slot : rewrittenPlan.getOutput()) { 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 ac986cbe77b..17c49ea87c8 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 com.google.common.collect.Maps; 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,7 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -528,7 +529,7 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -542,7 +543,7 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -556,7 +557,7 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); MTMVCache cache = mtmv.getCache(); - if (cache == null) { + if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -567,9 +568,23 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan Map<Slot, Slot> constructReplaceMap(MTMV mtmv) { Map<Slot, Slot> replaceMap = new HashMap<>(); - List<Slot> 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<Slot> originOutputs = new ArrayList<>(); + for (Slot originSlot : mtmv.getCache().getOriginalPlan().getOutput()) { + if (!(originSlot instanceof SlotReference) || (((SlotReference) originSlot).isVisible())) { + originOutputs.add(originSlot); + } + } + List<Slot> 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/mtmv_p0/limit/refresh_with_sql_limit.out b/regression-test/data/mtmv_p0/limit/refresh_with_sql_limit.out new file mode 100644 index 00000000000..c7caea66ceb --- /dev/null +++ b/regression-test/data/mtmv_p0/limit/refresh_with_sql_limit.out @@ -0,0 +1,41 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !query_mv_1 -- +1 1 o 10.50 2023-12-08 a b 1 yy +1 1 o 10.50 2023-12-08 a b 1 yy +1 1 o 10.50 2023-12-08 a b 1 yy +1 1 o 9.50 2023-12-08 a b 1 yy +2 1 o 11.50 2023-12-09 a b 1 yy +2 1 o 11.50 2023-12-09 a b 1 yy +2 1 o 11.50 2023-12-09 a b 1 yy +3 1 o 12.50 2023-12-10 a b 1 yy +3 1 o 12.50 2023-12-10 a b 1 yy +3 1 o 12.50 2023-12-10 a b 1 yy +3 1 o 33.50 2023-12-10 a b 1 yy +4 2 o 43.20 2023-12-11 c d 2 mm +4 2 o 43.20 2023-12-11 c d 2 mm +4 2 o 43.20 2023-12-11 c d 2 mm +5 2 o 1.20 2023-12-12 c d 2 mi +5 2 o 56.20 2023-12-12 c d 2 mi +5 2 o 56.20 2023-12-12 c d 2 mi +5 2 o 56.20 2023-12-12 c d 2 mi + +-- !query_mv_2 -- +1 1 o 10.50 2023-12-08 a b 1 yy +1 1 o 10.50 2023-12-08 a b 1 yy +1 1 o 10.50 2023-12-08 a b 1 yy +1 1 o 9.50 2023-12-08 a b 1 yy +2 1 o 11.50 2023-12-09 a b 1 yy +2 1 o 11.50 2023-12-09 a b 1 yy +2 1 o 11.50 2023-12-09 a b 1 yy +3 1 o 12.50 2023-12-10 a b 1 yy +3 1 o 12.50 2023-12-10 a b 1 yy +3 1 o 12.50 2023-12-10 a b 1 yy +3 1 o 33.50 2023-12-10 a b 1 yy +4 2 o 43.20 2023-12-11 c d 2 mm +4 2 o 43.20 2023-12-11 c d 2 mm +4 2 o 43.20 2023-12-11 c d 2 mm +5 2 o 1.20 2023-12-12 c d 2 mi +5 2 o 56.20 2023-12-12 c d 2 mi +5 2 o 56.20 2023-12-12 c d 2 mi +5 2 o 56.20 2023-12-12 c d 2 mi + diff --git a/regression-test/data/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.out b/regression-test/data/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.out new file mode 100644 index 00000000000..f6e6eb3653b --- /dev/null +++ b/regression-test/data/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.out @@ -0,0 +1,19 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !query1_0_before -- +4 + +-- !query1_0_after -- +4 + +-- !query2_0_before -- +4 + +-- !query2_0_after -- +4 + +-- !query3_0_before -- +4 + +-- !query3_0_after -- +4 + 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 099799ed8d6..f54ec51b85e 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 @@ -1329,6 +1329,8 @@ class Suite implements GroovyInterceptable { logger.info("status is not success") } Assert.assertEquals("SUCCESS", status) + logger.info("waitingMTMVTaskFinished analyze mv name is " + result.last().get(5)) + sql "analyze table ${result.last().get(6)}.${mvName} with sync;" } void waitingMTMVTaskFinishedByMvNameAllowCancel(String mvName) { @@ -1399,6 +1401,9 @@ class Suite implements GroovyInterceptable { logger.info("status is not success") } Assert.assertEquals("SUCCESS", status) + // 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)}.${result.last().get(5)} with sync;" } void waitingMTMVTaskFinishedNotNeedSuccess(String jobName) { diff --git a/regression-test/suites/mtmv_p0/limit/refresh_with_sql_limit.groovy b/regression-test/suites/mtmv_p0/limit/refresh_with_sql_limit.groovy new file mode 100644 index 00000000000..d08d842226f --- /dev/null +++ b/regression-test/suites/mtmv_p0/limit/refresh_with_sql_limit.groovy @@ -0,0 +1,115 @@ +package limit +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("refresh_with_sql_limit") { + String db = context.config.getDbNameByFile(context.file) + sql "use ${db}" + sql "set runtime_filter_mode=OFF"; + sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'" + + sql """ + drop table if exists orders; + """ + + sql """ + CREATE TABLE IF NOT EXISTS orders ( + o_orderkey INTEGER NOT NULL, + o_custkey INTEGER NOT NULL, + o_orderstatus CHAR(1) NOT NULL, + o_totalprice DECIMALV3(15,2) NOT NULL, + o_orderdate DATE NOT NULL, + o_orderpriority CHAR(15) NOT NULL, + o_clerk CHAR(15) NOT NULL, + o_shippriority INTEGER NOT NULL, + 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" + ); + """ + + sql """ + insert into orders values + (1, 1, 'o', 9.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 33.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), + (5, 2, 'o', 1.2, '2023-12-12', 'c','d',2, 'mi'); + """ + sql """analyze table orders with sync""" + + + sql """DROP MATERIALIZED VIEW IF EXISTS mv_1""" + sql """set default_order_by_limit = 2;""" + sql """set sql_select_limit = 2;""" + sql""" + CREATE MATERIALIZED VIEW mv_1 + BUILD DEFERRED REFRESH COMPLETE ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS select * from orders; + """ + sql """refresh materialized view mv_1 auto;""" + def job_name = getJobName(db, "mv_1"); + waitingMTMVTaskFinished(job_name) + + // Reset and test mv data is right or not + sql """set default_order_by_limit = -1;""" + sql """set sql_select_limit = -1;""" + order_qt_query_mv_1 "select * from mv_1" + sql """ DROP MATERIALIZED VIEW IF EXISTS mv_1""" + + + sql """DROP MATERIALIZED VIEW IF EXISTS mv_2""" + sql """set default_order_by_limit = 2""" + sql """set sql_select_limit = 2""" + sql""" + CREATE MATERIALIZED VIEW mv_2 + BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL + DISTRIBUTED BY RANDOM BUCKETS 2 + PROPERTIES ('replication_num' = '1') + AS select * from orders; + """ + waitingMTMVTaskFinished(getJobName(db, "mv_2")) + + // Reset and test mv data is right or not + sql """set default_order_by_limit = -1;""" + sql """set sql_select_limit = -1;""" + order_qt_query_mv_2 "select * from mv_2" + sql """ DROP MATERIALIZED VIEW IF EXISTS mv_2""" +} diff --git a/regression-test/suites/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.groovy b/regression-test/suites/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.groovy new file mode 100644 index 00000000000..b7c6ecbd8ae --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.groovy @@ -0,0 +1,321 @@ +package mv.with_sql_limit +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("query_with_sql_limit") { + String db = context.config.getDbNameByFile(context.file) + sql "use ${db}" + sql "set runtime_filter_mode=OFF"; + sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'" + + sql """ + drop table if exists orders + """ + + sql """ + CREATE TABLE IF NOT EXISTS orders ( + o_orderkey INTEGER NOT NULL, + o_custkey INTEGER NOT NULL, + o_orderstatus CHAR(1) NOT NULL, + o_totalprice DECIMALV3(15,2) NOT NULL, + o_orderdate DATE NOT NULL, + o_orderpriority CHAR(15) NOT NULL, + o_clerk CHAR(15) NOT NULL, + o_shippriority INTEGER NOT NULL, + 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" + ); + """ + + sql """ + drop table if exists lineitem + """ + + sql""" + CREATE TABLE IF NOT EXISTS lineitem ( + l_orderkey INTEGER NOT NULL, + l_partkey INTEGER NOT NULL, + l_suppkey INTEGER NOT NULL, + l_linenumber INTEGER NOT NULL, + l_quantity DECIMALV3(15,2) NOT NULL, + l_extendedprice DECIMALV3(15,2) NOT NULL, + l_discount DECIMALV3(15,2) NOT NULL, + l_tax DECIMALV3(15,2) NOT NULL, + l_returnflag CHAR(1) NOT NULL, + l_linestatus CHAR(1) NOT NULL, + l_shipdate DATE NOT NULL, + l_commitdate DATE NOT NULL, + l_receiptdate DATE NOT NULL, + l_shipinstruct CHAR(25) NOT NULL, + l_shipmode CHAR(10) NOT NULL, + 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" + ) + """ + + sql """ + drop table if exists partsupp + """ + + sql """ + CREATE TABLE IF NOT EXISTS partsupp ( + ps_partkey INTEGER NOT NULL, + ps_suppkey INTEGER NOT NULL, + ps_availqty INTEGER NOT NULL, + ps_supplycost DECIMALV3(15,2) NOT NULL, + ps_comment VARCHAR(199) NOT NULL + ) + DUPLICATE KEY(ps_partkey, ps_suppkey) + DISTRIBUTED BY HASH(ps_partkey) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1" + ) + """ + + sql """ insert into lineitem values + (1, 2, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-12-08', '2023-12-09', '2023-12-10', 'a', 'b', 'yyyyyyyyy'), + (2, 4, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-12-09', '2023-12-09', '2023-12-10', 'a', 'b', 'yyyyyyyyy'), + (3, 2, 4, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-12-10', '2023-12-09', '2023-12-10', 'a', 'b', 'yyyyyyyyy'), + (4, 3, 3, 4, 5.5, 6.5, 7.5, 8.5, 'o', 'k', '2023-12-11', '2023-12-09', '2023-12-10', 'a', 'b', 'yyyyyyyyy'), + (5, 2, 3, 6, 7.5, 8.5, 9.5, 10.5, 'k', 'o', '2023-12-12', '2023-12-12', '2023-12-13', 'c', 'd', 'xxxxxxxxx'); + """ + + sql """ + insert into orders values + (1, 1, 'o', 9.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (1, 1, 'o', 10.5, '2023-12-08', 'a', 'b', 1, 'yy'), + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), + (2, 1, 'o', 11.5, '2023-12-09', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 12.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (3, 1, 'o', 33.5, '2023-12-10', 'a', 'b', 1, 'yy'), + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), + (4, 2, 'o', 43.2, '2023-12-11', 'c','d',2, 'mm'), + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), + (5, 2, 'o', 56.2, '2023-12-12', 'c','d',2, 'mi'), + (5, 2, 'o', 1.2, '2023-12-12', 'c','d',2, 'mi'); + """ + + sql """ + insert into partsupp values + (2, 3, 9, 10.01, 'supply1'), + (2, 3, 10, 11.01, 'supply2'); + """ + + sql """analyze table partsupp with sync""" + sql """analyze table lineitem with sync""" + sql """analyze table orders with sync""" + + // test sql_select_limit default, default 9223372036854775807 + sql """set sql_select_limit = 2;""" + def mv1_0 = + """ + select + distinct + o_orderkey, + o_orderdate + from orders + where O_COMMENT not in ('mi', 'mm'); + """ + def query1_0 = + """ + select + count(*) + from + ( + with view1 as ( + select + distinct o_orderkey, + o_orderdate + from + orders + where + O_COMMENT not in ('mi', 'mm') + and 'BI' = 'BI' + ), + view2 as ( + select + distinct o_orderkey, + o_orderdate + from + view1 + where + o_orderdate = '2023-12-09' + ) + select + * + from + view1 + union all + select + * + from + view2 + ) as t + limit + 3; + """ + order_qt_query1_0_before "${query1_0}" + 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""" + // Reset default + sql """set sql_select_limit = -1;""" + + + + // test default_order_by_limit, default -1 + sql """set default_order_by_limit = 1;""" + // test sql_select_limit default + def mv2_0 = + """ + select + distinct + o_orderkey, + o_orderdate + from orders + where O_COMMENT not in ('mi', 'mm'); + """ + def query2_0 = + """ + select + count(*) + from + ( + with view1 as ( + select + distinct o_orderkey, + o_orderdate + from + orders + where + O_COMMENT not in ('mi', 'mm') + and 'BI' = 'BI' + ), + view2 as ( + select + distinct o_orderkey, + o_orderdate + from + view1 + where + o_orderdate = '2023-12-09' + ) + select + * + from + view1 + union all + select + * + from + view2 + ) as t + limit + 3; + """ + order_qt_query2_0_before "${query2_0}" + async_mv_rewrite_success(db, mv2_0, query2_0, "mv2_0") + order_qt_query2_0_after "${query2_0}" + sql """ DROP MATERIALIZED VIEW IF EXISTS mv2_0""" + // Reset default value + sql """set default_order_by_limit = -1;""" + + + + // test default_order_by_limit and , default -1 + sql """set default_order_by_limit = 1;""" + sql """set sql_select_limit = 2;""" + // test sql_select_limit default + def mv3_0 = + """ + select + distinct + o_orderkey, + o_orderdate + from orders + where O_COMMENT not in ('mi', 'mm'); + """ + def query3_0 = + """ + select + count(*) + from + ( + with view1 as ( + select + distinct o_orderkey, + o_orderdate + from + orders + where + O_COMMENT not in ('mi', 'mm') + and 'BI' = 'BI' + ), + view2 as ( + select + distinct o_orderkey, + o_orderdate + from + view1 + where + o_orderdate = '2023-12-09' + ) + select + * + from + view1 + union all + select + * + from + view2 + ) as t + limit + 3; + """ + order_qt_query3_0_before "${query3_0}" + async_mv_rewrite_success(db, mv3_0, query3_0, "mv3_0") + order_qt_query3_0_after "${query3_0}" + sql """ DROP MATERIALIZED VIEW IF EXISTS mv3_0""" + // Reset default value + sql """set default_order_by_limit = -1;""" + sql """set sql_select_limit = -1;""" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org