Repository navigation
Cherry pick #118972 to 26.9: Decline a text-index lookup that cannot cover a padded needle - #123997
Merged
Merged
Conversation
A `FixedString` needle compares equal to a `String` value both with and without its trailing zero bytes, and a term-preserving tokenizer (`array`, or `splitByString` with a separator that does not contain the zero byte) stores those two spellings as two different terms. #117314 strips the needle's padding before extracting the search terms, which fixed the plain row (#117021) and moved the loss onto the row whose own value carries literal zeros: the index looked up a term that granule never stored and pruned it, so the query returned fewer rows than the same query with `use_skip_indexes = 0`. No single lookup covers both spellings, so a needle that really carries padding now leaves the index unusable for that atom, which is what the `FixedString`-column case already did. The decision becomes explicit: strip for a tokenizer that treats the zero byte as a separator, keep the padding for a `FixedString` column whose terms carry it too, and decline for the term-preserving-over-`String` combination - and only when the needle actually has padding to strip, so ordinary needles keep their pruning. The `IN`-set path, which strips per element, follows the same rule.
…es a matching value
The padding decision was keyed on `ITokenizer::Type`, which is too coarse for
parameterized tokenizers: `splitByString(['\0'])` tolerates the padding while
`splitByString([','])` does not, and both fell into one bucket. The decision
now runs on the concrete tokenizer instance with its pre- and postprocessor:
the stripped needle is tokenized next to its padded spellings (one trailing
zero byte and the padding it really carries), and stripping is sound when the
terms of the stripped needle survive in the padded spellings, since `equals`
only requires all needle terms to be present in the granule. This keeps
`ngrams` pruning too, whose grams of a prefix are grams of the whole.
Probing the comparison semantics along the way corrected two assumptions:
- `equals` and `IN` with a `FixedString` on either side drop the trailing
zeros of both sides, so a `String` value spelled with any number of trailing
zero bytes matches, not just two spellings. `hasAny` and `hasAll` instead
cast the needle to `String`, which drops its padding, and compare the value
as it is, so only the stripped spelling matches and one lookup always
covers it; they no longer decline.
- A `FixedString(N)` indexed column stores every value padded to N, and so do
its terms, but the comparison strips both sides, so the only value that
compares equal to a needle is the needle without its own padding re-padded
to N. The previous code kept the needle as typed, which looked up a term
the index never stored for a plain `String` needle or a `FixedString` needle
of another width and silently dropped the matching rows:
FixedString(6) column, tokenizer = array
s = 'hello' truth [1,3] with the index []
s = toFixedString('hello', 10) truth [1,3] with the index []
The needle is now re-padded to the column width, and a needle longer than
the column declines the index. The `IN` set path follows the same rule and
derives the element type from the set column.
The regression test now builds the index on the `Array(String)` column so the
`hasAny` and `hasAll` predicates really reach it, asserts pruning versus
declining with `force_data_skipping_indices`, and covers `splitByString` with
and without the zero byte as a separator, the `FixedString` column with
`String`, same-width, wider and too-long needles, and `Array(FixedString)`.
Renumbered to 05223 since 05167 was taken on master.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
- Add FixedStringPaddingSemantics and FixedStringNeedleContext data structures to make the implementation simpler. - Rename functions to match ClickHouse naming style.
We might need to modify the internal data of `FixedString`, however for other cases we can avoid copy.
…18669 Decline a text-index lookup that cannot cover a padded needle
…onflicts Conflicts in `MergeTreeIndexConditionText.cpp`: - `traverseMapElementKeyNode`: take the release branch version, which reads the key via `tryGetConstant` (the cherry-picked change only reordered the code it replaces). - `tryPrepareSetForTextSearch`: take the new `FixedString` padding normalization, but detect a `FixedString` set on `set_column_values` (the non-nullable nested column), as on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Original pull-request #118972
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job