Skip to content

feat(optimizer): Native TopNRank optimization#24138

Merged
aditi-pandit merged 2 commits intomasterfrom
topn
Feb 12, 2026
Merged

feat(optimizer): Native TopNRank optimization#24138
aditi-pandit merged 2 commits intomasterfrom
topn

Conversation

@aditi-pandit
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit commented Nov 25, 2024

Description

https://docs.google.com/document/d/1WQfNigR9bVrbM-PqY7F0mswcetN_tdNahzD9ENye-Q0/edit?tab=t.0

Motivation and Context

TPC-DS Q67

== RELEASE NOTES ==

General Changes
* Add Window filter pushdown in native engine for rank and dense_rank functions. Use session property `optimizer.optimize-top-n-rank` to enable the rewrite.

Copy link
Copy Markdown
Contributor

@BryanCutler BryanCutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just a couple questions

@JsonProperty("rankingType") RankingFunction rankingFunction,
@JsonProperty("rowNumberVariable") VariableReferenceExpression rowNumberVariable,
@JsonProperty("maxRowCountPerPartition") int maxRowCountPerPartition,
@JsonProperty("maxRowCountPerPartition") int maxRankPerPartition,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the json property be changed too or is that not possible without breaking compat?

// Write config file
String configProperties = format("discovery.uri=%s%n" +
"presto.version=testversion%n" +
"native-execution-enabled=true" +
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need a %n? I'm guessing that's to give it a newline but not sure

@steveburnett
Copy link
Copy Markdown
Contributor

Thank you for the release note! Some nits of phrasing and formatting suggestions.

== RELEASE NOTES ==

Prestissimo (Native Execution) Changes
* Improve Window filter pushdown in Prestissimo engine for ``rank`` and ``dense_rank`` functions. :pr:`24138`

@steveburnett
Copy link
Copy Markdown
Contributor

One more nit about the release note entry: we've automated the link to the PR so you don't have to add it manually anymore.

== RELEASE NOTES ==

Prestissimo (Native Execution) Changes
* Improve Window filter pushdown in Prestissimo engine for ``rank`` and ``dense_rank`` functions. 

@aditi-pandit aditi-pandit force-pushed the topn branch 2 times, most recently from 35f18b2 to 4b96592 Compare March 25, 2025 20:06
meta-codesync bot pushed a commit to facebookincubator/velox that referenced this pull request Oct 29, 2025
Summary:
Design doc : https://docs.google.com/document/d/1WQfNigR9bVrbM-PqY7F0mswcetN_tdNahzD9ENye-Q0/edit?usp=sharing

https://github.com/facebookincubator/velox/discussions/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.

Pull Request resolved: #14141

Reviewed By: pratikpugalia

Differential Revision: D85763891

Pulled By: kevinwilfong

fbshipit-source-id: 122bc6d60a4cfbf90c7921ebb1df28ef6edcc0a0
@psantos-denodo
Copy link
Copy Markdown

Hi! it looks this is ready to merge, just missing one failing check, is that right? if that's the case could you re-run it? it looks this feature can make a significant improvement and it would be great to merge it soon :)

@kaikalur
Copy link
Copy Markdown
Contributor

Hmm - looks like we already have: optimize_top_n_row_number that does it in the plan? What is this for?

@aditi-pandit
Copy link
Copy Markdown
Contributor Author

Hi! it looks this is ready to merge, just missing one failing check, is that right? if that's the case could you re-run it? it looks this feature can make a significant improvement and it would be great to merge it soon :)

Hi @psantos-denodo : I have one failure to debug and will prioritize submitting this change.

@aditi-pandit
Copy link
Copy Markdown
Contributor Author

Hmm - looks like we already have: optimize_top_n_row_number that does it in the plan? What is this for?

@kaikalur : optimize_top_n_row_number was only for queries with row_number. This PR added support for rank and dense_rank window functions pushdown in that same operator. This had Velox runtime code changes as well. The Velox team wanted to disable the optimization by default (optimize_top_n_row_number is true) and so I added a new config for it.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 23, 2026

Codenotify: Notifying subscribers in CODENOTIFY files for diff fc589a5...a43be71.

No notifications.

@tdcmeehan tdcmeehan self-assigned this Jan 23, 2026
Copy link
Copy Markdown
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aditi-pandit, a couple of little nits.

@aditi-pandit aditi-pandit force-pushed the topn branch 2 times, most recently from 3660237 to 6303d65 Compare February 1, 2026 23:55
@aditi-pandit aditi-pandit changed the title feat(optimizer): Native TopNRank optimization feat(optimizer): Native TopNRank optimization (needs Velox fix) Feb 2, 2026
@aditi-pandit
Copy link
Copy Markdown
Contributor Author

Submit only after facebookincubator/velox#16190 is updated in Velox submodule.

@aditi-pandit
Copy link
Copy Markdown
Contributor Author

Hi! it looks this is ready to merge, just missing one failing check, is that right? if that's the case could you re-run it? it looks this feature can make a significant improvement and it would be great to merge it soon :)

Hi @psantos-denodo : I have one failure to debug and will prioritize submitting this change.

Hi @psantos-denodo : I have debugged the failure and have the fix in facebookincubator/velox#16190. We can submit this PR after that one is merged in Velox and the module updated.

@psantos-denodo
Copy link
Copy Markdown

Hi! it looks this is ready to merge, just missing one failing check, is that right? if that's the case could you re-run it? it looks this feature can make a significant improvement and it would be great to merge it soon :)

Hi @psantos-denodo : I have one failure to debug and will prioritize submitting this change.

Hi @psantos-denodo : I have debugged the failure and have the fix in facebookincubator/velox#16190. We can submit this PR after that one is merged in Velox and the module updated.

That's great news, thanks for sharing!

@aditi-pandit aditi-pandit changed the title feat(optimizer): Native TopNRank optimization (needs Velox fix) feat(optimizer): Native TopNRank optimization Feb 11, 2026
@aditi-pandit
Copy link
Copy Markdown
Contributor Author

aditi-pandit commented Feb 11, 2026

@hantangwangd @aaneja @tdcmeehan : This PR is finally clean.

Would be great to have a round of review.

Really appreciate the help.

Copy link
Copy Markdown
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! (docs)

Copy link
Copy Markdown
Member

@hantangwangd hantangwangd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aditi-pandit, lgtm!

@aditi-pandit aditi-pandit merged commit ff462d8 into master Feb 12, 2026
124 of 126 checks passed
@aditi-pandit aditi-pandit deleted the topn branch February 12, 2026 00:50
@aditi-pandit
Copy link
Copy Markdown
Contributor Author

Thanks @hantangwangd for all the detailed reviews.

kevintang2022 pushed a commit that referenced this pull request Feb 17, 2026
## Description

https://docs.google.com/document/d/1WQfNigR9bVrbM-PqY7F0mswcetN_tdNahzD9ENye-Q0/edit?tab=t.0

## Motivation and Context
TPC-DS Q67

```
== RELEASE NOTES ==

General Changes
* Add Window filter pushdown in native engine for rank and dense_rank functions. Use session property `optimizer.optimize-top-n-rank` to enable the rewrite.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants