(Do not review) feat: TopNRank optimization#11554
Conversation
✅ Deploy Preview for meta-velox canceled.
|
0446e51 to
153a06f
Compare
There was a problem hiding this comment.
Could you also add a test case for the logic in fixTopRank.
There was a problem hiding this comment.
@liujiayi771 : The fixTopRank logic is tested very thoroughly in the fewPartitions test. Have added a comment there.
|
@aditi-pandit So, do we need to make some abstractions in addInput here as well, to facilitate the addition of TopNStreamingRowNumber later on? |
@JkSelf : TopNRowNumber is a somewhat streaming operator in its current implementation ... It uses HashTable internally to map the input row to a partition and each partition has an accumulator that maintains the ordered rows (as many required for limit) in a priority queue. Window accumulates all the input rows and does a full sort of the input rows to demarcate into partitions and sort by order-by. So the preceding Sort was useful and we abstracted the streaming window. With TopNRowNumber, doing a full sort and then making TopNRowNumber limit to only a partition at a time, the tradeoffs are different. Have you considered removing the global sort and checking if TopNRowNumber suffices ? If we decide eventually that having a full streaming operator for topNRowNumber is useful, then it might be worth it to write a new operator itself (rather than enhance this current one). Offcourse, we can try to reuse some of the ranking logic pieces. |
@aditi-pandit I see. Thanks for your explanations. |
227f92c to
67f644d
Compare
Summary: topNRowNumber node is an optimized planNode for SQL with ranking window functions but which limits them to only the topN results. Add a TopNRowNumberFuzzer for plans with this planNode. This fuzzer is closely modeled after the RowNumberFuzzer. So the common code is abstracted to a RowNumberFuzzerBase class which is used as the parent class for both RowNumberFuzzer and TopnRowNumberFuzzer. The fuzzer generates plans only for row_number function right now. It will be enhanced to support rank and dense_rank functions after #11554 Pull Request resolved: #12103 Reviewed By: xiaoxmeng Differential Revision: D69936162 Pulled By: kagamiori fbshipit-source-id: 81214748c874f219cf7bc57b5eeeb8039325b06c
f84597c to
2aab22c
Compare
|
@ethanyzhang imported this issue into IBM GitHub Enterprise |
|
This feature is useful, and I am wondering when will this PR get merged? Seems it's been half a year since proposal. |
@HolyLow : I'm breaking this feature into smaller pieces to keep reviews moving. We have added the fuzzers needed to keep validating results for this logic now. |
Summary: The getOutputFromMemory loop first output the remainder of rows (if any) from the current partition. If there was still space on the output buffer, then it went into a loop trying to add as many partitions (some with all rows in entirety and a last partial one possibly). The code is simplified to just a loop that carries forward from the current partition to fill output rows. The loop iterates over as many partitions can be output like the one before. The priority queue in the TopNRowNumber partitions pops rows in reverse order of row number. The old code maintained a remainingRowsInPartition_ variable that was used in some odd ways to compute the 'start' rowNumber for each output block from a partition. This is not needed. The partition.rows.size() can be used simply to get the correct row numbers. Remove the un-necessary currentPartition() function as a result. ref #11554 for TopNRank enhancements to this operator. Pull Request resolved: #11440 Reviewed By: xiaoxmeng Differential Revision: D74427134 Pulled By: kagamiori fbshipit-source-id: d4e422a899db733565846e844834dd6bb408b689
|
Hi @aditi-pandit. Could you rebase the code? |
@liujiayi771 : Done. |
Summary: TopNRank comparisons require an API to return if the comparisons are <, > or =. The old APIs only returned a bool for <= or not. This is the 2nd PR towards TopNRank functionality ref #11554 Pull Request resolved: #13264 Reviewed By: bikramSingh91 Differential Revision: D76729753 Pulled By: mbasmanova fbshipit-source-id: 0a5f600530793508750d12a4d50201e9d4a50663
60bc434 to
c13136b
Compare
|
@aditi-pandit It looks like TopNRowNumberTest/MultiTopNRowNumberTest.fewPartitions/1 is broken |
|
@kevinwilfong : Thanks for looking at this PR. I've been breaking this feature into smaller PRs and trying to rebase. Will put only the minimal changes here for review after the underlying PRs make it in. Moving this to a draft state. |
812d59d to
91787f7
Compare
|
Closing in favor of #14141 which is the final piece of this PR after all the refactoring PRs linked. |
|
Failed to update imported issue: PATCH https://github.ibm.com/api/v3/repos/lakehouse/velox/issues/506: 422 Validation Failed [] |


Design doc : https://docs.google.com/document/d/1WQfNigR9bVrbM-PqY7F0mswcetN_tdNahzD9ENye-Q0/edit?usp=sharing
#9404
e2e Presto PR (with changes in the Presto optimizer as well) prestodb/presto#24138
Latency for SF1K TPC-DS Q67 fell from 399s to 146s with this change.
(I also started working on a fuzzer in #12103 which I will enhance for the rank and dense_rank functions added here).