Repository navigation
Do not refuse to attach a table because of an implicit min-max index that cannot be built - #125861
Conversation
…that cannot be built `StorageInMemoryMetadata::addImplicitIndicesForColumn` already skips an implicit index that fails `MergeTreeIndexFactory::validate` with BAD_ARGUMENTS / INCORRECT_QUERY, but it built the index outside that try. Building it analyses the column's ALIAS expression, so an ALIAS that calls `dictGet` on a dictionary that no longer exists (dropped with `check_table_dependencies = 0`, or removed from the configuration) threw BAD_ARGUMENTS from ATTACH. The table could not be loaded and, with `async_load_databases = 0`, the server did not start. Found by the Stress test: the AST fuzzer cloned 05325's `t_alias_dict` with `add_minmax_index_for_string_columns = 1` before the test dropped the dictionary. Move the construction into the existing try and keep the error filter. An implicit index over `dictGet` is never kept when the dictionary exists either (`dictGet` is non-deterministic and validation rejects it), so ATTACH now yields the same indices CREATE did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able or function Building the implicit index analyses the ALIAS expression. Besides a missing dictionary (BAD_ARGUMENTS), `joinGet` on a `Join` table dropped with `check_table_dependencies = 0` throws UNKNOWN_TABLE and an executable user-defined function that is not registered throws UNKNOWN_FUNCTION, and both made the table unattachable. Add these two codes to the filter of `addImplicitIndicesForColumn`. Executable functions are registered only after the table metadata is loaded at startup, so this also covers a deterministic executable function that is still configured: the table used to fail to load at every restart, now it loads without that implicit index. Build, validate and push the index inside the `try`, which removes the staging `IndexDescription` and its extra deep copy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f a dropped database `joinGet` keeps the database qualifier of its `Join` table, so after `DROP DATABASE ... SETTINGS check_table_dependencies = 0` the analysis of the ALIAS fails with UNKNOWN_DATABASE before the table is looked up, which the filter did not accept: the dependent table stayed unattachable. Add UNKNOWN_DATABASE. Tests: a cross-database `joinGet` arm in 05397, and a `test_executable_user_defined_function` case that pins UNKNOWN_FUNCTION: executable functions are registered only after the tables are loaded, so a deterministic executable function in an ALIAS with a string implicit index made the table fail to load at every restart (with `async_load_databases = 0` the server did not start). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own cold review; three rounds (heads
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261014-192700 |
|
Workflow [PR], commit [f8cbc53] Summary: ✅
AI ReviewSummaryReviewed Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
|
cc @Algunenano @shankar-iyer, could you review this and add |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 32 s compile time in total, 9 of them have a recent master baseline. |
…instead of reading them Versions before 25.12 serialized implicit min-max indices into the table definition (after any ALTER) and into Keeper metadata. The loader analyzed such a stored index as a regular one and then re-marked every index with the reserved name as implicit, so: - once the dictionary, `Join` table or function used by an ALIAS was gone (or, for an executable function, not yet registered at startup), the table could not be loaded, and a replica stayed read-only because `parseAndNormalize` analyzed the stored definition too; - for an ALIAS expression column (`b ALIAS key * 2`), `addImplicitIndicesForColumn` did not recognize the stored index (its `column_names` holds the columns of the expression) and generated it a second time, so loading failed with `Index with name auto_minmax_index_b already exists` even with every object present (measured on 25.8, 26.3, 26.8 and 26.9 with a table written and altered by 25.8); - a stored implicit index over a non-deterministic `joinGet` / `dictGet` ALIAS was kept, although such an index is never generated; - an index with the reserved name but another shape (e.g. `GRANULARITY 8` from a full-definition `ATTACH`) was re-marked implicit, so the next ALTER dropped it from the definition and the next load generated it with granularity 1, after which reading it failed with `Cannot read all marks`. Now a stored index identical to the one the generator builds is skipped without analysis, in `registerStorageMergeTree` (it is generated below exactly as for a table created now) and in `parseAndNormalize` (stripped from Keeper metadata); any other index is a regular index on both sides. The upgrade test creates and alters the table on 25.10; the executable function case attaches the stored form of the definition. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano
left a comment
There was a problem hiding this comment.
@groeneai In the future, unless they are about the same code, please prefer opening 2 PRs. Having one PR fixing several different bugs makes it harder to review and backport if necessary.
Also, please avoid adding backwards compatibility code for versions that aren't supported anymore unless they are critical and reported by real scenarios. Why do we need to workaround a tiny corner case from versions prior to 25.10 when the oldest supported release is 26.3 and nobody has complained about it?
This PR could have been 2 much simpler ones 😉
|
Thanks, noted for future PRs: one bug per PR unless the fixes touch the same code, and no compatibility code for unsupported versions unless the case is critical and reported. Nobody reported the legacy case. It came from an automated review comment on this PR (a table created and |
Related: #118527
Related: #121140
Related: #123926
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A MergeTree table with
add_minmax_index_for_string_columns(or the numeric / temporal variant) and anALIAScolumn that callsdictGet,joinGetor an executable user-defined function can now be loaded when that dictionary,Jointable (or its database) or function is missing, as an executable function is at every startup. A table written before 25.12 whose definition or Keeper metadata lists its implicit indices loads too, also with such an index over anALIASexpression, which failed withIndex with name ... already exists.Description
On 26.3.42.3 and 26.8.18.2, a MergeTree table with
add_minmax_index_for_string_columnsand anALIAScolumn that callsdictGetcannot be attached once that dictionary is gone, so withasync_load_databases = 0the server does not start. Found byStress test (arm_release)(report): the fuzzer cloned a table of05325_analyzer_lazy_alias_columnswith that setting before the test dropped the dictionary.addImplicitIndicesForColumnbuilt the index outside thetrythat skips one failing validation; this PR moves it inside and adds UNKNOWN_TABLE, UNKNOWN_DATABASE and UNKNOWN_FUNCTION. An executable function is registered after tables load, so its index is skipped at startup.Before 25.12, implicit indices were stored in the definition (after any
ALTER) and in Keeper, and loading analysed them as regular ones. A stored index identical to the generated one is now skipped unanalysed, locally and in Keeper, and generated as for a new table. It also loads a 25.8 table with one overa ALIAS id * 2(26.3/26.8/26.9 fail:Index with name auto_minmax_index_a already exists) and drops one overjoinGet, whichCREATEnever builds. Another reserved-name index (GRANULARITY 8) stays regular: re-marked implicit, it was dropped by anALTERand regenerated with granularity 1 (Cannot read all marks). A manualATTACHof such a definition still analyses it inInterpreterCreateQuery. My open #123938 conflicts only textually.Validation: 05397 fails before and passes 30/30 randomized runs after; the integration cases (a table created and altered on 25.10, a reserved-name index on a replica, executable functions across a restart) fail before, as does a mutant of each change.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125861]
Version info
26.11.1.298-master(included in26.11and later)