Repository navigation
Don't Force Normal Projection Optimization to Have Filter - #104680
Conversation
|
Workflow [PR], commit [0524f16] Summary: ✅ AI ReviewSummaryThis PR relaxes Final Verdict
|
LLVM Coverage Report
Changed lines: 100.00% (12/12) · Uncovered code |
…ow expects Projection metadata is re-derived from the projection query text at every table load, so the believed column set of a projection can drift from the stored column set of existing projection parts. Two native triggers: parts written by <= 26.2 for a projection selecting an ALIAS column store only the sort key (26.3+ derive the alias source as a physical projection column), and ALTER TABLE ... MODIFY COLUMN re-pointing an ALIAS used by a projection is allowed without a projection rebuild. Since 26.5 the planner also selects normal projections for sorting without a filter (ClickHouse#103723, ClickHouse#104680), so a plain SELECT reads the drifted part through the projection, fills the missing column with the type default, and silently returns wrong data. Background merges that merge projection parts directly read the same default fill and bake the wrong values permanently into the merged projection part. The same shape breaks aggregate projections: the aggregate-state column name embeds the expanded alias (`sum(plus(b, 1))`), so a re-pointed alias leaves old parts without the state column the metadata now expects and reads return default aggregate states. A column is missing legitimately only when it is a parent-table column the parent part also lacks (added by `ALTER ADD COLUMN` after the part was written) - the default fill is then correct and identical on either read path. Everything else counts as drift: `analyzeProjectionCandidate` now reads such parts from the base table (covers normal and aggregate projections; virtual columns are exempt since the reading step provides them), and `prepareProjectionsToMergeAndRebuild` rebuilds the projection from the merged parent data instead of merging drifted projection parts directly (skipped under `deduplicate_merge_projection_mode = 'ignore'`, mirroring the expired-columns rule). Co-Authored-By: Claude Fable 5 <[email protected]>
…ow expects Projection metadata is re-derived from the projection query text at every table load, so the believed column set of a projection can drift from the stored column set of existing projection parts. Two native triggers: parts written by <= 26.2 for a projection selecting an ALIAS column store only the sort key (26.3+ derive the alias source as a physical projection column), and ALTER TABLE ... MODIFY COLUMN re-pointing an ALIAS used by a projection is allowed without a projection rebuild. Since 26.5 the planner also selects normal projections for sorting without a filter (ClickHouse#103723, ClickHouse#104680), so a plain SELECT reads the drifted part through the projection, fills the missing column with the type default, and silently returns wrong data. Background merges that merge projection parts directly read the same default fill and bake the wrong values permanently into the merged projection part. The same shape breaks aggregate projections: the aggregate-state column name embeds the expanded alias (`sum(plus(b, 1))`), so a re-pointed alias leaves old parts without the state column the metadata now expects and reads return default aggregate states. A column is missing legitimately only when it is a parent-table column the parent part also lacks (added by `ALTER ADD COLUMN` after the part was written) - the default fill is then correct and identical on either read path. Everything else counts as drift: `analyzeProjectionCandidate` now reads such parts from the base table (covers normal and aggregate projections; virtual columns are exempt since the reading step provides them), and `prepareProjectionsToMergeAndRebuild` rebuilds the projection from the merged parent data instead of merging drifted projection parts directly (skipped under `deduplicate_merge_projection_mode = 'ignore'`, mirroring the expired-columns rule). Co-Authored-By: Claude Fable 5 <[email protected]>
|
26.3 is still affected by the crash that the second hunk of this PR fixes. On 26.3.60.2-lts (the latest 26.3 release) this aborts (measured with Without a filter, Measured with official and CI
A plain Does 26.3 need this fix, and in which form: (a) |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
This patch changes when
optimizeUseNormalProjectionscan be used and allows a specific case where nothing was filtered, but the projection's sorting key can help remove the sorting step of a query.Version info
26.5.1.579