Skip to content

ES|QL: Don't reuse the same alias for _fork column#143909

Merged
ioanatia merged 3 commits intoelastic:mainfrom
ioanatia:fork_dont_reuse_alias
Mar 10, 2026
Merged

ES|QL: Don't reuse the same alias for _fork column#143909
ioanatia merged 3 commits intoelastic:mainfrom
ioanatia:fork_dont_reuse_alias

Conversation

@ioanatia
Copy link
Copy Markdown
Member

@ioanatia ioanatia commented Mar 9, 2026

In the initial version of FORK, only WHERE, LIMIT and SORT where allowed in subbranches - meaning FORK branches could not modify the columns.

Right now, that's no longer the case, and each FORK branch is analyzed separately - even if FORK branches are querying the same indices, we don't reuse the same attributes across FORK branches.

However for the _fork attribute we reuse the same Alias (with the same id) across FORK branches which was a remnant from the initial implementation.
This could get us into all kind of troubles, if for example, we decide to push down filters after FORK into FORK branches, similar to PushDownFilterAndLimitIntoUnionAll.

Take for example the following query:

FROM test
| FORK (where true) (where true)
| where _fork == "fork1"

this executes correctly right now, because we have an implicit LIMIT on fork branches and we don't push down filters like where _fork == "fork1" into fork bracnhes.

When we do add this optimization (PR coming soon) and we no longer have an implicit limit, because of the way constant folding works right now, we won't optimize this correctly and we might end up pushing either WHERE true or WHERE false in both of the branches.

@ioanatia ioanatia added >non-issue Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch :Search Relevance/ES|QL Search functionality in ES|QL labels Mar 9, 2026
@ioanatia ioanatia marked this pull request as ready for review March 10, 2026 11:56
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Copy Markdown
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

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

LGTM!

I think it would be good to have some unit test for checking this? So we can check that the aliases are indeed different?

@ioanatia
Copy link
Copy Markdown
Member Author

this is a good point - I think we can prioritise adding some basic golden tests for FORK - let me follow up on that.

@ioanatia ioanatia merged commit 84c3f9e into elastic:main Mar 10, 2026
36 checks passed
@ioanatia ioanatia deleted the fork_dont_reuse_alias branch March 10, 2026 13:13
szybia added a commit to szybia/elasticsearch that referenced this pull request Mar 10, 2026
…locations

* upstream/main: (126 commits)
  Update KnnIndexTester to use more settings from datasets (elastic#143869)
  fix: dynamic template vector array is overridden by automatic dense_vector mapping (elastic#143733)
  ES|QL: Don't reuse the same alias for _fork column (elastic#143909)
  Close and initialize clients after each node upgrade in logsdb rolling upgrade tests. (elastic#143823)
  ESQL: Added GroupedTopNOperator for LIMIT BY, compute only (elastic#143476)
  Handle views in ResolveIndexAction (elastic#143561)
  Improve reindex rethrottle API in stateless (elastic#143771)
  Use a copy of the SearchExecutionContext for each Percolator execution (elastic#142765)
  Log the stacktrace when we encounter a deprecation warning for `default_metric` (elastic#143929)
  ESQL: evaluate ReferenceAttributes to potentially FieldAttributes for full-text functions restriction (elastic#143893)
  Add ClusterStateSerializationStats Serializatation Tests (elastic#142703)
  Adds Coordination Diagnostics Tests (elastic#142709)
  Upgrade Elasticsearch to Apache Lucene 10.4 (elastic#141882)
  ESQL: Add configurable bracket-based multi-value support for CSV reader (elastic#143890)
  time series es819 binary dv use up to a 1mb block size (elastic#143049)
  Dynamically enable / disable plugins in correspondence to stateless mode. (elastic#142147)
  ES|QL: Implement first/last_over_time for tdigest (elastic#143832)
  Document CHANGE_POINT limitation (elastic#143877)
  Fix OperationsOnSeqNoDisabledIndicesIT (elastic#143892)
  [Test] Test that sequence numbers are not pruned with retention lease (elastic#143825)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Relevance/ES|QL Search functionality in ES|QL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants