ESQL: Be careful with duplicate doc ids#142055
Merged
nik9000 merged 1 commit intoelastic:mainfrom Feb 7, 2026
Merged
Conversation
ESQL's `DocVector` is *fine* having duplicate doc ids inside it. Except some consumers aren't! It's much easy to optimize some of the loaders if there aren't any duplicate docs ids. This adds a flag, `mayContainDuplicates` to `DocVector`. When it's `false` we `assert` that there aren't any duplicate docs. When it's `true` we allow duplicates. Callers that need to optimize can check if before running the no-dups-path. While building this I consolidated a bunch of the ctor calls for `DocVector` into a pattern like this: ``` new DocVector(refCounteds, shards, segments, docs, DocVector.config().mayContainDuplicates() ) ``` `config()` handles all of the optional parameters builder-style. While doing this I noticed that `ResultBuilderForDoc` didn't track it's memory! It should! So I wrote a `DocVector.FixedBuilder` class and plugged it in. It's easier to use than what we had and it tracks memory.
Collaborator
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
nik9000
commented
Feb 6, 2026
| throws E { | ||
|
|
||
| public static ByteSizeValue findBreakerLimit(ByteSizeValue tooBigToBreak, CheckedConsumer<ByteSizeValue, Exception> c) | ||
| throws Exception { |
Member
Author
There was a problem hiding this comment.
Made it easier to find a bug.
| * TODO: pass BlockFactory | ||
| */ | ||
| Block filter(int... positions); | ||
| Block filter(int... positions); // TODO mayContainDuplicates |
Member
Author
There was a problem hiding this comment.
In a follow-up I'll deal with duplicates here. Right now you can write 1, 1, 1 and it'll contain duplicates. This should be a parameter we pass in.
| @Override | ||
| public void close() { | ||
| // TODO Memory accounting | ||
| builder.close(); |
Member
Author
|
@parkertimmins , I didn't plug this into the values reader, but figured this was enough for a Friday afternoon. |
nik9000
added a commit
to nik9000/elasticsearch
that referenced
this pull request
Feb 8, 2026
As of elastic#142055 we track when `DocVector` contains duplicates. In that PR we said "if you call `filter`, then the result may contain duplicates." This PR adds a flag to `filter` saying "the result of this `filter` may contain duplicates." It's quite common for `filter` calls not to create duplicates and most callers can pass `false`. That'll allow block loaders that follow these `filter` calls to use faster paths.
nik9000
added a commit
that referenced
this pull request
Feb 9, 2026
As of #142055 we track when `DocVector` contains duplicates. In that PR we said "if you call `filter`, then the result may contain duplicates." This PR adds a flag to `filter` saying "the result of this `filter` may contain duplicates." It's quite common for `filter` calls not to create duplicates and most callers can pass `false`. That'll allow block loaders that follow these `filter` calls to use faster paths.
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.
ESQL's
DocVectoris fine having duplicate doc ids inside it. Except some consumers aren't! It's much easy to optimize some of the loaders if there aren't any duplicate docs ids.This adds a flag,
mayContainDuplicatestoDocVector. When it'sfalseweassertthat there aren't any duplicate docs. When it'struewe allow duplicates. Callers that need to optimize can check if before running the no-dups-path.While building this I consolidated a bunch of the ctor calls for
DocVectorinto a pattern like this:config()handles all of the optional parameters builder-style.While doing this I noticed that
ResultBuilderForDocdidn't track it's memory! It should! So I wrote aDocVector.FixedBuilderclass and plugged it in. It's easier to use than what we had and it tracks memory.