-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feature](Nereids): Optimize Query Plan by Pulling Up Join with Common Child from Union #42033
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c798e0
origin code from xj
feiniaofeiafei 97188b5
fix compare bug and make common child slot same position
feiniaofeiafei b7f2c25
only retain the logic of tryToExtractCommonChild, and re-implement th…
feiniaofeiafei 5bc8a99
fix feut
feiniaofeiafei 215547b
remove rule PullUpJoinFromUnionAll
feiniaofeiafei 18ffb7e
fix query71 and query76 regression
feiniaofeiafei 1298fdf
fix regression query4 14 11 74, and add some cases
feiniaofeiafei 304d384
remove useless code
feiniaofeiafei ca3d8a1
change by review comment
feiniaofeiafei fb40e30
change by review comment
feiniaofeiafei 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 hidden or 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 hidden or 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
1,025 changes: 488 additions & 537 deletions
1,025
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnionAll.java
Large diffs are not rendered by default.
Oops, something went wrong.
171 changes: 171 additions & 0 deletions
171
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PullUpJoinFromUnionTest.java
This file contains hidden or 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,171 @@ | ||
| // 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. | ||
|
|
||
| package org.apache.doris.nereids.rules.rewrite; | ||
|
|
||
| import org.apache.doris.nereids.util.MemoPatternMatchSupported; | ||
| import org.apache.doris.nereids.util.PlanChecker; | ||
| import org.apache.doris.utframe.TestWithFeService; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class PullUpJoinFromUnionTest extends TestWithFeService implements MemoPatternMatchSupported { | ||
| @Override | ||
| protected void runBeforeAll() throws Exception { | ||
| createDatabase("test"); | ||
| connectContext.setDatabase("default_cluster:test"); | ||
| createTables( | ||
| "CREATE TABLE IF NOT EXISTS t1 (\n" | ||
| + " id int not null,\n" | ||
| + " name char\n" | ||
| + ")\n" | ||
| + "DUPLICATE KEY(id)\n" | ||
| + "DISTRIBUTED BY HASH(id) BUCKETS 10\n" | ||
| + "PROPERTIES (\"replication_num\" = \"1\")\n", | ||
| "CREATE TABLE IF NOT EXISTS t2 (\n" | ||
| + " id int not null,\n" | ||
| + " name char\n" | ||
| + ")\n" | ||
| + "DUPLICATE KEY(id)\n" | ||
| + "DISTRIBUTED BY HASH(id) BUCKETS 10\n" | ||
| + "PROPERTIES (\"replication_num\" = \"1\")\n", | ||
| "CREATE TABLE IF NOT EXISTS t3 (\n" | ||
| + " id int,\n" | ||
| + " name char\n" | ||
| + ")\n" | ||
| + "DUPLICATE KEY(id)\n" | ||
| + "DISTRIBUTED BY HASH(id) BUCKETS 10\n" | ||
| + "PROPERTIES (\"replication_num\" = \"1\")\n" | ||
| ); | ||
| connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION"); | ||
| } | ||
|
|
||
| @Test | ||
| void testSimple() { | ||
| String sql = "select * from t1 join t2 on t1.id = t2.id " | ||
| + "union all " | ||
| + "select * from t1 join t3 on t1.id = t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testProject() { | ||
| String sql = "select t2.id from t1 join t2 on t1.id = t2.id " | ||
| + "union all " | ||
| + "select t3.id from t1 join t3 on t1.id = t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
|
|
||
| sql = "select t2.id, t1.name from t1 join t2 on t1.id = t2.id " | ||
| + "union all " | ||
| + "select t3.id, t1.name from t1 join t3 on t1.id = t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testConstant() { | ||
| String sql = "select t2.id, t1.name, 1 as id1 from t1 join t2 on t1.id = t2.id " | ||
| + "union all " | ||
| + "select t3.id, t1.name, 2 as id2 from t1 join t3 on t1.id = t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testComplexProject() { | ||
| String sql = "select t2.id + 1, t1.name + 1, 1 as id1 from t1 join t2 on t1.id = t2.id " | ||
| + "union all " | ||
| + "select t3.id + 1, t1.name + 1, 2 as id2 from t1 join t3 on t1.id = t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalUnion(), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testMissJoinSlot() { | ||
| String sql = "select t1.name + 1, 1 as id1 from t1 join t2 on t1.id = t2.id " | ||
| + "union all " | ||
| + "select t1.name + 1, 2 as id2 from t1 join t3 on t1.id = t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalUnion(), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testFilter() { | ||
| String sql = "select * from t1 join t2 on t1.id = t2.id where t1.name = '' " | ||
| + "union all " | ||
| + "select * from t1 join t3 on t1.id = t3.id where t1.name = '' ;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
|
|
||
| sql = "select t2.id from t1 join t2 on t1.id = t2.id where t1.name = '' " | ||
| + "union all " | ||
| + "select t3.id from t1 join t3 on t1.id = t3.id where t1.name = '' ;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testMultipleJoinConditions() { | ||
| String sql = "select * from t1 join t2 on t1.id = t2.id and t1.name = t2.name " | ||
| + "union all " | ||
| + "select * from t1 join t3 on t1.id = t3.id and t1.name = t3.name;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testNonEqualityJoinConditions() { | ||
| String sql = "select * from t1 join t2 on t1.id < t2.id " | ||
| + "union all " | ||
| + "select * from t1 join t3 on t1.id < t3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .nonMatch(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
|
|
||
| @Test | ||
| void testSubqueries() { | ||
| String sql = "select * from t1 join (select * from t2 where t2.id > 10) s2 on t1.id = s2.id " | ||
| + "union all " | ||
| + "select * from t1 join (select * from t3 where t3.id > 10) s3 on t1.id = s3.id;"; | ||
| PlanChecker.from(connectContext) | ||
| .analyze(sql) | ||
| .rewrite() | ||
| .matches(logicalJoin(logicalProject(logicalUnion()), any())); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
make sure the new rule sets can replace the original one's column pruning functionality.