Skip to content

Support partial sort fields in TopN pushdown #116043

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 6 commits into from
Nov 4, 2024

Conversation

craigtaverner
Copy link
Contributor

@craigtaverner craigtaverner commented Oct 31, 2024

The work in #112938 allowed for pushing down SORTS to Lucene even when the sort expression came from an EVAL, as long as is was possible to push it down. It laid the groundwork for partial pushdown, where if the first n expressions could be pushed down, but not all could, we should be able to push down those n expressions. Since the coordinator-node TopNExec would still exist to merge partially sorted results from data nodes, this is sufficient to also perform the final sort on partially sorted data from Lucene. This feature therefor only required removing the limitation.

Benchmark before this PR after this PR Comments
distanceSort-esql 180 180
distanceSort-esql-partial 14467.9 180
distanceFilterSort-esql 26 26
distanceFilterSort-esql-partial 5800 25

The four queries benchmarked here are:

  • distanceSort-esql
FROM osmgeopoints
| EVAL distance = ST_Distance(location, TO_GEOPOINT("POINT(7.0 55.0)")),
| SORT distance ASC
| LIMIT 10
  • distanceSort-esql-partial
FROM osmgeopoints
| EVAL distance = ST_Distance(location, TO_GEOPOINT("POINT(7.0 55.0)")),
       loc = location::string
| SORT distance ASC, loc ASC
| LIMIT 10
  • distanceFilterSort-esql
FROM osmgeopoints
 | EVAL distance = ST_Distance(location, TO_GEOPOINT(\"POINT(7.0 55.0)\")),
| WHERE distance <= 400000
| SORT distance ASC
| LIMIT 10
  • distanceFilterSort-esql-partial
FROM osmgeopoints
 | EVAL distance = ST_Distance(location, TO_GEOPOINT(\"POINT(7.0 55.0)\")),
        loc = location::string
| WHERE distance <= 400000
| SORT distance ASC, loc ASC
| LIMIT 10

Fixes #114515

@craigtaverner craigtaverner added >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL labels Oct 31, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @craigtaverner, I've created a changelog YAML for you.

@craigtaverner craigtaverner marked this pull request as ready for review November 4, 2024 16:26
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Hi @craigtaverner, I've updated the changelog YAML for you.

@craigtaverner craigtaverner added auto-backport Automatically create backport pull requests when merged v8.17.0 labels Nov 4, 2024
@craigtaverner craigtaverner requested a review from iverase November 4, 2024 17:00
@craigtaverner craigtaverner merged commit aa99392 into elastic:main Nov 4, 2024
15 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

The backport operation could not be completed due to the following error:

An unexpected error occurred when attempting to backport this PR.

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 116043

jozala pushed a commit that referenced this pull request Nov 13, 2024
* Support partial sort fields in TopN pushdown

* Update docs/changelog/116043.yaml

* Update docs/changelog/116043.yaml

* Refine physical planner tests
alexey-ivanov-es pushed a commit to alexey-ivanov-es/elasticsearch that referenced this pull request Nov 28, 2024
* Support partial sort fields in TopN pushdown

* Update docs/changelog/116043.yaml

* Update docs/changelog/116043.yaml

* Refine physical planner tests
@alex-spies
Copy link
Contributor

@craigtaverner , it looks like the backport broke and this never made it into 8.x

Should we backport this to 8.x (label says 8.17, but that doesn't look necessarily right due to the parity between 8.18 and 9.0)?

craigtaverner added a commit to craigtaverner/elasticsearch that referenced this pull request Jun 10, 2025
* Support partial sort fields in TopN pushdown

* Update docs/changelog/116043.yaml

* Update docs/changelog/116043.yaml

* Refine physical planner tests
@craigtaverner
Copy link
Contributor Author

Did the backport manually in #129199

elasticsearchmachine pushed a commit that referenced this pull request Jun 10, 2025
* Support partial sort fields in TopN pushdown

* Update docs/changelog/116043.yaml

* Update docs/changelog/116043.yaml

* Refine physical planner tests
craigtaverner added a commit to craigtaverner/elasticsearch that referenced this pull request Jun 10, 2025
…c#129199)

* Support partial sort fields in TopN pushdown

* Update docs/changelog/116043.yaml

* Update docs/changelog/116043.yaml

* Refine physical planner tests
elasticsearchmachine pushed a commit that referenced this pull request Jun 10, 2025
…9203)

* Support partial sort fields in TopN pushdown

* Update docs/changelog/116043.yaml

* Update docs/changelog/116043.yaml

* Refine physical planner tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pushdown of spatial sort-by-distance does not allow partial sorts
4 participants