Skip to content

Conversation

@bpintea
Copy link
Contributor

@bpintea bpintea commented Aug 15, 2025

This fixes a planning error leaving a Project on top of an empty LocalRelation marker unpruned. The empty EmptyRelation is added in the plan as a marker, signalling that the right hand-side of the join can be pruned entirely (and thus the entire InlineJoin).

This fixes a planning error leaving a Project on top of an empty
LocalRelation marker unpruned. The empty EmptyRelation is added in the
plan as a marker, signaling that the right hand-side of the join can be
pruned entirely (and thus the entire InlineJoin).
@bpintea
Copy link
Contributor Author

bpintea commented Aug 15, 2025

Fixes #132417 (comment)

interestingly, it fails in CsvTests, but not in EsqlSpecIT, which
accepts MIN(MV_COUNT(integer)) as both long and integer type.
@bpintea bpintea requested review from alex-spies and astefan August 18, 2025 06:06
@bpintea bpintea marked this pull request as ready for review August 18, 2025 06:06
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Aug 18, 2025
@elasticsearchmachine
Copy link
Collaborator

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

private static LogicalPlan pruneColumnsInProject(Project project, AttributeSet.Builder used) {
LogicalPlan p = project;

// A project atop a stub relation will only output attributes which are already part of the INLINEJOIN left-hand side output.
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels brittle in the sense that there may be other rules that might have a different behavior and mess up with the expected pair of steps/actions (1. transform the aggregate in a Project then 2. look for the exact combination Project -> StubRelation) this pruning expects here.

I've had such a solution in my draft PR here but eventually I changed it after reconsidering what is happening in the life of an InlineJoin (basically I considered the flow of the EsqlSession as well, because there are things that are InlineJoin specific and it expects a StubRelation to exist OR the InlineJoin to be pruned completely) and I ended up with this solution instead: https://github.com/elastic/elasticsearch/pull/132934/files#diff-4c0de47236c79e13849f81a2b9765240c822a6af6e90902ba4912f1548c65082R90-R107

Maybe explore a bit more the pruning idea based on what I mentioned above on the idea that the Project + StubRelation you are expecting there might be coming from other rules and mess up the pruning.

Copy link
Contributor Author

@bpintea bpintea Aug 19, 2025

Choose a reason for hiding this comment

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

Thanks for the review. Generally:

the Project + StubRelation you are expecting there might be coming from other rules

this simplification only happens when the plan has the pattern: InlineJoin - Project - StubRelation. It'll only be problematic if we'll ever have StubRelations on the left hand-side of the InlineJoin. But I guess the verification can be done earlier in the flow, on Aggregate/Project substitution and make the substitution less pattern-dependent.
I'll give it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@astefan, I've taken another approach, simplifying the analysis of the Aggregate iif this is part of an InlineJoin, which allows simplifying the Project analysis downstream too. I think the logic should hold irrespective of InlineJoin being currently only used for INLINESTATS or later modeling other commands too.

The case where an agg on the right hand-side of an InlineJoin was pruned
emitted unnecessary nodes in the case when only groups remained
available.
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@bpintea
Copy link
Contributor Author

bpintea commented Aug 28, 2025

Thanks, Andrei!

@bpintea bpintea merged commit 2f0010c into elastic:main Aug 28, 2025
32 of 33 checks passed
@bpintea bpintea deleted the fix/inlinejoin_prune_cols branch August 28, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants