Repository navigation
Conversation
A Buffer table may have columns its destination lacks. Rows already flushed are read from the destination and those columns are filled on read, but the read fetched only the selected columns the destination has, evaluated the defaults over the destination's types and converted afterwards. So a default whose inputs were not selected saw type-default constants (`x DEFAULT length(arr)` read 0), a default over a column the destination stores under another type used that type (7 instead of 3 for `String` vs `Array(UInt8)`), a selected subcolumn of a missing column got its own type default, a `Nested` member got empty arrays, a filter forwarded into the destination read consumed the inputs before the fill, and a select with no column present in the destination skipped the destination entirely (`count()` returned 0). The same row read differently before and after its flush. The fill now does what `Merge` and the `MergeTree` reader do: read the inputs of the defaults (recursively, including the Buffer-only columns they depend on), an array of the `Nested` group for sizes, and the smallest column when nothing else is read; convert to the Buffer types first; fill only the selected columns and their Buffer-only dependencies; extract the subcolumns of converted and filled columns; keep what the fill reads through a forwarded PREWHERE or row-level filter. This applies at `FetchColumns` over a local destination, where the Buffer fills the columns itself; a remote destination keeps its read list. `isSubcolumnOfDefaultValue` moves to `addMissingDefaults` so both callers share it. `00910_buffer_prewhere_different_types` now returns the destination's rows for a select of a column only the Buffer has. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fill of a column missing in the destination reads the inputs of its default and a Nested size source from the destination. Their values reach the result, so a user granted only the selected columns on the destination could read another column through a Buffer DEFAULT (x DEFAULT secret). Check SELECT on those columns like on the selected ones. The smallest column read only for the row count is not checked, as for count(). 03631_buffer_access_check gains a partial-grant case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… read When no selected column exists in the destination and the fill reads no input, the destination is read through its smallest physical column only for the row count. That read had no access check, so a user whose only destination grant names a column the destination lacks (`SELECT(x)`) could read the destination's row count through the Buffer. Gate it with the planner's own rule for a row-count-only read (`checkAccessRights` with empty `column_names`, as for `count()`): SELECT must be granted on at least one existing destination column. The column that is read does not change. 03631_buffer_access_check gains the partial-grant case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sizes The row count of a row-count-only read and the sizes of a missing `Nested` member come from a destination column whose value is discarded. Both took the smallest column of all candidates, ignoring grants. A destination that re-checks the columns it reads (`Alias`) then denied a user that `count()` on it admits, and the strict check on the size source denied a user granted another array of the group, even on a plain MergeTree destination. Pick the smallest candidate among the columns `checkAccessRights` reports as readable (with empty `column_names`, as the planner does for `count()`), falling back to all candidates when none is readable, as the planner does. The at-least-one-readable-column rule still holds: the call throws. 03631_buffer_access_check gains an `Alias` row-count case and a `Nested` size-source case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rewrite the fill-inputs comment in StorageBuffer::read as a one-line invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (4 fixed, 1 declined with evidence, 3 nits)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261006-104400 |
|
Workflow [PR], commit [79601b8] Summary: ✅
AI ReviewSummaryThis PR fixes the local-destination Findings❌ Blockers
Tests
Final VerdictRequest changes: the filter path can still erase the only support column used to keep row count, so flushed rows disappear again for a realistic |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes7 object files changed (+88.67 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units14 translation units recompiled, 101 s compile time in total, 14 of them have a recent master baseline. |
CI finish ledger - 2840490Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 146 check runs completed and Session id: cron:our-pr-ci-monitor:20261007-010218 |
|
Fixing PR for the AST fuzzer 'Equal values are not contiguous' (STID 2508-32f8) failure: #124361 |
…mns-fill-over-buffer-types # Conflicts: # src/Storages/StorageMerge.cpp
Since ClickHouse#103402 a subcolumn inherits the grants of its column, and a grant on the subcolumn's own name is enough to select it and to run `count()`. Two reads of the fill still used the rules from before: - The destination columns the fill reads were checked by their raw names, so a user with SELECT(t) on the destination could select `t.a` from the Buffer but got ACCESS_DENIED for a Buffer-only column with `DEFAULT t.a`. They are now mapped with getColumnNamesForSelectAccessCheck, like the selected columns. - The column read for the row count was chosen among whole columns only, so with a grant on `j.a` alone it fell back to a column the user may not read, which an `Alias` destination then denied. It is now chosen by the planner's own chooseSmallestColumnToReadFromStorage (moved out of the anonymous namespace of PlannerJoinTree.cpp), so it is the column `count()` reads, including granted subcolumns and dynamic paths. 03631 gains both cases; each fails without its change. Also read a default input from the destination only when the name resolves to the same column there. With `j JSON, y DEFAULT j.c::UInt64` over a destination that has a column named `j.c`, the fill read that column after the flush instead of the path of `j` (9 before the flush, 0 after). The input is now read through `j`; fixture W of 05337 covers it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a destination without subcolumns Two cases where a flushed row still read differently than before the flush: - A missing `Nested` member took its sizes from a sibling chosen by the destination type. A sibling that is an array in the `Buffer` but stored as `String` in the destination was skipped (`[]` instead of `[0,0]`), and a sibling that is a `String` in the `Buffer` but an array in the destination gave sizes the `Buffer` never had (`[0,0]` instead of `[]`). Siblings are now chosen by the `Buffer` type; one the destination does not store as an array is converted to the `Buffer` type first. A destination array is still used as is, so a differing element type cannot make the read fail. - A default reading a subcolumn (`x DEFAULT t.a`) asked the destination for `t.a` even when it cannot read subcolumns (`StripeLog`), which threw `INCORRECT_INDEX`. Such a destination now reads `t`, and `t.a` is extracted after the conversion, as for any other converted input. Both found by the AI review on ClickHouse#124296. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed members A member stored as an array in the destination was always preferred as the size source, even when the user may not read it while it may read another member that is an array in the `Buffer` but stored as `String` in the destination. That read was denied although a readable source existed. The size source is now the smallest readable member, one that needs no conversion first; with none readable it falls back as before and the access check denies. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| /// so keep the ones the fill of the missing columns reads as pass-throughs. | ||
| Names consumed_fill_support; | ||
| for (const auto * input : filter_dag.getInputs()) | ||
| if (fill_support.contains(input->result_name)) |
There was a problem hiding this comment.
[P1] Preserve the row-count support column through filters
This only keeps destination columns that the fill reads for values (fill_support). When columns_intersection was empty, the new branch above injects one destination column solely so the later addMissingDefaults sees the flushed row count. A row policy or PREWHERE can consume and remove that helper column too, and then the post-filter header is empty again, so queries that select only Buffer-only columns still return zero rows after the flush.
A minimal shape is a local destination like dst(k UInt8), a Buffer table buf(k UInt8, x UInt8 DEFAULT 0), and SELECT x FROM buf PREWHERE k = 1 (or the same predicate as a row policy). After the flush the read adds only k; the filter drops it; addMissingDefaults sees zero rows and materializes no x values. Please preserve that row-count support column through merge_converting_prefix, not only fill_support.
There was a problem hiding this comment.
Measured on this head, this does not reproduce: after the flush, SELECT x FROM buf PREWHERE k = 1, the same predicate in WHERE, and a row policy USING k = 1 each return the 2 matching rows (MergeTree and Memory destinations; StripeLog and TinyLog for the last two). A filter is forwarded to the destination only on columns it has (supportedPrewhereColumns), which are already in the read list, so k is read as a selected column rather than the row-count fallback, and a read whose filter consumes every column still yields chunks with their row count.
Related: #113231
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading a
Buffertable that has columns its destination table lacks, when the destination is a local table (notDistributed). After the rows were flushed,count()and queries selecting only such columns returned no rows, and theDEFAULT/MATERIALIZEDvalues,Nestedarray sizes and subcolumns of such columns were computed from the wrong data, so a row read differently before and after the flush.Description
On 26.8.18.2,
SELECT count()from aBuffertable that has a column its destination lacks returns 0 instead of the destination's row count (also 26.3.42.3, 25.3.14.14):For flushed rows,
StorageBuffer::readread only the selected columns the destination has, filled the missing ones over that block in the destination's types, then converted. With no selected column in the destination, it skipped the destination.Like
Mergeand theMergeTreereader, the fill now reads the default inputs (recursively, kept through a forwardedPREWHEREor row policy; the parent if the destination cannot read subcolumns), aNestedmember that is an array in theBufferfor sizes, and the smallest column for the row count. It converts to theBuffertypes first, fills only the selected columns and theBuffer-only columns they depend on, and extracts subcolumns from the converted or filled column. A selected subcolumn of a destination column with another type is unchanged (#113231 fixes it). OnlyFetchColumnsreads of a local destination change. The destination columns the fill reads needSELECT; for the row count orNestedsizes it reads a column the user may read, ascount()does.The new test expects each case to read the same before and after
OPTIMIZE TABLEflushes the rows. It fails on master and passes here (100 randomized runs).00910_buffer_prewhere_different_typesnow returns the destination's rows for aBuffer-only column.03631_buffer_access_checkgains seven partial-grant cases.Workflow [PR]
Sync PR [sync-upstream/pr/124296]