Repository navigation
Conversation
`ColumnArray::indexImpl` built one 8-byte nested index per selected element and gathered the nested values element by element, and it reserved that scratch for every element of the whole column whatever `limit` was. A pre-pass now computes the result offsets and the number of selected elements. When the nested values are fixed-size (`isFixedAndContiguous`) and the selected rows hold at least 8 elements on average, each selected array is copied with one `insertRangeFrom`. This is the per-row copy and the break-even of `ColumnReplicated::convertToFullColumnArrayImpl` (ClickHouse#111581). Other nested types, and shorter arrays, keep the element gather, whose scratch is now reserved for the selected elements only. The decision is made in the array that holds the values, so an array of numbers inside a `Tuple`, a `Map` value or an outer `Array` is copied by range too. The selected element count is checked against `Offset` overflow and throws `TOO_LARGE_ARRAY_SIZE`, as `ColumnArray::insertManyFrom` does: an array of `Tuple()` can claim a huge size without storage, so repeated indexes could wrap the sum. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A PREWHERE condition on a sparse column yields a `Sparse(UInt8)` filter. `FilterWithCachedCount` already extracted its kept-row indices, but its constructor still expanded it to a full one-byte-per-row mask, and `filterColumns` used the indices only for a `ColumnSparse` whose offsets equal them (ClickHouse#129738); every other column was filtered with the full mask, so the cost was per row of the range instead of per kept row. WHERE (`FilterTransform` + `SparseFilterDescription`) applies the same filter by `index` to every column. `filterColumns` now takes `index` for every column when the filter is sparse; `ColumnSparse::indexImpl` still shares its values when the indices equal its offsets, so the ClickHouse#129738 case is subsumed. `FilterWithCachedCount` builds the full mask lazily, on the first `getData()` / `getColumn()` (several PREWHERE steps, zero-tail collapse, vector search), and stores the row count separately. Adds a `prewhere.xml` query with a sparse PREWHERE condition and extends `01780_column_sparse_filter` with every column kind read after such a filter. Analysis and patch by snelheidai in ClickHouse#133047. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the range-copy threshold comment to one line and drop the cross-file reference in filterColumns. 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; 3 findings) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261120-183600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261120-154400 |
|
Workflow [PR], commit [0e76c8b] Summary: ✅
AI ReviewSummaryThe PR applies selective sparse Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units402 translation units recompiled, 3162 s compile time in total, 402 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: Only one query was flagged: clickbench Q10 (MobilePhoneModel, COUNT(DISTINCT UserID) with WHERE MobilePhoneModel <> ''), which measured +16.3% slower (107 ms vs 92 ms). This query runs exactly the code the PR changes: the sparse PREWHERE filter is now kept as row indices, and columns such as UserID are filtered with index() when few rows are kept. The PR description names this query as one it speeds up, so a slowdown is the opposite of what was expected. The automatic checks hid it because 107 ms falls inside master's recent range for this query (83–115 ms). That range is wide because master's timing for this query is noisy, and the tested runs shared a machine with another benchmark, so the result is now shown as inconclusive rather than as a regression. A rerun on dedicated hardware, compared against the PR's own prewhere.xml query, would show whether the index-based filtering is actually slower for UserID on this data. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
`index` writes the kept rows to new columns, while the mask filter moves them inside the column. When a sparse filter keeps most rows of a block (a clustered condition), `index` for every column made arrays of numbers, 64-byte strings and `Tuple(UInt64, Array(UInt64))` up to 23% slower than master at 80-99% of rows kept (reported by snelheidai in ClickHouse#133047 for arrays). Keeping the mask only for top-level arrays of fixed-size values left the strings and tuples up to 16% slower. `index` is now taken when the filter keeps at most 1/8 of the rows, and always for a sparse column whose non-default rows are the kept ones (it shares the values). Otherwise the full mask is built and used as on master. perf.py, master / index for every column / this commit concurrently, ThinLTO clang-23, 4 / 16 threads: - kept fraction 5..99%: with `index` for every column, short arrays are slower from 20%, long arrays from 35%, 64-byte strings from 65%; with the 1/8 gate no case is slower than master beyond noise (50-run check of the worst cases: 0.87..1.03). All 43 ClickBench results are equal. - ClickBench Q10 0.934 / 0.948, Q11 0.921 / 0.952, `max(UserID) ... WHERE MobilePhoneModel <> ''` 0.885 / 0.906, the same as with `index` for every column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
116fc46 to
17ce759
Compare
PREWHERE filter by index to every column, as WHERE doesPREWHERE filter that keeps few rows by index, as WHERE does
Below the 1/8 gate, a sparse `PREWHERE` filter whose kept rows come in runs (a clustered condition) left short arrays of numbers slower than master's mask filter: `index` gathered arrays of fewer than 8 elements value by value through 8-byte nested indexes, while the mask filter copies whole 64-row chunks (reported by snelheidai in ClickHouse#133047). The range copy now copies each run of consecutive selected rows with one `insertRangeFrom` when the runs average at least 8 elements, not only when the rows do. `permute` takes the same path. Indexes are compared as `UInt64`, so `UInt32` indexes cannot wrap into a false run. perf.py, master / previous head / this commit concurrently, ThinLTO clang-23, 33.5M rows, `max(arraySum(a)) ... PREWHERE f != ''`, 6-12.5% of rows kept (one 512-1024-row run per granule, 8-row runs, random), 4 / 16 threads, two 50-run rounds: for `Array(UInt8)` and `Array(UInt64)` with 0-6 elements and `Array(UInt64)` with 8-12, the previous head was up to 1.06-1.09 of master, this commit 0.86-1.02 (8-row runs 0.86-0.95). Strings, numbers and tuples of scalars do not reach this code. All result hashes are equal across the three binaries. The new perf test, one thread, 3 rounds: 8-row runs 1.03 -> 0.90 of master, one 820-row run per granule 1.13 -> 0.99. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 6904564Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261121-130022 |
|
Fixing PR for Stress test (arm_release) / At its head |
…ilter-by-index # Conflicts: # src/Columns/ColumnArray.cpp
Closes: #133047
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Faster
PREWHEREwith a selective condition on a sparse column (for examples != '', also when moved there fromWHERE): when it keeps at most 1/8 of the rows of a block, the columns read after it are filtered by the indices of the kept rows, asWHEREdoes, and the filter is no longer expanded to one byte per row. Selecting rows of arrays of numbers (sparse filters, sorting) copies each run of consecutive rows at once when it holds 8 or more elements.Description
Analysis and patch by snelheidai in #133047.
A
PREWHEREcondition on a sparse column yields aSparse(UInt8)filter.FilterWithCachedCountexpanded it to a full mask for every block, andfilterColumnsused its row indices only for a sparse column with the same offsets (#129738); every other column was filtered with the mask, at a cost per row instead of per kept row.WHEREusesIColumn::index.filterColumnstakesindexwhen the filter keeps at most 1/8 of the rows, and the full mask is built only when needed. Above that the in-place mask filter is faster (indexfor arrays, strings and tuples was up to 23% slower at 80-99% kept).ColumnArray::indexcopies each run of consecutive selected rows with oneinsertRangeFromwhen the values are fixed-size and the runs average at least 8 elements (Avoiding multiple copies of data on array high order functions (Part 1) #111581 copies per row), also insideTuple/Mapand inpermute. Copying per row left short arrays after a clustered filter below 1/8 up to 13% slower than master. Other nested types keep the gather; the element count is overflow-checked.PR / master, perf.py, servers run at once, Xeon 6975P-C, 16 pinned cores, ThinLTO clang-23, 4 / 16 threads: ClickBench Q10 0.934 / 0.948, Q11 0.921 / 0.952,
max(UserID) ... WHERE MobilePhoneModel <> ''0.885 / 0.906; queries without a sparse filter 0.98 to 1.03. From 5 to 99% kept rows, random or in runs, no case is slower than master beyond noise (worst cases, 50 runs: 0.86 to 1.03). All 43 ClickBench results are equal.Tests:
01780_column_sparse_filtercompares 14 column kinds read after a sparsePREWHEREwith a table without sparse columns, on both sides of the threshold and with runs; a gtest pins the overflow check;prewhere.xmlgets the sparse query (0.918 locally);sparse_prewhere_array_runs.xmlcovers short arrays with runs (0.90 and 0.99 locally).Workflow [PR]
Sync PR [sync-upstream/pr/133292]