Repository navigation
Fix Merge tables logical error - #112326
Merged
Merged
Conversation
Contributor
|
Workflow [PR], commit [53fa42b] Summary: ✅
AI ReviewSummaryThis PR hardens the Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 254/269 (94.42%) · Uncovered code |
PedroTadim
enabled auto-merge
July 29, 2026 07:49
…lize_query_plan = 1` limitation A row policy defined on the shard-local table is not applied to a read shipped to a non-local replica when `serialize_query_plan = 1`: the receiving server executes an already-built plan and never applies its own row policies. That is a pre-existing bug on master, filed as #112891, but it makes the "define the policy on the underlying local tables" migration path this change documents incomplete. Qualify it everywhere it is stated: the two `ILLEGAL_PREWHERE` messages, `docs/reference/statements/create/row-policy.mdx`, `docs/concepts/features/security/access-rights.mdx` and `docs/resources/support-center/knowledge-base/security/row-column-policy.mdx`. Also add the "Distributed and remote-backed tables" section to the live Mintlify page `docs/reference/statements/create/row-policy.mdx`; it had only been added to the legacy, unpublished `docs/en` tree.
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 255/269 (94.80%) · Uncovered code |
Merged
1 task
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Aug 3, 2026
…0216 Master (ClickHouse#112326) reworked the PREWHERE contract and the row-level-security pushdown gate that this branch had also touched, so the shared parts are now taken from master and only the Iceberg-specific half plus the snapshot threading remain here. Resolution: * supportedPrewhereColumns keeps this branch's StorageSnapshotPtr parameter. Master derives the answer from a fresh getInMemoryMetadataPtr(), which for a data lake can observe a commit that landed after analysis picked the schema; the pinned snapshot is what closes that window. The parameter is threaded through every override master added since the fork (Buffer, Proxy, TableFunction, DatabaseURL) and into master's own recursive calls in Merge, MaterializedView and Buffer, which previously asked children with no snapshot. * InterpreterSelectQuery::canPushRowPolicyToSource is deleted in favour of master's shouldPushRowLevelFilterToStorage, which is a superset: it also refuses remote storages and resolves subcolumns through prewhereSupportedColumnsContain. It is called from four sites, so the local gate would have been a second, weaker copy. Its addPrewhereAliasActions guard is likewise dropped: master's get_prewhere_columns already excludes a policy that will not be pushed. * The child/target intersections this branch added to StorageMerge and StorageMaterializedView are dropped: master added equivalent ones, plus an undeclared-column check this branch lacked. * supportedPrewhereColumnsIncludeSubcolumns, new in master, is kept everywhere. * contrib/libpng, whose submodule master removed in 9573cb0, was left on disk by the merge as an untracked directory. utils/list-licenses walks contrib/ on the filesystem rather than the index, so the stale directory failed the license scan and blocked cmake; it is moved aside. Verified on the merged tree against a same-day master build, on an Iceberg table whose identity-partition column is absent from the data files: master reads the column empty and returns no rows for a filter on it, the merged branch backfills it and returns the rows with optimize_move_to_prewhere both on and off, and an explicit PREWHERE on that column still raises ILLEGAL_PREWHERE.
This was referenced Aug 3, 2026
vdimir
added a commit
that referenced
this pull request
Aug 18, 2026
Without plan optimizations the chain below the sort re-materializes the constant of a constant `SELECT` item while still taking a same-named input, so an `ExpressionStep` DAG holds a `COLUMN` node named as one of its inputs. Splitting such a DAG for lazy materialization renamed the node promoted to the lazy half (`avoid_duplicate_inputs`), and the re-stacked `Sorting` step no longer resolved its sort description: `Not found column 2_UInt8 in block ... 2_UInt8_0`. Fixed indirectly by #112326, whose `hasInputNameShadowedByComputedNode` declines such plans. Its own test covers only the row-policy `CAST(x, ...) AS x` shape, so pin the constant `SELECT` item with `ORDER BY ALL` as well. Related: #112209 Related: #112326 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
robinld
pushed a commit
to robinld/ClickHouse
that referenced
this pull request
Oct 14, 2026
…processes the query `ReadFromMerge::convertAndFilterSourceStream` added every child's row policy as a `FilterStep` on top of the child plan, whatever built that plan. When a `Merge` table also reads a `Distributed` table its stage is above `FetchColumns`, so `createPlanForTable` builds a local child (e.g. MergeTree) with `InterpreterSelectQueryAnalyzer`, whose planner already applies the child's policy below its own aggregation. The `Merge` then applied it a second time over the processed header, and every query failed with `NOT_FOUND_COLUMN_IN_BLOCK`. The child plan now records that the interpreter built it, and the `Merge` skips its own copy. A child that reports a stage above `FetchColumns` itself (`Distributed`, and tables over one) sorts, limits, aggregates and computes extremes before the `Merge` sees a row, so a filter above it was applied too late: `ORDER BY ... LIMIT` returned no rows, `extremes = 1` printed values of rows the policy hides or threw `Got 1 in extremes chunk, expected 2`, and aggregates failed with `NOT_FOUND_COLUMN_IN_BLOCK`. Such a child is now rejected with `ILLEGAL_PREWHERE`, the rule a direct read of that table follows since ClickHouse#112326. Related: ClickHouse#125580 Related: ClickHouse#112326 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a logical error when PREWHERE is used on a Merge table over another Merge table or a materialized view whose column type differs. Also fixes a row policy being silently ignored on tables that read from remote servers (a Distributed table, or a table wrapping one), which could expose rows the policy was meant to hide; such queries are now rejected with an ILLEGAL_PREWHERE error. Define these policies on the underlying local tables on each remote server instead; note that such a policy is still not applied to reads shipped with
serialize_query_plan = 1, which is a separate, pre-existing bug.Closes: #112315
Related: #112891
Version info
26.8.1.656(included in26.8and later)