Repository navigation
Conversation
A filter deferred until after FINAL is executed by a FilterTransform with remove_filter_column = true. When the predicate is a bare column reference the predicate node is the DAG's own input node, so the transform erased the source column the stream carries, and the query then failed with THERE_IS_NO_COLUMN or NOT_FOUND_COLUMN_IN_BLOCK depending on whether a result projection existed. The existing restoreDAGInputs guard does not cover that shape: it adds an input to the outputs only when it is not already there, and a bare predicate is already an output. A wrapped predicate such as b = 1 builds a distinct function result node, so erasing it leaves the input alone, which is why only the bare form failed. Clear the remove flag when the filter column is one of the DAG's own inputs, the same resolution optimizePrewhere.cpp already uses for a prewhere column that is needed later. The lambda is shared by the deferred row policy and the deferred PREWHERE, so this covers both. The row policy half is reachable with stock default settings, because apply_row_policy_after_final defaults to 1. Closes: ClickHouse#114512
…lumn The regression test asserted the right values on a fixture that could not distinguish two plausible wrong fixes. Every ReplacingMergeTree fixture had no version column and one row per sorting key, so FINAL deduplicated nothing and a fix that re-applied the filter before FINAL produced byte-identical output. And because the predicate column was 0 or 1, a fix that substituted a synthesized truth column for the real one also passed. Add a versioned fixture whose predicate flips across the deduplication group: one key passes only before deduplication, another only after, so the two filter orders must disagree. The surviving value is 7, which a synthesized UInt8 truth column cannot produce. Both halves are covered, the explicit PREWHERE and the bare-column row policy that needs no SETTINGS clause. Merges are stopped per table because a merge collapses the versions and removes the flip, which would silently retire the arms.
Internal second-model reviewAn independent model reviewed this change cold against the PR contract, over two rounds. Verdicts below are mine.
A final cold pass over the second round found no blocker and no major. The new fixture depends on the two inserts landing in separate parts, which holds because Session id: cron:clickhouse-review-slot-9:20260813-021000 |
|
Workflow [PR], commit [a0f2195] Summary: ✅
AI ReviewSummaryThis PR fixes a real deferred-after- Missing context / blind spots
Final Verdict✅ No new code-level findings in the current PR diff. The fix and regression coverage look correct; the only remaining gap is independent execution evidence for the new regression test. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260812-181700 |
|
cc @yariks5s @novikd, could you review this? A filter deferred until after FINAL runs in a FilterTransform with remove_filter_column set, so when the predicate is a bare column reference the predicate node is the DAG's own input and the transform erases the source column the stream still needs; this clears that flag when the filter column is one of the DAG inputs, the way optimizePrewhere already resolves the same case. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 34 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - a0f2195CI is fully finished on this head and there are no failures to own.
177 leaf jobs: 159 OK, 18 skipped, 0 failed, 0 dropped. Praktika reports this head top-level |
|
📊 Cloud Performance Report ✅ AI verdict: This PR is a narrow correctness fix in ReadFromMergeTree that keeps a bare-column filter predicate alive in the stream when a filter is deferred until after FINAL (row policies or apply_prewhere_after_final). None of the flagged ClickBench queries (Q18, Q28, Q32) use FINAL, row policies, or after-final filtering, so they never reach the changed code. All three are already not_sure, sit within master's variance band, and show essentially flat CPU time, so the small median deltas are run-to-run variance rather than a real effect of this change. clickbenchFlagged queries (3 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
|
362cbd2
…earch_lightweight_delete_limit` Reading `SELECT ... FINAL PREWHERE _row_exists` with `apply_prewhere_after_final = 1` fails with `THERE_IS_NO_COLUMN` in 26.8 regardless of the vector index (reproduced without any index). The bug is fixed on master by #114578, which is not in 26.8. Keep the `EXPLAIN` check that the index is not used in this case, which is what this backport changes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=125108&sha=76bfddc8e3fe65c82d6272e7107fb6cb46e658ca&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29 PR: #125108 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):
Fixes
THERE_IS_NO_COLUMN/NOT_FOUND_COLUMN_IN_BLOCKwhen a filter that runs afterFINALis a plain column reference. This affected an explicitPREWHERE bunderFINALand, with default settings, a row policy whose expression is a bare column.Description
Closes: #114512
SELECT count() FROM t FINAL PREWHERE bthrewCode: 8. Cannot find column 'b' in source stream. NoSETTINGSclause is needed:apply_row_policy_after_finaldefaults to 1, so a row policy defersPREWHEREpastFINAL.Root cause: a filter deferred after
FINALruns in aFilterTransformbuilt withremove_filter_column = true. When the predicate is a bare column reference, the predicate node is the DAG's own input node, so the transform erases the source column the stream carries. The existingrestoreDAGInputsguard cannot help: it only re-adds an input that is not already an output, and a bare predicate is already one. A wrapped predicate (b = 1,NOT b) has a distinct result node, so erasing it leaves the input alone. Hence only the bare form failed.The fix clears the local
remove_columnflag inadd_deferred_filterwhen the filter column is one of the DAG's own inputs, which is howoptimizePrewhere.cppalready resolves the same case. That lambda is shared by the deferred row policy and the deferredPREWHERE, so one change covers both.The defect is broader than reported: a bare-column row policy with no
PREWHEREanywhere in the query fails identically under default settings. That shape is in the test.Validated in both directions on a debug build. Every shape in the issue's matrix now returns what its
WHEREequivalent returns, and the new test fails on an unfixed binary. Covered: all four projections, subcolumns, a stacked policy plusPREWHERE, the four FINAL engines, andNullable/LowCardinality/Floatpredicates.SELECT *stays byte-identical to theWHEREequivalent. A versioned fixture whose predicate flips across deduplication pins that the filter runs afterFINAL, on the source column.Pre-existing and unchanged here: a row policy on a bare subcolumn fails
NOT_FOUND_COLUMN_IN_BLOCKon the non-deferred read path, with and withoutFINAL.