Repository navigation
Conversation
Introduce `auto_statistics_columns` and `auto_statistics_exclude_columns` so MergeTree tables can limit which columns receive implicit statistics from `auto_statistics_types`, without affecting explicit per-column STATISTICS. Related: ClickHouse#111231 Co-authored-by: Cursor <[email protected]>
|
@ylw510 Please implement this analogous to https://clickhouse.com/docs/operations/settings/merge-tree-settings#exclude_materialize_skip_indexes_on_merge and |
|
Workflow [PR], commit [0258934] Summary: ✅
AI ReviewSummaryThe PR adds column exclusion settings for statistics materialization during inserts and merges on Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or changes to existing threads are needed. |
…cludes
Exclude columns from statistics materialization during merge/insert via
exclude_materialize_statistics_on_{merge,insert}. Explicit MATERIALIZE
STATISTICS is unaffected.
|
cc @cv4g. Can you take a look? |
Thank you for updating the PR! Yes, I will have a look |
|
I think this is a false positive. I've added the required header files. Could you please help confirm this? |
|
Not a false positive, but the header you added was not wrong either: it was correct when you wrote it, and master moved the declaration out from under you. Commit The clearest confirmation is inside your own diff: the same master commit rewrote this include in two files your PR also touches. In the merged tree, One line in That matches every caller of this overload on master (
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 111/111 (100.00%) · Uncovered code |
Resolved conflicts in statistics-related settings and merge logic: - Combined materialize_statistics_on_insert_max_table_size from master with exclude_materialize_statistics_on_insert from this branch - Updated documentation links to match master's URL format
This comment was marked as resolved.
This comment was marked as resolved.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes10 object files changed (+59.81 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units363 translation units recompiled, 3598 s compile time in total, 363 of them have a recent master baseline. |
Add the session and MergeTree exclude settings to the current version block so settings_changes_history CI passes, and drop an unused Statistics.h include from MergeTreeData.h.
|
@cv4g Everything looks good. Please take a review. Thanks. |
This comment was marked as resolved.
This comment was marked as resolved.
…umn-lists Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. - retargeted PR record [email protected] to 26.10 (settings-history check rule) - retargeted PR record [email protected] to 26.10 (settings-history check rule) Also resolved conflicts in: - `src/Storages/StorageReplicatedMergeTree.cpp` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Both `exclude_materialize_statistics_on_insert` and `exclude_materialize_statistics_on_merge` had a second "New setting" history record for 26.8, left over from a merge that put them into both the 26.9 and the 26.8 blocks of `SettingsChangesHistory.cpp`. `system.settings_changes` and the generated documentation therefore claimed that 26.8, which never shipped them, added them. Keep only the 26.10 record.
`parseIdentifiersOrStringLiteralsToSet` stops at the first token that does not continue the list and does not check that it reached the end of the string, and it only reads undotted names. So `n.x`, a column of a Nested structure, was read as `n` and excluded nothing, `a B` excluded only `a`, and `n.x, b` excluded neither `n.x` nor `b`. Add `parseColumnNameList`, which reads a name as an identifier, identifiers joined by dots or a non-empty string literal, requires the whole string to be the list and reports the offending token. It uses the default parser limits instead of the query settings, so that the outcome does not depend on the context the value is parsed in. Use it for both `exclude_materialize_statistics_on_insert` and `exclude_materialize_statistics_on_merge`; the released skip-index excludes keep their parser. `collectStatisticsToMaterialize` no longer needs the settings, which also drops the unneeded `Core/Settings.h` include from `Statistics.cpp`. Document the syntax: comma-separated, case-sensitive, backquotes or string literals for names with special characters, `n.x` for Nested columns, and that unknown names are ignored.
…needed An invalid `exclude_materialize_statistics_on_merge` was accepted by CREATE TABLE, ALTER TABLE and the `merge_tree` server configuration, and only failed when a merge parsed it. Every merge of the table then failed and was retried forever, which eventually leads to "too many parts", and a bad server-wide value did that to every MergeTree table including the system log tables. The list was also parsed before checking whether the table has statistics at all, so even a table with `auto_statistics_types = ''` could not merge. - Check the value in `MergeTreeSettingsImpl::sanityCheck`, which runs on CREATE, on a full-definition ATTACH, on ALTER ... MODIFY/RESET SETTING and for the `merge_tree` section at server startup. An invalid value is rejected there with an error naming the setting, and the server refuses to start with a bad server-wide value. - Parse the lists for merges and INSERTs only if the table has statistics, so a table without statistics is never affected. - On INSERT, parse `exclude_materialize_statistics_on_insert` before the `materialize_statistics_on_insert_max_table_size` check. An invalid value used to fail INSERTs into small tables only and to be silently accepted for tables above the limit; now it fails the INSERT into every table with statistics. The statistics themselves are still only created when they are built. - `collectStatisticsToMaterialize` now takes the parsed list and builds on the `ColumnsStatistics(const ColumnsDescription &)` constructor instead of repeating it.
A background merge between the two INSERTs and the first check would build statistics and make the check fail. Stop merges around it, as `02346_exclude_materialize_skip_indexes_on_merge` does.
The generator always set the table setting to an empty list, so merges with excluded columns were never fuzzed. Generate random combinations of the columns `c0` to `c4`, as is done for the skip index names of `exclude_materialize_skip_indexes_on_merge`. Names of columns that a table does not have are ignored, so the values can never make a CREATE TABLE fail.
The documentation of `exclude_materialize_statistics_on_merge` said that the statistics of the excluded columns are still built and stored by MATERIALIZE STATISTICS or during INSERTs. They are built, but the next merge drops them, even if every merged part has them. With the default `materialize_statistics_on_insert = 1` only the parts inserted since the last merge then have statistics for such a column, and the planner applies their selectivity to the whole table: a condition that matches all rows of a fresh part is estimated to match the whole table. Describe this, and recommend excluding the column on INSERT as well. Pin the behaviour in 04660: a merge of parts that all have statistics for an excluded column drops them. Whether the setting should behave differently (exclude the columns on INSERT as well, or keep existing statistics through merges that do not remove rows) is a design decision that is left open here.
… a table Like `exclude_materialize_skip_indexes_on_insert`, the session setting matches column names in every MergeTree table the query writes to: excluding `id` for the source table of a materialized view also excludes it in the view's target table, and in a settings profile the setting applies to every INSERT of the profile's users. That follows from it being a query setting, so document it and recommend setting it in the SETTINGS clause of the INSERTs it is meant for. 04661 pins the behaviour for a materialized view target.
… column renames The setting refers to columns by name and ALTER TABLE ... RENAME COLUMN / DROP COLUMN do not change it: after `b` is renamed to `b2`, merges build statistics for `b2` again, and a column added as `b` later is excluded. Document this and show how to change the setting in the same ALTER TABLE query. Rewriting the setting in `AlterCommand::apply` would not be replica-safe, because settings are not part of the replicated table metadata, and rejecting such ALTERs is a policy decision; both are left open here.
The first version of the change limited only the implicit statistics that `auto_statistics_types` adds. `exclude_materialize_statistics_on_insert` and `exclude_materialize_statistics_on_merge` also exclude statistics declared with `STATISTICS(...)` in the column definition. Document this change in scope for both settings, and cover it with a test.
Mutations use neither `materialize_statistics_on_merge` nor `exclude_materialize_statistics_on_merge`. A mutation that rewrites a column, such as ALTER TABLE ... UPDATE, builds statistics for it, and one that rewrites a whole part, such as ALTER TABLE ... DELETE or any mutation of a compact part (even a lightweight DELETE or MATERIALIZE STATISTICS of another column), builds statistics for all columns, the excluded ones included. Document this for both settings, and check in 04660 that rewriting an excluded column builds its statistics.
…erges Cover the merge paths the existing tests do not reach: - 05318: a vertical merge, with an excluded column in each stage (the sorting key column in the horizontal stage, another column in the vertical one), and a ReplacingMergeTree merge, which can remove rows and therefore builds the statistics of the new part from the merged rows. - 05319: two ReplicatedMergeTree replicas with the same list. Both end up with the merged part without statistics for the excluded column, whether a replica merges the part itself or fetches it. Nested and dotted column names and explicitly declared statistics are covered by 05316 and 05317.
…n_merge For ReplicatedMergeTree, ALTER TABLE ... MODIFY SETTING only changes the replica it runs on, and so does the settings part of a query that also changes columns, such as the RENAME COLUMN workaround documented for this setting. Replicas with different lists merge the same parts into different parts: the replica whose part differs from the one another replica committed logs "Data after merge is not byte-identical", discards its part and downloads the other one (seen as `DataAfterMergeDiffersFromReplica`). Document this and recommend changing the setting with a separate ALTER TABLE ... ON CLUSTER ... MODIFY SETTING.
…the size limit The example claimed that only `a` "and possibly `c`" get statistics on INSERT, but the String column `c` does get `basic` statistics. Also state that the setting has no effect on tables larger than `materialize_statistics_on_insert_max_table_size`, into which INSERTs build no statistics.
The documentation of `exclude_materialize_statistics_on_merge` linked to `exclude_materialize_statistics_on_insert` on the `materialize-statistics-on-insert` page of the session settings, but the docs generator routes that setting to the `other` page. The generator only rewrites links within a settings family, and the legacy-route redirect only resolves links without a page, so the anchor was broken. Link to the page the setting is generated on.
…ning paths An invalid value of exclude_materialize_statistics_on_insert or exclude_materialize_statistics_on_merge was reported as "...write a name with special characters in backquotes: (in the value of setting '...')". The setting is now part of the main message: "Cannot parse the value 'a b' of setting '...' as a comma-separated list of column names: unexpected 'b' at position 3. ...". parseColumnNameList takes the setting name for that, which leaves nothing for the parseExcludeStatisticsColumns wrapper to do, so it is removed. parseColumnNameList returns at once for an empty string, so that INSERTs do not tokenize the default value for every written part, and collectStatisticsToMaterialize no longer creates the statistics of the excluded columns only to erase them. Tests: - 05318 did not check that the merge is vertical, and it was not when the randomized min_bytes_for_full_part_storage made the parts packed. Disable packed parts and assert merge_algorithm = 'Vertical' from system.part_log. - 05332 checks the error messages and the rejection of an invalid value by a full-definition ATTACH. - test_exclude_materialize_statistics_config checks that merges use the value from the merge_tree config section and that the server does not start with an invalid one. - Fix a comment in 05316 that described an earlier revision of the change.
Style check requires a history entry for the current version when a setting is added. These settings were still tagged 26.10. Co-authored-by: ylong2483 <[email protected]>
Add
exclude_materialize_statistics_on_insertandexclude_materialize_statistics_on_mergeto control which columns have statistics built and stored during automatic materialization onMergeTreetables. The design mirrors the existingexclude_materialize_skip_indexes_on_{insert,merge}settings.The new settings only skip building and persisting statistics for named columns during INSERT or merge. They do not affect explicit per-column
STATISTICS(...)declarations orMATERIALIZE STATISTICS.exclude_materialize_statistics_on_insert(session setting): comma-delimited column list excluded from statistics materialization on INSERT. Can be set per query viaINSERT ... SETTINGS. Has no effect whenmaterialize_statistics_on_insert = 0.exclude_materialize_statistics_on_merge(MergeTree table setting): comma-delimited column list excluded from statistics materialization during background or explicit merges. Has no effect whenmaterialize_statistics_on_merge = 0.Excluded columns can still receive statistics via
MATERIALIZE STATISTICSor through the other materialization path (e.g. a column excluded on INSERT is materialized on a subsequent merge unless it is also listed inexclude_materialize_statistics_on_merge).Closes: #111231
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
You can now skip automatic statistics materialization for specific columns on
MergeTreetables: use the session settingexclude_materialize_statistics_on_insertto exclude columns on INSERT, and the table settingexclude_materialize_statistics_on_mergeto exclude columns during merges. ExplicitMATERIALIZE STATISTICSand per-columnSTATISTICS(...)declarations are unchanged.Workflow [PR]
Sync PR [sync-upstream/pr/111273]