Repository navigation
Decline a text-index lookup that cannot cover a padded needle - #118972
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.
|
Workflow [PR], commit [a7877f0] Summary: ✅
AI ReviewSummaryThis PR fixes Missing context / blind spots
Findings
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit a7877f0.
Changed lines: Changed C/C++ lines covered: 104/110 (94.55%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units31 translation units recompiled, 304 s compile time in total, 31 of them have a recent master baseline. |
…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]>
|
@ahmadov Could you review this PR please? |
- 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.
|
@alexey-milovidov @ahmadov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Cherry pick #118972 to 26.8: Decline a text-index lookup that cannot cover a padded needle
Cherry pick #118972 to 26.9: Decline a text-index lookup that cannot cover a padded needle
Backport #118972 to 26.8: Decline a text-index lookup that cannot cover a padded needle
Backport #118972 to 26.9: Decline a text-index lookup that cannot cover a padded needle
Master now carries its own index-domain conversion for the bloom filter text index (`convertConstantToIndexDomain` plus `const_source_type` on the `mapKeys` redirects) and a rewritten `FixedString` needle normalization for the `text` index (ClickHouse#118972). Both supersede parts of this branch, so this merge keeps master's code and re-applies only the cases that still fail on it: - `normalizeConstantForIndexDomain` now wraps master's converter and only adds the width of a `FixedString` column (trim, then re-pad to N) and the decline for a widthless column whose trimmed constant ends inside a UTF-8 sequence. It is applied to `has`, `mapContainsKey`, `mapContains`, `mapContainsValue`, `hasAny` and `hasAll`, which master leaves unnormalized, and to `equals` / `notEquals` in place of the bare conversion. The `IPv6` text parser and the redirected-map-key flag are dropped: master's conversion handles both. - The `text` index replaces its type-only `tokenizerSplitsAtZeroByte` with the shared per-value `tokensSurviveTrailingNuls`, so `ngrams` and `sparseGrams` decline a stripped needle that ends mid-sequence (both the direct and the `IN` path go through `tryNormalizeNeedlePadding`). `asciiCJK` and `icu` keep master's answer: asciiCJK drops a sequence cut by the buffer end and icu emits word tokens only, measured identical to master. - The padding helpers stay in the anonymous namespace, as on master, since the `text` index no longer has its own copy. The test moves to the free 05332 prefix, loses the three IPv6 spelling rows that only exercised master's parser, and gains a `text` `IN` row. On the master snapshot 29 of its 59 cells differ; all pass on this branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A
FixedStringneedle compared withequalsorINdrops the trailing zero bytes of both sides, so it matches aStringvalue spelled with any number of trailing zero bytes, and a term-preserving tokenizer (array, orsplitByStringwith a separator that does not contain the zero byte) stores every spelling as a different term. #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.The needle is now spelled the way the index stores a value that compares equal to it, decided on the concrete tokenizer instance with its pre- and postprocessor rather than on the tokenizer kind:
Stringcolumn,equalsorIN: the stripped needle is tokenized next to its padded spellings, and stripping is sound when its terms survive in them, sinceequalsonly requires all needle terms to be present in the granule.splitByString(['\0']),splitByNonAlphaandngramskeep pruning;arrayandsplitByString([','])cannot cover the spellings with one lookup and decline the atom, only when the needle really carries padding, so ordinary needles keep their pruning.Stringcolumn,hasAnyorhasAll: these cast the needle toString, which drops its padding, and compare the value as it is, so only the stripped spelling matches and one lookup always covers it.FixedString(N)column: the values and their terms are stored padded to N while the comparison strips both sides, so the only matching value is the stripped needle re-padded to N. Before this change the needle was looked up as typed, and a plainStringneedle or aFixedStringneedle of another width silently dropped the matching rows (s = 'hello'on aFixedString(6)column with thearraytokenizer returned nothing). A needle longer than the column declines the index.The
INset path follows the same rule. The test asserts pruning versus declining withforce_data_skipping_indices.Closes: #118669
Related: #117314
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
textindex dropping matching rows when aFixedStringis involved in the comparison: a term-preserving tokenizer over aStringcolumn lost the rows whose value carries literal trailing zero bytes when the search constant is aFixedString, and an index over aFixedStringcolumn lost all matching rows for aStringconstant or aFixedStringconstant of another width.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/118972]
Version info
26.10.1.459-master(included in26.10and later)26.9.12.5,26.8.19.7