-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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] window function optimization, support rank (5) #6120
[Enhancement] window function optimization, support rank (5) #6120
Conversation
4d8a682
to
61c6691
Compare
61c6691
to
1ab5b49
Compare
ce724dc
to
c83c56e
Compare
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/TopNType.java
Show resolved
Hide resolved
@@ -23,45 +24,55 @@ public class LogicalTopNOperator extends LogicalOperator { | |||
private final List<Ordering> orderByElements; | |||
private final long offset; | |||
private final SortPhase sortPhase; | |||
private final TopNType topNType; |
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.
I think this name is confusing, because the ROW_NUMBER, RANK and DENSE RANK are actually wundow functions, not TopNType.
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.
Actually, it will truely effect the behavior of topn, I've considered LimitType
and TopNType
, and TopNType
is choosed finally. Do you have any naming suggestion?
bfa3a7b
to
ec3af72
Compare
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/TopNType.java
Show resolved
Hide resolved
55d4418
to
f139873
Compare
f139873
to
bab17bb
Compare
[FE PR Coverage check]😍 pass : 50 / 54 (92.59%) file detail
|
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/logical/LogicalTopNOperator.java
Show resolved
Hide resolved
Signed-off-by: amber-create <yangyanping@starrocks.com>
Signed-off-by: amber-create <yangyanping@starrocks.com> (cherry picked from commit 4a5e6e3) Co-authored-by: amber-create <48005258@qq.com>
Signed-off-by: amber-create <yangyanping@starrocks.com> (cherry picked from commit 4a5e6e3) Co-authored-by: amber-create <48005258@qq.com>
Signed-off-by: amber-create <yangyanping@starrocks.com> (cherry picked from commit 4a5e6e3) Co-authored-by: amber-create <48005258@qq.com>
What type of PR is this:
Which issues of this PR fixes :
Fixes #5885
Enhancement
For rank window function, including
rank
、dense_rank
、row_number
, if it has a related predicate (rk < 5
), then it can be optimized by inserting aPartitionTopN
operator before theSort
operator of window function.The main purpose of
PartitionTopN
is to filter data, and it's output still remain unordered. It consists of three components:partitioner
:Divide the input chunk based on the partition exprssorter(topn)
:Each partition has an instance of sorter and is sorted independentlygather
:fetch chunks from all sorters into one data stream, so the data is still unordered after gahtering. Moreover, gather is a only logical concetp, not an actual componentThe implementation on the optimizer and the executor is a little different:
{Logical/Physical}PartitionTopNOperator
but reuse the existing{Logical/Physical}TopNOperator
by adding a new fieldpartitionByExprs
to record the partition by information. Besides, we need to pay attentation to the following things:LocalPartitionTopN{Sink/Source}Operator
, and we may use different implementation based on the fieldpartitionByExprs
partitionByExprs
is unset or empty, then the original pair ofPartitionSortSinkOperator/LocalMergeSortSourceOperator
is usedpartitionByExprs
is not empty, then pair ofLocalPartitionTopN{Sink/Source}Operator
is usedTasks
row_number
rank
(this pr)dense_rank
Performance Improvement of this pr
test Info
test sql
test result