Repository navigation
Do not convert a column a pending mutation drops - #118585
Conversation
Dropping a column and re-adding one of the same name but another type made every query touching that
column fail as long as a part still physically carried the old column, that is until the drop's mutation
had rewritten it:
ALTER TABLE t DROP COLUMN c; -- c UInt64 is still in the part
ALTER TABLE t ADD COLUMN c UInt32; -- a new column, absent from the part
SELECT count(), sum(c) FROM t;
-- Code: 44. Illegal column UInt32 of first argument of function toUInt32:
-- while executing 'FUNCTION _CAST(c, 'UInt32')'
Both statements are metadata-only, so the part keeps the old column file while the metadata already
reports the new column. `performRequiredConversions` then saw a column whose type in the part differs
from the requested one and converted it - building the conversion for `UInt64` and handing it the
`UInt32` default of the new column. `SELECT *` and every query naming the column raised, while the other
columns of the same part were readable.
A column that a pending mutation drops is not read from the part at all: the readers skip it and the
value comes from the current metadata, in the requested type, so there is nothing to convert. The
conversion is now skipped for such a column, which is also what a read of the rewritten part does - the
answer no longer changes when the mutation materializes.
Closes: #116416
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [77b2fe0] Summary: ✅
AI ReviewSummaryThis PR fixes the stale-read path for Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 77b2fe0.
Changed lines: Changed C/C++ lines covered: 51/52 (98.08%) · Uncovered code |
…drop-conversion-116416
Build profile diff (arm_release)Commit See the job log for details. |
…drop-conversion-116416
…on is pending A projection part is read without the parent part's `AlterConversions`, so it still carries a column that a pending `DROP COLUMN` removed. After `DROP COLUMN c, ADD COLUMN c UInt32` (and the projection dropped and re-added), a query served from a normal projection returned the old values of `c`, and an aggregate projection failed with `CANNOT_CONVERT_TYPE`. Reject projections in `canUseProjectionForReadingStep` while metadata mutations are pending, like the statistics min/max shortcut already does. Addresses the review comment on the base-table reader fix. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 AI Review blocker addressed in 91ca27d:
|
…arent, not its projection The previous gate rejected all projections whenever the mutations snapshot had any metadata mutation. Once one is pending, the snapshot holds every mutation still in `current_mutations_by_version`, including finished ones, so projections (and the implicit `_minmax_count_projection`) were refused even for parts the mutation had already rewritten, breaking `force_optimize_projection` in `04546_ttl_delete_where_recalc_after_update`, `04653_mutation_rewrite_stale_part_column_type`, `04008_skip_empty_columns_lifecycle` and `05059_minmax_count_projection_after_alter_column`. Decide per part instead: a part whose on-fly mutation commands contain `RENAME COLUMN` / `DROP COLUMN` is read from the parent part (with its `AlterConversions`), other parts may still use the projection part. The same rule applies to projection-index filtering. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118585&sha=91ca27d4e399c23428036291a338109dcf809960&name_0=PR&name_1=Fast%20test PR: #118585 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The table-wide gate from 91ca27d broke |
…s touching its columns `partHasPendingMetadataMutations` rejected the projection part for any pending `DROP COLUMN` / `RENAME COLUMN` on the part, even on a column neither the projection nor the query reads, which lost projection pruning (and made `force_optimize_projection` fail with `PROJECTION_NOT_USED`) until the mutation materialized. Now only mutations touching a column the projection holds or the read needs (for `RENAME COLUMN`, both the old and the new name) send the part to the parent read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118585&sha=latest&name_0=PR&name_1=Upgrade%20check%20(amd_release) and provide a fix in a separate PR. If the fix is already in progress, link it here. The |
|
This is #120975. At The fix is #118499 (mine, open). It now conflicts with master on one adjacent line in |
A `RENAME COLUMN` waits for a pending `DROP COLUMN` mutation, so with merges stopped the test hung. Check the pending drop and the pending rename of an unrelated column on two tables. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ition cache ClickHouse#119337 added `hasPendingAlterOrMetadataMutations`, which stops reading and writing the query condition cache while an alter or metadata mutation is pending for one of the read parts. It covers what `hasPendingMetadataMutations` was added for (a pending `DROP COLUMN` or `RENAME COLUMN` that `KILL MUTATION` can leave unmaterialized), and it ignores the finished mutations the snapshot keeps for `system.mutations`, which made our snapshot-level check disable the cache after any `DROP COLUMN` until the mutation was evicted. So drop `hasPendingMetadataMutations` from the read side and both write sides. Its last user was `isQueryConditionCacheAllowed`, which also checked it because projection analysis reads projection parts with an empty mutations snapshot. Since ClickHouse#118585 a part with a pending metadata mutation on a column the projection holds or the read needs is read from the parent part, so projection analysis does not consult the cache for it, and the getter is back to master's form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dropping a column and re-adding one of the same name but another type made every query touching that column
fail with 44
ILLEGAL_COLUMNas long as a part still physically carried the old column, that is until thedrop's column-removal mutation had rewritten it:
Both statements are metadata-only, so the part keeps the old column file while the metadata already reports
the new column.
IMergeTreeReader::performRequiredConversionsthen saw a column whose type in the partdiffers from the requested one and converted it - building the conversion for
UInt64and handing it theUInt32default of the new column.A column that a pending mutation drops is not read from the part at all: the readers skip it and the value
comes from the current metadata, in the requested type, so there is nothing to convert. The conversion is now
skipped for such a column, which is what a read of the rewritten part already does, so the answer no longer
changes when the mutation materializes.
Projection parts are read without the parent part's
AlterConversions, so a projection could still serve theold column (after
DROP PROJECTION p,DROP COLUMN c,ADD COLUMN c UInt32,ADD PROJECTION p): a normalprojection returned the old values, an aggregate one failed with
CANNOT_CONVERT_TYPE. A part that still has apending
RENAME COLUMN/DROP COLUMNmutation touching a column the projection holds or the query reads (forRENAME COLUMN, the old or the new name) is now read from the parent part (with itsAlterConversions) insteadof its projection part; other parts, and parts whose pending mutations touch only unrelated columns, keep using
the projection.
Closes: #116416
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed
ILLEGAL_COLUMN("Illegal column ... of first argument of function to...") raised by every querytouching a column that was dropped and re-added with a different type, for as long as a part still carried
the old column. The re-added column now reads as its default, as it does once the drop's mutation rewrites
the part. Queries served from a projection no longer return the old values of such a column.
Workflow [PR]
Sync PR [sync-upstream/pr/118585]
Version info
26.10.1.2100-master(included in26.10and later)