Repository navigation
Conversation
…UMN` changes On a type change of a column, the mutation rebuilt only the projections having the column in their primary key, and kept the parts of the others. A projection that computes from the column kept what it computed with the old type and returned it for the queries it served: an aggregate projection `SELECT toHour(dt) AS h, count() GROUP BY h` its `toHour(dt)` values, and a projection sorted by an expression of the column, such as `ORDER BY toHour(dt)`, its order and primary index, so its pruning dropped matching rows. Also rebuild a projection whose sorting key is an expression of the column, and one that reads the column and computes any of its columns. A projection that only stores the column as is keeps its parts as before. Related: ClickHouse#127952 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [fba5ab5] Summary: ❌
AI ReviewSummaryThis PR rebuilds projections affected by type-changing Missing context / blind spots
Final VerdictStatus: ✅ Approve. No unresolved findings or required code changes. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units495 translation units recompiled, 4934 s compile time in total, 495 of them have a recent master baseline. |
…OLUMN` changes
A projection with `WHERE` keeps the rows that the filter selected. After
`MODIFY COLUMN dt DateTime64(0, 'Asia/Tokyo')` on a `DateTime('UTC')`
column, `PROJECTION p (SELECT id, dt WHERE toHour(dt) = 9 ORDER BY id)`
still held the row of 9:00 UTC, and `WHERE toHour(dt) = 9` through it
returned no rows instead of the row of 0:00 UTC. It stores `dt` as is and
its key is `id`, so the previous commit did not rebuild it. Now a
projection is also rebuilt when its `WHERE` uses the column.
Found by the AI review of the PR.
Related: ClickHouse#127952
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ype `MODIFY COLUMN` changes A wide part that predates `ADD COLUMN dt ... DEFAULT` does not store `dt`; its values are computed from the default when read. A projection materialized on such a part, e.g. `SELECT toHour(dt) AS h, count() GROUP BY h`, is computed from those values. After `MODIFY COLUMN dt DateTime64(0, 'Asia/Tokyo')` the reads compute `dt` with the new type, but `splitAndModifyMutationCommands` dropped the `READ_COLUMN` for the part, since there is nothing to rewrite, so the interpreter never decided to rebuild the projection, and `GROUP BY toHour(dt)` through it kept returning the hours in UTC. Now in that case the mutation adds `MATERIALIZE_PROJECTION` for the projections of the part that compute from the column (the rule moved to `MutationsInterpreter::projectionComputesFromColumn`). The interpreter skips `MATERIALIZE_PROJECTION` for a part that already has the projection, so the generated command carries the new internal flag `rebuild_existing_projection`. The column is still not written to the part. A compact or packed part already reads such a column for its projections, writing it, and goes through the previous commit's check. Found by the AI review of the PR. Related: ClickHouse#127952 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he column whose type `MODIFY COLUMN` changes A wide part that stores `dt` but predates `ADD COLUMN h UInt8 DEFAULT toHour(dt)` does not store `h`: it is computed from the default when read. A projection `SELECT h, count() GROUP BY h` materialized on such a part stored the hours computed with the old type. After `MODIFY COLUMN dt DateTime64(0, 'Asia/Tokyo')` the reads compute `h` with the new time zone, but the projection reads `h`, not `dt`, so it was not rebuilt, and `GROUP BY h` through it returned the hours in UTC. Now `projectionComputesFromColumn` also follows a column that the projection reads and the part does not store through its default, also through the defaults of other such columns, and the projection is rebuilt when the default uses the changed column, even if the projection stores the column as is. The interpreter checks the columns of the part, through the renames of `AlterConversions`; the case of a part that stores neither column, handled by `splitAndModifyMutationCommands`, checks the columns of the part there. Found by the AI review of the PR. Related: ClickHouse#127952 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e column whose type `MODIFY COLUMN` changes The previous commit follows a column that the projection reads through its default only when the part does not store the column. An `ALIAS` is computed from its expression whenever it is read, but a part can still store the data of a former column with its name: after `MODIFY COLUMN h UInt8 ALIAS toHour(dt)` of a stored `h`, the old files stay until the next mutation. With `w UInt8 DEFAULT h` and a projection `SELECT w, count() GROUP BY w`, the walk stopped at `h`, and `MODIFY COLUMN dt DateTime64(0, 'Asia/Tokyo')` kept the projection with the old hours. Now an `ALIAS` is always followed; the check whether the part stores the column applies only to the other defaults. Found by the AI review of the PR. Related: ClickHouse#127952 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…`MODIFY COLUMN` changes
`projectionComputesFromColumn` compared the inputs of the projection and of
its keys with the name of the column, so a projection that reads a
subcolumn, such as `x.dt` of `x Tuple(dt DateTime('UTC'))` in
`SELECT toHour(x.dt) AS h, count() GROUP BY h`, was not rebuilt by
`MODIFY COLUMN x Tuple(dt DateTime64(0, 'Asia/Tokyo'))` and kept the old
hours. Now an input that the column metadata resolves to a subcolumn of the
column counts as the column, for the inputs of the projection and of its
primary and sorting keys; a column whose name has a dot is still a column of
its own.
Found by the AI review of the PR.
Related: ClickHouse#127952
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… computed from A projection that reads a subcolumn of a column the part computes from its default, as `toUInt16(x.v)` with `x Tuple(v UInt8) DEFAULT tuple(toHour(dt))`, was kept by `MODIFY COLUMN dt`: the walk over the defaults looked up the default of `x.v`, which has none, so it did not see that `x` is computed from `dt`. The walk now resolves a subcolumn to its column, for the inputs of the projection and for the identifiers in the defaults it follows, through the column metadata, which tells a subcolumn from a column whose name has a dot. Found by the AI review of the PR. Related: ClickHouse#127952 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…not store the column
A projection that only stores the changed column was kept by `MODIFY COLUMN`,
which is right when the part stores the column: the part and the projection
convert the same values. A wide part that predates `ADD COLUMN` does not store
it and computes it from its default with the new type, while the projection
converted the values it stored, so `x UInt8` changed to `String` read
`['0','0','0']` through the projection and `['','','']` without it, and a
`DateTime('UTC') DEFAULT '2026-01-01 00:00:00'` changed to
`DateTime64(0, 'Asia/Tokyo')` had the hour `9` through the projection and `0`
without it, as on master. A projection that reads the column, or a subcolumn
of it, is now rebuilt for a part that does not store the column. Both callers
of the check use it: the branch of `splitAndModifyMutationCommands` for a
column that the part does not store, and `MutationsInterpreter`.
Found by the AI review of the PR.
Related: ClickHouse#127952
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…build-on-modify-column-127952 # Conflicts: # src/Interpreters/MutationsInterpreter.h
…pplies without rewriting it `MODIFY COLUMN` to `Nullable` of the same type, with the default serialization and without statistics, and an extension of a `Variant` are applied to a part without rewriting the column: `MutateTask::prepare` drops the command before the interpreter sees it. A projection of the part computed from the column then kept what it computed from the values of the old type, also through the default of a column that the part does not store: with `PROJECTION p (SELECT id + length(toTypeName(dt)) AS h, count() GROUP BY h)`, after `MODIFY COLUMN dt Nullable(UInt8)` the query answered through the projection returned `[5,6,7]` instead of `[15,16,17]`. Now such a conversion still skips the column, but a projection of the part computed from it is rebuilt, as `MATERIALIZE PROJECTION` builds it, by the same check as for a rewritten column. Related: ClickHouse#127952 Related: ClickHouse#127977 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #127952
On a type change of a column (
ALTER TABLE ... MODIFY COLUMN, which runs a mutation),MutationsInterpreter::preparerebuilt only the projections having the column in their primary key (projection.metadata->getPrimaryKeyColumns()), and the mutation kept the parts of all the others. That is enough for a projection that stores the column as is, whose values are converted when read like those of the table, but not for one that computes from the column:PROJECTION p (SELECT toHour(dt) AS h, count() GROUP BY h)storeshcomputed with the old type; its key ish, notdt. AfterMODIFY COLUMN dt DateTime64(0, 'Asia/Tokyo')on aDateTime('UTC')column,GROUP BY toHour(dt)through it returns the hours in UTC,0to4, instead of9to13;PROJECTION p (SELECT id, toHour(dt) AS h ORDER BY h), storesidanddt, and readingdtis converted, but its order and primary index keeptoHour(dt)of the old type, soWHERE toHour(dt) = 9through it returns no rows.A projection is now also rebuilt when its sorting key is an expression of the column (
getSortingKey().expression->getRequiredColumns()), when itsWHEREuses the column (where_clause_ast; such a projection keeps the rows that its filter selected with the old type, even if it stores the column as is), and when it reads the column and computes any of its columns (a column of its sample block that is not one of the columns it reads, such as an aggregate state). An input that is a subcolumn of the column, such asx.dtof aTuple, counts as the column. A projection that only stores the column as is keeps its parts, as before, unless a wide part does not store the column: such a part computes the column from its default with the new type (a compact part is rewritten with the converted values, so it agrees with its projection), while the projection would convert the values it stores, such as0of an implicitUInt8default read back as'0'instead of the''ofString, so the projection is rebuilt for such a part. The same applies to a wide part that does not store the column, e.g. one that predatesADD COLUMN dt ... DEFAULT, whose projection was computed from the default: the mutation does not write the column to such a part, but it now addsMATERIALIZE_PROJECTIONfor those projections, with an internal flagrebuild_existing_projectionbecauseMATERIALIZE_PROJECTIONotherwise skips a part that already has the projection. A column that the projection reads and the part does not store, such ashofh UInt8 DEFAULT toHour(dt)added after the part was written, is computed from its default, so the projection is rebuilt when that default (also through the defaults of other such columns, and through anALIAS, which is computed from its expression even when the part still stores data of a former column with its name) uses the changed column, even if it stores the column as is. Such a mutation now rebuilds more projections than before, which is needed for their results to be correct.MODIFY COLUMNtoNullableof the same type, with the default serialization and without statistics, and an extension of aVariantare applied to a part without rewriting the column (canSkipConversionToNullable,canSkipConversionToVariant); such a conversion still skips the column, but every projection of the part computed from it, by the same check, is now rebuilt with the sameMATERIALIZE_PROJECTIONcommand.05458_projection_rebuilt_on_modify_columncompares the results with the projection forced (force_optimize_projection = 1) and without projections after such aMODIFY COLUMN, for an aggregate projection, a normal projection sorted bytoHour(dt), a projection withWHERE toHour(dt) = 9that storesdtas is, an aggregate projection of a wide part that does not storedt, an aggregate projection over a columnh DEFAULT toHour(dt)that the part does not store, an aggregate projection overw DEFAULT hafterhbecomesALIAS toHour(dt), an aggregate projection over the subcolumnx.dtof aTuple, an aggregate projection over the subcolumnx.vofx Tuple(v UInt8) DEFAULT tuple(toHour(dt))that the part does not store, a projection that storesxordtas is for a part that does not store it (with an implicit and an explicit default), a projection grouped byid + length(toTypeName(dt))afterdtbecomesNullable(UInt8), an aggregate projection overh DEFAULT id + length(toTypeName(x))afterx Variant(UInt8, String)is extended, and a projection that only storesdt. The first twelve differ on master.Not covered: a
MODIFY COLUMNthat changes only the time zone runs no mutation at all, so such a projection is not rebuilt for it either. That part of #127952 is left for a follow-up, which can make such a change run a mutation when a projection computes from the column.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ALTER TABLE ... MODIFY COLUMNthat changes the type of a column now rebuilds the projections that compute from it, such as an aggregate projection overtoHour(dt), a projection sorted bytoHour(dt)or a projection withWHERE toHour(dt) = 9. They used to keep the values computed with the old type, so queries served by them could return wrong results.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127977]