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
[Enhancement] Push down topn with left and right outer join #30128
[Enhancement] Push down topn with left and right outer join #30128
Conversation
...src/main/java/com/starrocks/sql/optimizer/rule/transformation/PushDownTopNWithOuterJoin.java
Outdated
Show resolved
Hide resolved
...src/main/java/com/starrocks/sql/optimizer/rule/transformation/PushDownTopNWithOuterJoin.java
Outdated
Show resolved
Hide resolved
...main/java/com/starrocks/sql/optimizer/rule/transformation/OuterJoinAddRedundantTopNRule.java
Show resolved
Hide resolved
what will happen if A colocate join B AGG order by A.x; |
...main/java/com/starrocks/sql/optimizer/rule/transformation/OuterJoinAddRedundantTopNRule.java
Outdated
Show resolved
Hide resolved
what's the detail plan for TOPN one stage or two stage. two stage TOPN is not as expected. |
what will happen if l left join r on l.a = r.a where l.a + l.b < 10 order by l.a limit 10? |
Signed-off-by: stephen <stephen5217@163.com>
Signed-off-by: stephen <stephen5217@163.com>
Join may only be executed on one machine.after this change |
do you want to write |
9dd31bc
to
2ac67e6
Compare
fixed |
yes, but I only push one layer of topn nodes. |
...main/java/com/starrocks/sql/optimizer/rule/transformation/OuterJoinAddRedundantTopNRule.java
Outdated
Show resolved
Hide resolved
...main/java/com/starrocks/sql/optimizer/rule/transformation/OuterJoinAddRedundantTopNRule.java
Outdated
Show resolved
Hide resolved
@@ -401,6 +402,7 @@ private OptExpression logicalRuleRewrite(ConnectContext connectContext, | |||
// After this rule, we shouldn't generate logical project operator | |||
ruleRewriteIterative(tree, rootTaskContext, new MergeProjectWithChildRule()); | |||
|
|||
ruleRewriteOnlyOnce(tree, rootTaskContext, new OuterJoinAddRedundantTopNRule()); |
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.
execute it before MergeProjectWithChildRule
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 before MergeProjctWithChildRule
, it may need two patterns. I had discussed with stephen, the check process has ensure all order by cols are from the child of join. The added topN operator also without setting projection. So after the rule it OK? Has any other problem here?
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.
OK, just few supported scenarios now
Signed-off-by: stephen <stephen5217@163.com>
SonarCloud Quality Gate failed. 5 Bugs 0.0% Coverage Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
[FE Incremental Coverage Report]😍 pass : 49 / 51 (96.08%) file detail
|
[BE Incremental Coverage Report]😍 pass : 0 / 0 (0%) |
…s#30128) Signed-off-by: stephen <stephen5217@163.com> Signed-off-by: Moonm3n <saxonzhan@gmail.com>
…s#30128) Signed-off-by: stephen <stephen5217@163.com>
Fixes #issue
What type of PR is this:
BASE PLAN:
OPTIMIZED PLAN
Some test case
SELECT * FROM ( SELECT c.*, p.p_name, p.p_brand FROM customer c LEFT JOIN part p ON c.c_custkey = p.p_partkey AND p.p_size = 32 ) AS mocktable ORDER BY mocktable.c_nationkey DESC LIMIT 20
TPCH 100G olap table
TPCH 1T olap table
SELECT * FROM ( SELECT c.*, p.p_name, p.p_brand FROM customer c RIGHT JOIN part p ON c.c_custkey = p.p_partkey ) AS mocktable ORDER BY mocktable.p_brand DESC LIMIT 20
TPCH 100G olap table
TPCH 1T olap table
select * from ( select * from ( SELECT * FROM ( SELECT c.*, p.p_name, p.p_brand FROM customer c RIGHT JOIN part p ON c.c_custkey = p.p_partkey ) AS one_level ORDER BY one_level.p_brand LIMIT 20 ) AS two_level LEFT JOIN orders o ON two_level.c_custkey = o.o_orderkey ) twice_join ORDER BY twice_join.c_nationkey limit 10;
TPCH 100G olap table
TPCH 1T olap table
select * from ( select * from ( SELECT * FROM ( SELECT c.*, p.p_name, p.p_brand FROM customer c RIGHT JOIN part p ON c.c_custkey = p.p_partkey ) AS one_level ORDER BY one_level.p_brand LIMIT 20 ) AS two_level RIGHT JOIN orders o ON two_level.c_custkey = o.o_orderkey ) twice_join ORDER BY twice_join.o_orderdate limit 10;
TPCH 100G olap table
TPCH 1T olap table
TPCH 1T HIVE external table
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: