[ESQL] Plug TopN agg groupings filtering into the language#130111
Draft
ivancea wants to merge 95 commits intoelastic:mainfrom
Draft
[ESQL] Plug TopN agg groupings filtering into the language#130111ivancea wants to merge 95 commits intoelastic:mainfrom
ivancea wants to merge 95 commits intoelastic:mainfrom
Conversation
…cs, and added it to benchmark
# Conflicts: # x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/blockhash/BlockHashTests.java
ivancea
commented
Jun 27, 2025
| aggregatorFactories, | ||
| context.pageSize(ts.estimatedRowSize()) | ||
| context.pageSize(ts.estimatedRowSize()), | ||
| context.queryPragmas().maxTopNAggsLimit() |
Contributor
Author
There was a problem hiding this comment.
Here we inject the pragma
# Conflicts: # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/mapper/Mapper.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalPlanOptimizerTests.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
# Conflicts: # x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/OrdinalsGroupingOperator.java # x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/OperatorTests.java # x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/HashAggregationOperatorTests.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/AbstractPhysicalOperationProviders.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/PhysicalPlanOptimizerTests.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/planner/TestPhysicalOperationProviders.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuation of #127148
Depends on #129633 (Bug fix)The first PR added a new
TopNBlockHashthat skips non-topN groups for specific cases (TopNafterAggregate, sharing the same attributes for groups/order).This PR plugs it into the language:
TopN+AggregatetoTopNAggregate. This is done at the very end, so other logical rules remain unchangedTopNAggregatetoTopNAggregateExecTopNis converted toLimitandSortat the beginning, here we do the same convertingTopNAggregatetoTopNandAggregateTopNAggregateExecis a child class ofAggregateExec, so most rules still apply. Some other were updatedAlso, a new pragma was added (
max_top_n_aggs_limit) to limit the maximum TopN limit after which the TopNBlockHash will be used. This is temporary until we use better index statistics.Draft
TopNAggregatecan't be serialized to older nodes. This must be fixed before merging.A potential solution could be applying the pragma at logical plan optimization level, and skip the rule there instead of at physical plan to operator conversion. However, we don't have (currently) the pragmas accesible within the rulesFuture changes
OrdinalsGroupingOperatorto use the pragma for its BlockHash, if it makes sense