Skip to content

Conversation

@kanoshiou
Copy link
Contributor

This PR extends the PropagateEmptyRelation optimizer rule to handle StubRelation nodes with empty output, in addition to the existing LocalRelation support.

Previously, when using INLINE STATS after dropping all fields (such as ROW a = 12 | drop a | inline stats b = count(*)), the optimizer would create a StubRelation with empty output but fail to properly optimize aggregations over it. The PropagateEmptyRelation rule now checks for both LocalRelation with empty supplier and StubRelation with empty output, allowing correct optimization of aggregations in these scenarios.

Closes #136851

@elasticsearchmachine elasticsearchmachine added v9.3.0 needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team labels Oct 22, 2025
# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

Thanks @kanoshiou

As I already commented here, this problem is a consequence of #133405

IMHO the best approach to solve the problem is to properly support this case (ie. pages with no blocks) in the aggregator function, rather than trying to change the plan.

I'm working to a different fix already, so I guess this PR can be closed (sorry, I know you spent quite some time on this, and the basic reproducer you posted on the issue was really helpful, I really appreciated it)

;

b:long
0
Copy link
Contributor

Choose a reason for hiding this comment

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

This should return 1, see comment above

@kanoshiou
Copy link
Contributor Author

@luigidellaquila No worries at all! Thanks for taking the time to review this PR and for the kind words — I’m glad the reproducer was helpful. I’ll go ahead and close this PR.

@kanoshiou kanoshiou closed this Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor Pull request authored by a developer outside the Elasticsearch team needs:triage Requires assignment of a team area label v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ES|QL: ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

3 participants