Repository navigation
Conversation
Internal second-model review: 5 rounds, 10 substantive findings, 8 agreed and fixed, 2 disagreed with evidenceAn independent model reviewed this change against the repository review guidelines, in five
1. Non-UTF-8 tail. 2. 3. 4. Setting randomization. The stateless runner randomizes 5 and 6. Answer-only assertions. This is why finding 2 was invisible. A decline returns 9. Direction D, disagreed. The finding is right that the pinned value is the wrong answer: 10. Also verified independently rather than accepted: all 21 tokenization sites in the condition |
Pre-PR validation gate
Build: One mutation, normalizing the Session id: cron:clickhouse-review-slot-8:20260801-060002 |
|
cc @shankar-iyer @tiandiwonder, could you review this? A text bloom-filter skip index tokenized a FixedString constant including its NUL padding, which the executing comparison does not compare, so the probe filter was built over tokens the granule never saw and a granule holding a matching row was pruned away. |
|
Workflow [PR], commit [79d5598] Summary: ❌
AI ReviewSummaryReviewed #112868 at Missing context / blind spots
Final VerdictStatus: ✅ Approve No required code changes identified. Existing CI and discussion gates still apply. |
PR-caused CI failures on 67c6a37, fixed in 760e3cd1.
The fix adds the arm under the same guard. It returns Verified in both directions by compiling the file against master's 2.
Session id: cron:clickhouse-maint-slot-22:20260801-114800 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 94/100 (94.00%) · Uncovered code |
CI finish ledger - 760e3cdEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260803-180000 |
|
@groeneai Please first post a minimal reproducible example for what you try to fix. |
|
Minimal example, on master CREATE TABLE t (s String, INDEX i s TYPE ngrambf_v1(3, 512, 2, 0) GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 1;
INSERT INTO t VALUES ('V0'), ('X');
SELECT count() FROM t WHERE s = toFixedString('V0', 3);
-- 0, wrong
SELECT count() FROM t WHERE s = toFixedString('V0', 3)
SETTINGS ignore_data_skipping_indices = 'i';
-- 1, correct
Cause: index analysis tokenizes the constant's raw bytes, which still carry the The same cause reaches the other predicates listed in the description; |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes25 object files changed (+150.20 KiB total), 2 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units23 translation units recompiled, 137 s compile time in total, 23 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - d527b3cEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
#117053 replaces the 171 check-runs, 0 incomplete, 1 failing. Session id: cron:our-pr-ci-monitor:20260829-170000 |
|
Dear @rschu1ze, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@Ergus If you have some time - like to check this one (low prio though). |
|
Rebasing and re-scoping as asked. Before deciding what is left I ran this branch's own fixture against today's master ( Still wrong on master, i.e. the matching granule is pruned:
Three causes: Answers correct but pruning lost, since a stripped probe is only a prefix of a fixed width value: On your four points:
|
`stripFixedStringPaddingForTerms` trims the NUL tail of a `FixedString` constant for `equals`, `notEquals`, `hasAny` and `hasAll`, which leaves three cases where a matching granule is still pruned. Measured on master 398661c against an unindexed `Log` twin holding the same rows: - the membership arms never see the trim, so `has(v, toFixedString('VALUE0', 10))` over `Array(FixedString(8))`, and `mapContainsKey`, `mapContains`, `has(mapKeys(m), ...)` and `mapContainsValue` over a `FixedString` map key or value, all return 0 where the answer is 1; - the trim is keyed on the constant's type, so `s = 'VALUE0\0\0\0\0'` over a `FixedString(8)` column, where the `String` constant carries the tail itself, returns 0; - trimming is not token preserving when the trimmed value ends inside a declared UTF-8 sequence: the gram tokenizers walk by `UTF8::seqLength` and clamp the last gram to the buffer end, so a granule holding `5545C200` is probed with `5545C2` and dropped. This one also reaches `String`, `LowCardinality(String)` and `sparse_grams` columns, and the `text` index, whose own `canStripFixedStringPadding` does not look at the trimmed value. Instead of trimming, re-encode the constant into the bytes the index stores: trim the NUL tail, then pad back to the width of the index column's domain (`FixedString(N)`, or 16 for `IPv6`); where the domain has no width, decline the index if the trimmed constant ends mid sequence. Keying it on the column rather than on the constant covers the `String` constant direction too. Exact pruning comes back with it: an `IPv6` equality reads 1 granule of 64 instead of all 64. The suffix independence of a tokenizer is now asked of `ITokenizer`, which answers false for the tokenizers whose tokens can span the end of the value: with the `array` and `splitByString` tokenizers a `text` index trimmed the constant and then searched for its own single token, which a stored `String` carrying NUL bytes does not hold, so `s = toFixedString('VALUE0', 8)` returned 0 of 1 rows there too. Both condition classes now decline on the same ground, and a constant with nothing to trim keeps reading through its index. An `IPv6` index carried a fourth case of the same shape, which master has too: `ip = '2001:db8::'` was tokenized as the characters of the literal while the granule holds the 16 parsed bytes, so the matching granule was pruned and the query returned 0 instead of 1. A textual constant is now parsed into those bytes, which also makes it prune 1 granule of 64, and a constant that does not parse declines the index. A constant wider than the domain keeps its current probe, since it equals no stored value and its own tokens prune every granule. Where the domain has no width, only the predicates comparing through the `String` supertype re-encode the constant: a membership predicate compares it byte for byte there, so its padded bytes are already the exact probe and trimming them would only read more granules. `has(<constant array>, <indexed scalar>)` does not ignore the padding, so that probe is unchanged, and a constant redirected through `mapKeys` is a map key, which is stored as written. Related: ClickHouse#117021
d527b3c to
1a9a09f
Compare
|
Rebased and re-scoped: Your four points:
Two calls I made rather than asking:
Four cases of the same shape are measured and deliberately not in this PR, each equally wrong on master today: prepared-set elements ( Validation: 60 of 60 cells green, 36 of them red on master; 20 consecutive runs of the test under randomised settings; the 265 stateless tests that use these index types pass, except four that fail identically on a master binary in this environment (missing |
`tryPrepareSetBloomFilter` stripped a `FixedString` element without checking
that the trimmed value still tokenizes to a subset of the stored value, so
`s IN (SELECT toFixedString(concat('VALUE', unhex('C2')), 8))` pruned the
granule holding `'VALUE' || unhex('C200')` on `ngrambf_v1` (String and
`FixedString(8)` columns, 1 vs 0 rows on master). The set loop now goes through
`normalizeConstantForIndexDomain` with `equals` semantics, which subsumes both
of its branches (domain conversion and padding strip), and the helper takes
whether the comparison drops the padding instead of a function name.
The `text` index `IN` path already shares `tryNormalizeNeedlePadding` with the
direct path, so both index families now apply one rule to set elements.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `IN` rows compared answers only, which a silently declined index also satisfies. Add the plan side: a `FixedString(8)` column prunes to exactly the matching granule, and the widthless `ngrambf_v1` and `text` cases decline the index. All three print 0 on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`hasAny` and `hasAll` cast only the constant to `String`, so a matching stored
element equals the trimmed constant byte for byte and tokenizes the same. The
UTF-8 tail decline is needed only where the stored value loses its zero bytes
as well (`equals`, `notEquals`, `IN`), so the helper now takes the comparison's
padding semantics instead of one flag, as the `text` index already models them.
Declining there lost the index for `hasAny(v, [toFixedString(concat('VALUE',
unhex('C2')), 8)])` over `Array(String)`, which master prunes to 1 of 64
granules; the new row flips to 0 with the old decline.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`String = FixedString` compares zero padded, so a stored `'VALUE' ||
unhex('C200')` equals `toFixedString(concat('VALUE', unhex('C2')), 6)` even
though the constant has no padding to trim. The `ngrambf_v1` decline already
covers it (1 vs 0 rows on master); add the row.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged master and re-scoped again. #118972 and master's
One case is left out on purpose. |
The PR workflow run 37642194989 on 434b2fe was dropped by the GitHub Actions outage of 2026-10-07 15:15-15:35Z (every build abandoned, dependent jobs failed on missing S3 artifacts) and was not retried. No content change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 1d305c0Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 148 check runs completed, Session id: cron:our-pr-ci-monitor:20261007-230450 |
|
Dear @Ergus, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Ergus
left a comment
There was a problem hiding this comment.
Optional follow-up, not needed here: splitByString(['\0']) and a preprocessor that keeps NUL as a separator could count as surviving, which would recover pruning there. Master already declines those for a padded needle, so the change only extends that behavior to unpadded needles.
`String = FixedString` compares zero padded, so a stored value can carry
trailing zero bytes that a full-width constant lacks, for example the
stored `VALUE C2 00` equals `toFixedString(concat('VALUE', unhex('C2')), 6)`.
`tryNormalizeNeedlePadding` declined such a needle only when it had padding
to trim, so a `text` index with `ngrams`/`sparseGrams` (when the needle ends
inside a UTF-8 sequence), `array`, `splitByString` or a preprocessor still
looked up the bare needle and could prune the only matching granule. This
matches the bloom-filter side of this PR, which already declines that case.
05223's "a needle that carries no padding" rows now expect `INDEX_NOT_USED`
for `array`, both `splitByString` variants and the preprocessor variant;
the `splitByNonAlpha` rows keep pruning. 05332 gains the full-width
`text(tokenizer = ngrams(3))` oracle row with its `Log` twin.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| break; | ||
| /// The rest either emit the whole buffer as one token or take their separators from a configured pattern, | ||
| /// which a suffix can complete, and `KeyValuePairs` tokenizes no string at all. | ||
| case ITokenizer::Type::SplitByString: |
There was a problem hiding this comment.
tokensSurviveTrailingNuls is keyed only on ITokenizer::Type, so every splitByString tokenizer is treated as suffix-sensitive. That loses a safe case: with splitByString(['\0']), world and world\0\0... still tokenize to the same single term world, so the old exact pruning was correct. The updated 05223 expectation flips that case to INDEX_NOT_USED, which means this change regresses index usage for zero-byte separators just because the helper cannot see the tokenizer's actual separators. Since the call sites already have the tokenizer instance, this needs configuration-aware logic rather than a blanket Type::SplitByString => false.
There was a problem hiding this comment.
Not changed here: the reviewer ruled this refinement an optional follow-up in #112868 (review), and its cost is lost pruning for a NUL separator, never wrong rows.
|
Dear @Ergus, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…ed-string-constant
`find_last_not_of('\0') + 1` reaches 0 for an all-NUL constant only by
wrapping `npos`, which the `unsigned-integer-overflow` check master now
enables reports as an error. `trimRight` from `Common/StringUtils.h` is
the shared helper master moved the sibling trims of this file to.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`tryPrepareSetBloomFilter` now normalizes each set element into its own
`String`, but still tokenized it with `forEachTokenToBloomFilter`. For
`tokenbf_v1` that reaches `forEachTokenSplitByBytes`, which reads whole
16-byte blocks and relies on the 15 bytes of right padding a column buffer
has. A `String` has none: a 17- to 22-byte element lives in the libc++
short-string buffer, so `s IN (SELECT repeat('a', 20))` read past the end
of the object (ASan: stack-buffer-overflow, READ of size 16).
Use `ITokenizer::stringToBloomFilter`, as the other constant probes in this
file do; it emits the same tokens and never reads past `length`.
Add a `tokenbf_v1` prepared-set row with a 20-byte element to 05332.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master now has 29 other tests with the 05332 prefix. No test on master and no open pull request uses 05866. The test content is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed too few rows being returned when a query filters a column covered by an
ngrambf_v1,sparse_gramsortextskip index with aFixedStringconstant orINelement. The probe was built from bytes the comparison ignores, so a granule holding a matching row was skipped. This covershas,mapContainsKey,mapContains,mapContainsValue, aStringconstant carrying a NUL tail, and constants that end inside a UTF-8 sequence.Description
On 26.8.18.2,
has(v, toFixedString('VALUE0', 10))over anngrambf_v1index onArray(FixedString(8))returns 0 rows instead of 1.Master's
convertConstantToIndexDomainand #118972 already cover theIPv6, typed map key and paddedtextneedle cases, so this PR keeps only the rest. Against master9f7ed316the fixture differs in 36 of 69 cells (oracle = unindexedLogtwin):has,mapContainsKey,mapContains,mapContainsValue,has(mapKeys(m), ...)with a constant wider than aFixedString(N)element, key or value: 1/0. Onlyequals,notEquals,hasAnyandhasAllwere normalized.s = 'VALUE0\0\0\0\0'onFixedString(8): 1/0, the trim was keyed on the constant's type.INelement ending inside a UTF-8 sequence, e.g.toFixedString(concat('VALUE', unhex('C2')), 8)(also at full width,6) against a stored'VALUE' || unhex('C200'), onngrambf_v1,sparse_gramsand atextindex withngramsorsparseGrams: 1/0. These tokenizers clamp the last gram to the buffer end, andString = FixedStringcompares zero padded.normalizeConstantForIndexDomainwraps master's converter: for aFixedString(N)column it trims and re-pads the constant to N; for a widthless column it declines whenequals,notEqualsorINwould probe a constant ending mid-sequence. It is used by every arm oftraverseTreeEqualsand by prepared-set elements. On thetextindex the type-onlytokenizerSplitsAtZeroBytebecomes the shared per-valuetokensSurviveTrailingNuls(asciiCJKandicukeep master's answer), and the decline no longer requires padding to trim, so05223now expectsINDEX_NOT_USEDfor a full-width needle onarray,splitByStringand a preprocessor.The fixture passes. 363 of the 367 stateless tests using these index types give output identical to master
9f7ed316; the other four are the two edited tests and two tests newer than that build, which pass. Both edited tests pass 25 randomized runs each.Workflow [PR]
Sync PR [sync-upstream/pr/112868]