Repository navigation
Conversation
… filter With `apply_string_filters_during_scan` (on by default since ClickHouse#124507), `PlainStringDecoder::decode` checked a substring condition with one `StringValueFilter::match` per value, i.e. one dispatched `sz_find` call per value. For short values the per-call setup dominates, so the pushed-down check could cost more than the copy it saves (most visibly with the AVX2/NEON search kernels). MergeTree already scans a whole buffer once with `StringValueFilter::findBulkScanMatches`. `decodeWithBulkScan` does the same for a PLAIN page when every value of the decode call is read: it walks the 4-byte length prefixes of a batch, runs one `findBulkScanMatches` over the batch bytes (values together with their prefixes), replaces each run of values without the needle with one `insertManyDefaults`, and checks the found values against the other conditions of the filter. The bulk path is used only when the needle of the bulk-scanned condition (the longest substring needle of the filter) has at least 4 bytes and no zero byte. The last byte of a length prefix is zero for a value below 16 MiB, so such a needle cannot start in the prefix of such a value: every found value contains the needle and no value is searched twice. A found value of at least 16 MiB is re-checked against all conditions. Filters with a shorter or zero-containing longest needle keep the per-value check. The first batch of a page has 128 values; when more than 1/8 of the values of a batch contain the needle, the rest of the page goes through the per-value loop, since every found value restarts the scan. Closes ClickHouse#126663 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Results with apply_string_filters_during_scan 0 and 1 on plain pages, including length prefixes that contain the needle bytes, and the exact number of replaced values for the two needles that only the length prefixes spell: a one-byte needle equal to the low byte of every 103-byte value's length prefix, and a needle with zero bytes equal to the prefix of the values 'zz' (all 6000 values must be replaced in both cases, as with the per-value check). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pages A 20M-row Parquet file with one PLAIN-encoded String column (no dictionary), queried with substring filters that apply_string_filters_during_scan pushes into the scan: a rare needle (`%google%`), a rare needle together with a second condition (`%google%` AND `%site1%`), a needle found in about 15% of the values (`%/news%`) and a needle found in every value (`%example%`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…checks 16 MiB values The replaced count of the `LIKE '%needle%'` query is now exact (with one thread): values decided by the bulk scan do not count towards the minimum size of skipped values, so the filter stays applied to every value, while checked one by one these short values turn it off after 8192 checks per row group. The previous `> 0` check passed without the bulk scan as well. A third file has a value of exactly 16 MiB, whose length prefix ends with the first byte of the needle `'\x01xxx'`. The scan finds the needle there and only the re-check of values of at least 16 MiB rejects it, so all 3 values must be replaced. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he other conditions A value found by the scan is checked against the remaining conditions of the filter; PREWHERE re-evaluates the whole condition, so a missing re-check does not change the query result. Log a compound `LIKE '%needle%' AND LIKE '%1%'` query and pin its replaced count: 198102 = 197310 values without the needle plus 792 found values without '1'. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…AIN string pages With a page index, a column of a later PREWHERE step is decoded one row range at a time, often a single row. The bulk scan exempts its values from the minimum size of skipped values, so the filter stayed applied to every short value there, while the per-value check turns it off. Decode calls of fewer than 128 values now keep the per-value check; the test pins this and the 16 MiB re-check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove the comments on the bulk scan members and the probe batch size, and shorten the doc comment of decodeWithBulkScan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings over 4 rounds, the last round found none) plus my own review of each round.
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261020-001700 |
|
cc @al13n321 @grantholly-clickhouse, could you review this and add the |
|
Workflow [PR], commit [0a845dd] Summary: ❌
AI ReviewSummaryPR #126862 batches substring searches over Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested and no inline findings to post. |
clang-tidy readability-container-contains (Build (arm_tidy)) rejects `find(...) == npos`. Same semantics. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bulk scan of a page falls back to the per-value check once more than 1/8 of a batch contains the needle. With 17 of the first 128 values, the rest of the page is checked one by one and the filter turns itself off after 8320 checks; with 16 of every 128 values, all 40000 values are bulk-scanned and the 34992 without the needle are replaced. Removing the fallback, `* 5`, `* 9`, `>=` and skipping the first batch each make the test fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units314 translation units recompiled, 3177 s compile time in total, 313 of them have a recent master baseline. |
CI finish ledger - 0a845ddEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261021-100006 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Substring filters (
LIKE '%...%',position) pushed into the scan ofPLAIN-encodedStringcolumns of Parquet files now search a batch of values at once instead of every value separately, as forMergeTree. Closes #126663.Description
Closes #126663. Analysis and first patch: @ snelheidai; I narrowed where it applies and measured on x86.
Cost. Since #124507 made
apply_string_filters_during_scanthe default,PlainStringDecoder::decodechecks a substring condition with one dispatchedsz_findper value. With StringZilla's AVX2 kernel, master's Q21 uses 14-15% more CPU with the setting than without.Change. The decoder runs one
findBulkScanMatchesover a batch of values with their 4-byte length prefixes, inserts defaults for runs without the needle and checks found values against other conditions. This applies only when the longest substring needle has at least 4 bytes and no zero byte, so no occurrence can start in the length prefix of a value below 16 MiB; found values of 16 MiB or more are re-checked. A page starts with a 128-value batch; once more than 1/8 of a batch is found, the rest of the page is checked per value. Decodes with a row filter or of fewer than 128 values (as after anotherPREWHEREstep),DELTA_*pages and shorter or zero-containing needles keep the per-value check.Validation. Xeon 6975P-C, Release, 100 ClickBench files, 4 threads, paired CPU time, 95% CI: Q21 / Q22 take 0.66 [0.65, 0.67] / 0.71 [0.70, 0.72] of master with the AVX2 kernel (built without AVX-512, as on AMD Zen 3) and 0.91 / 0.92 with the default AVX-512 kernel (the issue: 0.63-0.70 with NEON, 0.91-0.94 with SVE on Graviton3). Short needles, mostly matching values, no substring filter: no change beyond noise (an identical-binary A/A arm reached +4.5%), except
%example%of the new performance test (every value matches): CPU +2.1% [+0.1%, +4.2%], and 256-row ranges after anotherPREWHEREstep: +1.3% [-0.1%, +2.7%]. Results match in the issue's 138 differential checks and the new test05407_string_filters_during_scan_parquet_plain_bulk_scan;parquet/string_filterstateless tests behave as on master; ASan clean.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126862]