Repository navigation
Calculate a projection without resolving its positional arguments again - #126185
Conversation
Building a projection's metadata analyzes its query in place: with `enable_positional_arguments_for_projections` on, the positional arguments are replaced in the stored query, and with it off, `1` stays a constant `GROUP BY` key. `calculateByQuery` then resolved positional arguments again by the setting of the INSERT, merge or mutation that calculates the projection, so an integer literal could be re-read as a position: `GROUP BY 'a', 1` built off and calculated on reads `1` as `'a'`, and `SELECT 2, 1 GROUP BY 1` built on (stored key `1`) reads it as `2`. Released versions reject such an INSERT with NOT_FOUND_COLUMN_IN_BLOCK; master, since the metadata check of ClickHouse#118375, throws a LOGICAL_ERROR (found by BuzzHouse, STID 4238-495c). Analyze the stored query with positional arguments disabled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Three review rounds (own review + an independent model, engine codex), final head
Final round: no new findings from the independent model. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261016-022400 |
|
cc @KochetovNicolai @CurtizJ, could you review this? Building a projection's metadata already replaces the positional arguments in its stored query, but |
|
Workflow [PR], commit [6179a9e] Summary: ✅
AI ReviewSummaryThe PR prevents Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested. |
05719a5
The only conflict is in `ProjectionDescription::calculateByQuery`: master also has the `enable_parallel_replicas` line of #129863 and the positional arguments change of #126185 there, neither of which is on 26.10. Keep the 26.10 code and add only the `rewrite_in_to_join` line of #130143. Also take the three lines of #129006 that materialize constant columns of the calculated projection block. On 26.10 a projection column such as `exists(SELECT ...)` is calculated as a `ColumnConst`, and once #130143 gives it the right name, writing the projection part fails with `Bad cast from type DB::ColumnConst to DB::ColumnVector<char8_t>` (the `t_subquery_normal` case of 05569). The rest of #129006 is not needed on 26.10: its trigger, `optimize_constant_columns_after_filter`, does not exist there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #118375
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an
INSERTfailing withNOT_FOUND_COLUMN_IN_BLOCKwhenenable_positional_arguments_for_projectionswas enabled for it and a projection of the table had an integer constant inGROUP BY, likeGROUP BY 'a', 1.Description
On 26.9.19.9, with
PROJECTION p (SELECT 'a' GROUP BY 'a', 1)created underenable_positional_arguments_for_projections = 0,INSERT INTO t SETTINGS enable_positional_arguments_for_projections = 1 VALUES (2)is rejected withNot found subcolumn 1 in block. There are only columns: 'a'. (NOT_FOUND_COLUMN_IN_BLOCK). On master, since #118375 added the check, it is aLOGICAL_ERROR, found by BuzzHouse: CI report (Projection p1 calculated the columns CAST('1970-01-01 00:00:00', 'DateTime') while its metadata describes the columns 1).Creating a projection analyzes its query in place: with the setting on, the positional arguments are replaced in the stored query, and with it off,
1stays a constant key. Calculating the projection then resolved positional arguments again by the setting of theINSERT, merge or mutation, so the calculated block could differ from the projection's columns.calculateByQuerynow always analyzes the stored query with positional arguments disabled.Re-attaching a table still rebuilds its projections with the server's value of the setting (#104430); this PR does not change that.
Validation: the new test aborts the server on the unfixed binary and passes with the fix, 50 randomized runs and the
DatabaseReplicated, s3 storage and parallel replicas setups pass, and 326 projection and positional-argument stateless tests show no new failures.Workflow [PR]
Sync PR [sync-upstream/pr/126185]
Version info
26.11.1.130-master(included in26.11and later)