Repository navigation
Conversation
…ike a stored column
A split PREWHERE keeps every step's computed columns in the block (an
intermediate filter column, or a sub-expression shared with a later step),
and the readers match columns by name: getReadTaskColumns treats every step
output as already read and skips the stored column of that name, and the
MergeTree and Memory sources pick result columns by name. So with a stored
column named `greater(x, 1_UInt8)`, `PREWHERE x > 1 AND k > 5` returned the
filter value instead of the stored data, a String column of that name
crashed, and a shared sub-expression gave NOT_FOUND_COLUMN_IN_BLOCK.
tryBuildPrewhereSteps now returns false (one step, the result of
enable_multiple_prewhere_read_steps = 0) when a non-input output of any step
is named like a physical column of the table, the same fallback as the
input-shadowing guard above it and the Parquet reader's.
The projection index reader built its processor without the projection's
columns while its pool's getReadTaskColumns passes them, so the two step
computations could now disagree ("PREWHERE steps count mismatch" in
createReadersChain); it passes the projection's columns too.
Closes ClickHouse#124484
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reverting the projection index reader's columns plumbing left the test green, and no arm reached the TopK dynamic filter path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds): 2 findings fixed, 2 declined with evidence
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261013-154700 |
|
Workflow [PR], commit [14c2873] Summary: ❌
AI ReviewSummaryThis PR prevents intermediate Final VerdictStatus: ✅ Approve |
Falling back to one step dropped the read boundaries of a split PREWHERE: with an unread stored column named `equals(gate, 1_UInt8)`, `PREWHERE gate = 1 AND n > 0` evaluated the default expression of `n`, and an exported `toUInt64(v)`, on the rows `gate = 1` rejects and threw CANNOT_PARSE_TEXT. The check also fired for stored columns the query never reads. The steps now give such a computed node another name (`__prewhere_<name>`) and keep their boundaries; the outputs of PREWHERE keep their names, since the query reads them by name. The step count no longer depends on the columns, and the projection index reader reads only PREWHERE inputs, which the input-shadowing guard already covers, so its columns plumbing is reverted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 32e74f7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The automatic retry re-ran one other job at attempt 3 and stopped there, so the lost job was never retried. The retry policy for this case is asked of the CI owner in #122501. Session id: cron:our-pr-ci-monitor:20261014-120008 |
|
@alexey-milovidov you can review this |
…h one name With join_use_nulls = 1, the WHERE copy of a JOIN ON condition repeated in WHERE is computed on toNullable(col) but keeps the name of the ON copy, so the PREWHERE DAG holds two different nodes with one name and two types (e.g. equals(__table2.enabled, 1_Bool) as Nullable(UInt8) and UInt8). tryBuildPrewhereSteps clones every node into its step under its own name, the steps pass columns to each other through a Block by name, and a non-last step keeps its filter column in the block. When the two copies fall into non-adjacent, non-last steps, the later step inserts a column of the same name and another type and Block::insert throws 352. Two repeated two-condition groups collide the same way through the generated `and` name. Clone the non-INPUT nodes whose name is shared with another node, and that are not outputs of PREWHERE, under new names (`__prewhere_<name>`). Only the step clones are renamed: the original DAG, and so its conjunct hashes used by the query condition cache attribution, are unchanged, and the step boundaries stay where they are, so an earlier condition still filters the rows a later default expression is evaluated on (a one-step fallback would throw there). The helper has the same shape as the one in ClickHouse#125670, which renames for a computed node named like a stored column. Same class as ClickHouse#111955, fixed for the FilterStep split by ClickHouse#112007. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new names given to the step clones of nodes that share a name were made unique only against the names of the PREWHERE DAG. Stored columns read after PREWHERE are not in that DAG but land in the same block, and the readers skip a stored column whose name a step already produced (`getReadTaskColumns` for MergeTree, `read_missing_columns` for Memory). So a table with a column named like a new name, e.g. `__prewhere_equals(__table2.enabled, 1_Bool)`, returned the step's predicate value instead of the stored value. Also skip a candidate name that is a physical column or subcolumn of the table, with the same `is_stored_column` helper as ClickHouse#125670. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A step with two or more conditions gets a generated `and` filter named after its children. With the renamed children that name is new, and a non-last step keeps the filter in the block, so a stored column with the same name is not read and the query returns the filter value instead. Alias such a filter to a fresh name, as ClickHouse#125670 does, and share its two name helpers so the two PRs fold mechanically. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #124484
Related: #124632
Related: #122470
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong values,
NOT_FOUND_COLUMN_IN_BLOCKerrors and a crash when aMergeTreetable has a column whose name equals the name of a sub-expression of a multi-conditionPREWHERE(for example a column namedgreater(x, 1_UInt8)read withPREWHERE x > 1 AND k > 5). Closes #124484.Description
On 26.8.21.12,
SELECT x, `greater(x, 1_UInt8)` FROM t PREWHERE x > 1 AND k > 5returns1instead of the stored values, and with aStringcolumn of that name the server crashes (SIGSEGV). A sub-expression shared by two conditions (plus(x, 1_UInt8)inx + 1 > 2 AND (x + 1) * k > 5) givesNOT_FOUND_COLUMN_IN_BLOCK. Memory's multi-stepPREWHERE(master only), aWHEREmoved toPREWHEREand the TopK dynamic filter step (#122470, also guarded inside the TopK optimization by my open #122486; the two do not conflict) hit the same path. All of it is correct withenable_multiple_prewhere_read_steps = 0.Root cause: the split steps keep their computed columns in the block, and the readers (
getReadTaskColumns,MergeTreeSelectProcessor, Memory) match columns by name, so a computed column stands in for the stored column of the same name.Change:
tryBuildPrewhereStepsgives a node computed by a step another name (__prewhere_<name>) when a stored column has its name. The steps keep their boundaries, so an earlier condition still filters the rows a later default expression or conversion is evaluated on. The outputs ofPREWHEREkeep their names, since the query reads them by name.A single-condition
PREWHERE x > 1with such a column is a separate defect (wrong also with one step) and is not changed here.Validation: new test
05394_prewhere_steps_stored_column_name(MergeTree, Memory, a guarded default expression and conversion, the TopK dynamic filter) fails on master with wrong values, an abort andNOT_FOUND_COLUMN_IN_BLOCK, and passes with the fix, also under randomized settings and parallel replicas.Workflow [PR]
Sync PR [sync-upstream/pr/125670]