-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix](mtmv) Disable sql_limit variable when query rewrite by materialize view #40106
Merged
morrySnow
merged 11 commits into
apache:master
from
seawinde:fix_add_limit_wrongly_when_mv
Oct 11, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d7923af
[fix](mtmv) Disable sql_limit variable when query rewrite by material…
seawinde 2133add
disable limit in mv refresh
seawinde 0adf89e
fix regression test
seawinde a108155
fix comment
seawinde f698574
optimize code usage
seawinde 35d9342
optimize code usage
seawinde 8f76064
fix compile error
seawinde c0eb449
add analyze after create mtmv
seawinde 592694f
fix regression test
seawinde 2e54f74
fix regression test
seawinde 1875947
fix regression test
seawinde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ | |
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 static Plan rewriteByRules( | |
CascadesContext rewrittenPlanContext = CascadesContext.initContext( | ||
cascadesContext.getStatementContext(), rewrittenPlan, | ||
cascadesContext.getCurrentJobContext().getRequiredProperties()); | ||
// Tmp old disable rule variable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set disable rules here, not everywhere |
||
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()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
regression-test/data/mtmv_p0/limit/refresh_with_sql_limit.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
19 changes: 19 additions & 0 deletions
19
regression-test/data/nereids_rules_p0/mv/with_sql_limit/query_with_sql_limit.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
regression-test/suites/mtmv_p0/limit/refresh_with_sql_limit.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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""" | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the default values are changed in the future, there may be issues here. Can we use an additional method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default value of
disableNereidsRules
session should always be empty ''