Repository navigation
Deprecate the minmax column statistics type - #108680
Conversation
The `minmax` statistics type is a subset of `basic` (which tracks the same numeric min/max plus string-length and null-count summaries). This deprecates `minmax` in favor of `basic`: - Creating `minmax` anew is rejected with `INCORRECT_QUERY`: this covers `CREATE ... STATISTICS(minmax)`, `ALTER ... ADD/MODIFY STATISTICS ... TYPE minmax`, and `auto_statistics_types` values containing `minmax`. The check lives in `MergeTreeStatisticsFactory::validate`. - Existing tables and parts keep working: `MergeTreeData::checkProperties` skips statistics validation on `attach`, so loading, reading, and merging parts that still reference `minmax` continue to work. - The default of the `auto_statistics_types` MergeTree setting changes from `minmax, uniq` to `basic, uniq`. Tests that used `minmax` are migrated to `basic`, and the random `auto_statistics_types` generator in `clickhouse-test` no longer emits `minmax` (otherwise random injection would fail unrelated tests). Adds a stateless test for the rejection and an integration test (`test_statistics_minmax_upgrade`) that creates a `minmax` table on an old server, upgrades, and verifies it still attaches, reads, and merges while new `minmax` statistics are rejected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [cc6586d] Summary: ✅
AI ReviewSummaryThis PR deprecates the Findings❌ Blockers
Final VerdictRequest changes: one new blocker remains, and the existing |
|
Is |
Yes, both of them are quite lightweight |
Reject deprecated `minmax` only when a statement newly introduces it, so an unrelated `ALTER` of an old table that still carries explicit `minmax` is not rejected. Fresh `CREATE` with `minmax` is still rejected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR deprecates the clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
| /// The `minmax` statistics type is deprecated: it is a subset of `basic`, which should be used instead. | ||
| /// Reject it only when it is declared explicitly (`STATISTICS(minmax)` in CREATE / ALTER) and newly | ||
| /// introduced by the current statement: | ||
| /// - Implicit `minmax` produced by the `auto_statistics_types` setting is tolerated here (including on |
There was a problem hiding this comment.
This explicitly grandfathers implicit minmax on freshly added columns of tables whose old auto_statistics_types still contains it. After upgrading such a table, ALTER TABLE ... ADD COLUMN x UInt64 takes the unchanged setting from getNewImplicitStatisticsTypes, addImplicitStatistics re-attaches implicit MinMax to x, and validate accepts it because desc.is_implicit is exempt here. That still creates new deprecated minmax metadata on the current version without any setting change, which contradicts the PR contract and the new 04411 test comments that new minmax can no longer be created.
Please grandfather existing implicit minmax only for columns that were already present before the ALTER, or rewrite grandfathered auto_statistics_types away from minmax before it can be applied to newly added columns.
| /// blocked. The rest of the statistics validation (unknown type, data-type support) still runs. | ||
| bool allow_deprecated_minmax = attach | ||
| || (is_alter | ||
| && old_metadata.columns.has(col.name) |
There was a problem hiding this comment.
allow_deprecated_minmax is keyed only by the post-ALTER column name. On an upgraded table that still carries explicit STATISTICS(minmax), ALTER TABLE ... RENAME COLUMN value TO value2 moves the existing ColumnDescription (including the explicit minmax) to value2, but old_metadata.columns.has(col.name) is now false, so MergeTreeStatisticsFactory::validate treats the inherited minmax as newly introduced and throws.
That breaks the PR contract that already-loaded old minmax metadata remains alterable. Please grandfather explicit minmax through renames as well, e.g. by tracing the pre-rename column identity instead of matching only the post-ALTER name, and add a regression test for RENAME COLUMN on an upgraded table.
| /// setting is unaffected. | ||
| for (const auto & command : commands) | ||
| { | ||
| if (command.type == AlterCommand::MODIFY_SETTING) |
There was a problem hiding this comment.
This still misses RESET SETTING auto_statistics_types on upgraded tables that have an old explicit auto_statistics_types = 'minmax, uniq'. After commands.apply, the reset removes the AST entry entirely, so getNewImplicitStatisticsTypes falls back to old_settings[auto_statistics_types], returns the deprecated value, and reports statistics_changed = false.
In the settings-only ALTER branch that means changeSettings switches storage_settings to the new default basic, uniq, but setInMemoryMetadata(new_metadata) is skipped, so inserts and merges continue using the old implicit MinMax metadata until restart or another ALTER rebuilds the columns. Please treat RESET SETTING auto_statistics_types as a real effective-value change and refresh implicit statistics immediately for both ordinary and replicated tables.
|
@hanfei1991 Could you please change the new default to |
I prefer to change uniq to uniq_v2 in another PR. This PR focuses on basic |
| bool allow_deprecated_minmax = attach | ||
| || (is_alter | ||
| && old_metadata.columns.has(col.name) | ||
| && old_metadata.columns.get(col.name).statistics.contains("minmax")); |
There was a problem hiding this comment.
allow_deprecated_minmax currently keys off old_metadata.columns.get(col.name).statistics.contains("minmax"), which matches both explicit and implicit old minmax. That lets an upgraded table whose legacy minmax came only from auto_statistics_types mint a fresh explicit minmax on the current version, for example with ALTER TABLE t ADD STATISTICS a TYPE minmax or ALTER TABLE t MODIFY COLUMN a UInt64 STATISTICS(minmax).
removeImplicitStatistics strips the inherited implicit stats from new_metadata, but old_metadata still makes allow_deprecated_minmax true here, so validate accepts the newly explicit declaration. That violates the PR contract that fresh STATISTICS(minmax) declarations are rejected after upgrade.
Please grandfather only columns whose previous StatisticsType::MinMax descriptor was already explicit (is_implicit == false), instead of using a plain contains("minmax") check.
rschu1ze
left a comment
There was a problem hiding this comment.
@hanfei1991 Question: This PR deprecates min-max statistics. Normally, deprecation of a feature is followed by the removal of the feature. I don't see any possibility to remove minmax statistics from ClickHouse in the long run after deprecation. Do you have a good idea how this can be achieved?
EDIT: Maybe the query execution can simply ignore minmax statistics at some point in future (perhaps in 12 months from now)?
| @@ -0,0 +1,37 @@ | |||
| -- Tags: no-fasttest | |||
| @@ -0,0 +1,151 @@ | |||
| import pytest | |||
|
|
|||
| from helpers.cluster import CLICKHOUSE_CI_MIN_TESTED_VERSION, ClickHouseCluster | |||
There was a problem hiding this comment.
CLICKHOUSE_CI_MIN_TESTED_VERSION is 25.3, but it is really a moving target. Consider hard-coding this to e.g. 26.5.
| if (statistics_types_str.empty()) | ||
| return; | ||
|
|
||
| /// Runs only on the setting-change path (CREATE / ALTER ... MODIFY SETTING auto_statistics_types), |
There was a problem hiding this comment.
Please remove l. 865-866. Function validateAutoStatisticsType has no authority about the places from which it is called. It cannot make any such claims.
| { | ||
| for (const auto & [type, desc] : stats.types_to_desc) | ||
| { | ||
| /// The `minmax` statistics type is deprecated: it is a subset of `basic`, which should be used instead. |
There was a problem hiding this comment.
L. 714-724 are way too much bla bla and it is also wrong to talk about other code parts (ALTER TABLE) in this file. Let's remove.
| validate_complex_projection(projection.name, {"_block_offset"}); | ||
| } | ||
|
|
||
| /// On CREATE the constructor passes the very same metadata object as both `new` and `old` (there is no |
There was a problem hiding this comment.
See my other comment about "bla bla" below, the same applies here. Can you try to compress the comment into a one-liner?
| /// with them in `auto_statistics_types`. Skipped for ATTACH and replicated propagation so that | ||
| /// existing tables which still carry `minmax` in the setting keep loading. | ||
| if (args.mode <= LoadingStrictnessLevel::CREATE) | ||
| validateAutoStatisticsTypes(statistics_types_str); |
There was a problem hiding this comment.
Context::getMergeTreeSettings already applies the session/profile compatibility defaults before this code copies the effective MergeTree settings. With the new 26.7 history entry for auto_statistics_types, compatibility = '26.6' makes the effective default here minmax, uniq even for a plain CREATE TABLE ... ENGINE = MergeTree with no explicit SETTINGS clause, so this unconditional validation now throws INCORRECT_QUERY for a statement that previously worked.
That breaks the backward-compatibility contract the PR just encoded in SettingsChangesHistory.cpp. Please validate only an explicit auto_statistics_types clause from the CREATE AST (or otherwise skip the check when the value comes only from compatibility/defaults), and add a regression test for SET compatibility = '26.6'; CREATE TABLE ... ENGINE = MergeTree ....
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 56/57 (98.25%) · Uncovered code |
|
@hanfei1991 @rschu1ze |
|
@fm4v It's supposed to be backward compatible, and we added an integration test in this PR. |
|
The PR goes great length that existing tables with (There is a philosophical argument that "deprecating X" (PR title) and "rejecting new instances of X" (what the PR actually does) are different things, but that's not relevant to the discussion.) |
|
Sorry for the missing info, I thought it would be an easier case. Created the issue with repros #111687 |
…tics-minmax Deprecate the minmax column statistics type
The
minmaxstatistics type is a subset ofbasic(which tracks the same numeric min/max plus string-length and null-count summaries). This deprecatesminmaxin favor ofbasic:minmaxanew is rejected withINCORRECT_QUERY: this coversCREATE ... STATISTICS(minmax),ALTER ... ADD/MODIFY STATISTICS ... TYPE minmax, andauto_statistics_typesvalues containingminmax. The check lives inMergeTreeStatisticsFactory::validate.MergeTreeData::checkPropertiesskips statistics validation onattach, so loading, reading, and merging parts that still referenceminmaxcontinue to work.auto_statistics_typesMergeTree setting changes fromminmax, uniqtobasic, uniq.Tests that used
minmaxare migrated tobasic, and the randomauto_statistics_typesgenerator inclickhouse-testno longer emitsminmax(otherwise random injection would fail unrelated tests). Adds a stateless test for the rejection and an integration test (test_statistics_minmax_upgrade) that creates aminmaxtable on an old server, upgrades, and verifies it still attaches, reads, and merges while newminmaxstatistics are rejected.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Deprecate the minmax column statistics type and change the default value of
auto_statistics_typesto 'basic, uniq'