Skip to content

Push contains binary doc values query down to es819 codec - #143898

Merged
parkertimmins merged 9 commits into
elastic:mainfrom
parkertimmins:parker/binary-dv-contains-iterator
Mar 20, 2026
Merged

parkertimmins merged 9 commits into
elastic:mainfrom
parkertimmins:parker/binary-dv-contains-iterator

Conversation

@parkertimmins

Copy link
Copy Markdown
Contributor

This PR pushes contains-term matching down into the ES819 codec's BinaryDecoder for single-valued binary doc values fields. Instead of iterating doc-by-doc through BinaryDocValues and checking each value, the new containsIterator scans already-decompressed block data directly, avoiding per-document doc values lookups.

Also includes some cleanup: the shared TwoPhaseIterator logic used by AbstractBinaryDocValuesQuery, BinaryDocValuesContainsTermQuery, and BinaryDocValuesLengthQuery is extracted into AbstractBinaryDocValuesQuery.multiValuedIterator.

Based on #142503

For single-valued binary doc values fields, push the contains term
check into the ES819 codec's BinaryDecoder via a containsIterator.
This avoids per-document BinaryDocValues lookups by scanning the
already-decompressed block data directly.

Extract multiValuedIterator into AbstractBinaryDocValuesQuery for
reuse across BinaryDocValuesContainsTermQuery and
BinaryDocValuesLengthQuery.

Made-with: Cursor
Test the BinaryDecoder.containsTermIterator directly via the
ES819BinaryDocValues.containsIterator method, verifying nextDoc,
advance, and no-match exhaustion. Also fix
SlowCustomBinaryDocValuesWildcardQueryTests to use indexed numeric
doc values fields so the DocValuesSkipper is available.

Made-with: Cursor
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

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

@parkertimmins

Copy link
Copy Markdown
Contributor Author

Buildkite benchmark this with clickbench-columnar-mode please

@parkertimmins
parkertimmins requested a review from martijnvg March 9, 2026 23:28

@martijnvg martijnvg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! I left a few comments and let's run benchmark again to see what q22 does.

Comment thread server/src/main/java/org/elasticsearch/index/mapper/BlockLoader.java Outdated
@parkertimmins

Copy link
Copy Markdown
Contributor Author

Buildkite benchmark this with clickbench-columnar-mode please

@parkertimmins parkertimmins self-assigned this Mar 10, 2026
@parkertimmins

Copy link
Copy Markdown
Contributor Author

Buildkite benchmark this with clickbench-columnar-mode please

Rename containsIterator/lengthIterator to tryContainsIterator/
tryLengthIterator to follow the try* naming convention. Remove
the redundant countsSkipper.maxValue() == 1 guard in
BinaryDocValuesContainsTermQuery since the codec already only
returns an iterator for the dense single-valued case. Randomize
test values using randomUnicodeOfCodepointLengthBetween.

Made-with: Cursor
@parkertimmins

Copy link
Copy Markdown
Contributor Author

Buildkite benchmark this with clickbench-columnar-mode please

@parkertimmins

Copy link
Copy Markdown
Contributor Author

Buildkite benchmark this with clickbench-columnar-mode please

1 similar comment
@parkertimmins

Copy link
Copy Markdown
Contributor Author

Buildkite benchmark this with clickbench-columnar-mode please

@elasticmachine

elasticmachine commented Mar 13, 2026 •

Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

This build ran two clickbench-columnar-mode benchmarks to evaluate performance impact of this PR.

History

cc @parkertimmins

@martijnvg martijnvg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

@parkertimmins
parkertimmins merged commit ff3a746 into elastic:main Mar 20, 2026
36 checks passed
@parkertimmins
parkertimmins deleted the parker/binary-dv-contains-iterator branch March 20, 2026 17:43
salvatore-campagna added a commit to salvatore-campagna/elasticsearch that referenced this pull request Mar 23, 2026
Resolve conflict with elastic#143898: move tryContainsIterator and
containsTermIterator into AbstractTSDBDocValuesProducer, rename
lengthIterator to tryLengthIterator.
salvatore-campagna added a commit to salvatore-campagna/elasticsearch that referenced this pull request Mar 23, 2026
Resolve conflict with elastic#143898: keep thin ES819 producer, use
TSDBBinaryDocValues/getTSDBBinaryValues in tests.
salvatore-campagna added a commit to salvatore-campagna/elasticsearch that referenced this pull request Mar 23, 2026
Rename lengthIterator to tryLengthIterator, add tryContainsIterator
and containsTermIterator in AbstractTSDBDocValuesProducer.
michalborek pushed a commit to michalborek/elasticsearch that referenced this pull request Mar 23, 2026
…3898)

This PR pushes contains-term matching down into the ES819 codec's BinaryDecoder for single-valued binary doc values fields. Instead of iterating doc-by-doc through BinaryDocValues and checking each value, the new containsIterator scans already-decompressed block data directly, avoiding per-document doc values lookups.

Also includes some cleanup: the shared TwoPhaseIterator logic used by AbstractBinaryDocValuesQuery, BinaryDocValuesContainsTermQuery, and BinaryDocValuesLengthQuery is extracted into AbstractBinaryDocValuesQuery.multiValuedIterator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants