Skip to content

[ESQL] Prune redundant stats groupings - #150030

Merged
costin merged 4 commits into
elastic:mainfrom
costin:esql/prune-redundant-agg-groupings
May 28, 2026
Merged

costin merged 4 commits into
elastic:mainfrom
costin:esql/prune-redundant-agg-groupings

Conversation

@costin

@costin costin commented May 27, 2026

Copy link
Copy Markdown
Member

Remove constant and conservative external-derived grouping keys from
STATS hash aggregation while rebuilding their output columns above the
aggregation. This reduces unnecessary grouping width without changing
parent-visible output.

Developed with AI-assisted tooling

costin added 2 commits May 27, 2026 23:15
Remove constant and conservative external-derived grouping keys from
STATS hash aggregation while rebuilding their output columns above the
aggregation. This reduces unnecessary grouping width without changing
parent-visible output.

Developed using AI-assisted tooling
Remove constant and conservative external-derived grouping keys from
STATS hash aggregation while rebuilding their output columns above the
aggregation. This reduces unnecessary grouping width without changing
parent-visible output.

Developed using AI-assisted tooling
@costin
costin requested a review from bpintea May 27, 2026 20:36
@costin
costin enabled auto-merge (squash) May 27, 2026 20:36
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 27, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

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

@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

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

@github-actions

github-actions Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

⏳ Building and deploying preview... View progress

This comment will be updated with preview links when the build is complete.

@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

@bpintea
bpintea disabled auto-merge May 28, 2026 08:18

@bpintea bpintea left a comment

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.

LG, but let's add integration tests too and also test with on 0 columns and/or 0 rows, make sure we're not changing the corner cases semantics.

}

private static boolean isSafeIntegralAttribute(Attribute attribute) {
return attribute.dataType() == INTEGER || attribute.dataType() == LONG;

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.

We don't have an isIntegral into DataType -- should we add it? In case we'll push the new integral blocks through.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added DataType.isIntegral(...) and switched the pruning rule to use it.

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.

Let's add more tests with just constants, one, or two, eval or not (| EVAL a = 1 | STATS c = COUNT(*) BY a), recursed aliasing (| EVAL a = ClientIP - 1, b = a - 1 | STATS c = COUNT(*) BY ClientIP, b)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added unit coverage for all-constant groupings and recursive alias pruning.

@costin

costin commented May 28, 2026

Copy link
Copy Markdown
Member Author

Added REST coverage for constant grouping semantics with rows, zero rows, and zero-column input.

@costin
costin force-pushed the esql/prune-redundant-agg-groupings branch from 25e5ca3 to 718fa04 Compare May 28, 2026 11:52
@costin
costin force-pushed the esql/prune-redundant-agg-groupings branch from 718fa04 to 0241726 Compare May 28, 2026 12:28
@costin
costin merged commit 4472237 into elastic:main May 28, 2026
39 of 40 checks passed
@costin
costin deleted the esql/prune-redundant-agg-groupings branch May 28, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >enhancement ES|QL|DS ES|QL datasources Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants