Skip to content

Add system.table_settings, system.engine_settings and SHOW TABLE SETTINGS - #118544

Closed
buggins wants to merge 265 commits into
ClickHouse:masterfrom
buggins:engine-and-table-settings-59913-116543
Closed

buggins wants to merge 265 commits into
ClickHouse:masterfrom
buggins:engine-and-table-settings-59913-116543

Conversation

@buggins

@buggins buggins commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #116543
Closes: #59913
Related: #113269
Related: #116522

A table's settings are not always the ones its CREATE query states, and today there is no way to ask what they actually are. This adds two system tables and a SHOW statement over them.

  • system.engine_settings — the settings each engine accepts. This is @kaijaytu's [#59913] Implement system.engine_settings table #113269, carried over at @nikitamikhaylov's request and reworked; their commits keep their authorship.
  • system.table_settings — the settings a particular table has, with the value in effect and a source column saying where it came from.
  • SHOW [CHANGED] TABLE SETTINGS {FROM|IN} [db.]table [[NOT] [I]LIKE 'pattern'], a rewrite over the second, in the manner of SHOW COLUMNS.

The issue's own example — a Kafka table built from a named collection, whose settings system.tables cannot show:

CREATE TABLE k (a UInt64) ENGINE = Kafka(kc) SETTINGS kafka_poll_max_batch_size = 1000;

SELECT engine_full FROM system.tables WHERE name = 'k';
┌─engine_full─────────────────────────────────────────────┐
│ Kafka(kc) SETTINGS kafka_poll_max_batch_size = 1000     │   -- the collection's part is behind its name
└─────────────────────────────────────────────────────────┘

SHOW CHANGED TABLE SETTINGS FROM k;
┌─name─────────────────────────────┬─value─────────────────────────────┬─changed─┬─source───────────┐
│ input_format_allow_errors_num    │ 0                                 │       1 │ other            │
│ input_format_allow_errors_ratio  │ 0                                 │       1 │ other            │
│ input_format_skip_unknown_fields │ 1                                 │       1 │ other            │
│ kafka_broker_list                │ [HIDDEN]                          │       1 │ named_collection │
│ kafka_client_id                  │ ClickHouse-<host>-default-k       │       1 │ other            │
│ kafka_format                     │ [HIDDEN]                          │       1 │ named_collection │
│ kafka_group_name                 │ [HIDDEN]                          │       1 │ named_collection │
│ kafka_max_block_size             │ [HIDDEN]                          │       1 │ named_collection │
│ kafka_poll_max_batch_size        │ 1000                              │       1 │ definition       │
│ kafka_topic_list                 │ [HIDDEN]                          │       1 │ named_collection │
└──────────────────────────────────┴───────────────────────────────────┴─────────┴──────────────────┘

Which settings the collection supplied is the answer the issue asks for; their values stay as secret as system.named_collections keeps them - a collection is secret as a whole, so a reader who may not read it there does not read it here either. What the table's own clause states is shown as before.

source is one of default, config, compatibility, named_collection, definition, shared_metadata, other - declared in the order engines apply them, so ORDER BY source sorts by precedence. changed is source != 'default', as agreed on the issue. system.engine_settings and system.merge_tree_settings report it too: a value a config section or compatibility set is named there as well, where before it was only marked as changed.

Decisions I'd like from you

Six items below. Two of them, aliases and runtime, are settled and kept so the reasoning stays visible; the other four are open. None blocks the rest, all are small, and I'll do whichever you say.

1. Aliases — settled: both tables. system.settings gives an alias its own row with an alias_for column, and now so do system.engine_settings, system.table_settings and system.merge_tree_settings: a user who knows only the old name finds the setting. Attribution needed the alias machinery anyway — a definition may name a setting by any alias, and without the match SETTINGS monitor_batch_inserts = 1 reports other instead of definition. The one alias row system.merge_tree_settings gains (allow_experimental_block_number_column) is filtered with alias_for = '' wherever tooling reads the table as a list of settings: 03999_stateless_settings_history, upgrade_runner.sh, and the docs autogeneration queries under ci/jobs/scripts/docs/autogenerate/sql/, which already filter system.settings that way.

2. Should system.merge_tree_settings become a view over system.engine_settings? That is what #59913 proposes, and it is now exactly expressible — measured, not assumed: the names differ by 0 rows in a two-way EXCEPT (same for replicated_merge_tree_settings), the values are identical under a <merge_tree> config override and under --compatibility=23.3, and the columns match in order but for the leading engine_name. 05267 and 05268 now pin that parity for every engine of the family, in every shared column and both ways, under <merge_tree> and <replicated_merge_tree> sections and compatibility too. With aliases in engine_settings, the view carries AND alias_for = '' and still reproduces today's output row for row. I kept it out of scope, because it changes a table a lot of tooling reads and the safe default is that it keeps its present behaviour — but say the word and it is a small follow-up.

3. runtime — settled: removed. It was reserved for #116522, which the issue's "Additional context" names as the case it finds most interesting: a Kafka batch size reduced while the table runs, which a settings struct cannot report because StorageKafka keeps the reduction in a member. It was a value with no producer and no test, while every other value of the enum has both, so it is gone; such a value reports other until an engine reports it as its own source, and the comment on Other says where a new value belongs - before it, in the order the sources are applied in. Nothing stores these numbers, so #116522 can add it back without a migration.

4. Eighteen columns on system.table_settings is a lot. Each is there because system.merge_tree_settings or system.settings already ships it; min/max/readonly were dropped at one point as "always constant" and reinstated after measuring 100% NULL in both production tables. Each column costs about five lines. Happy to trim if you would rather have a narrower table — tell me which and I will cut them.

5. One change outside the settings tables: the MergeTree baseline takes compatibility from the global context. Context::getMergeTreeSettings and getReplicatedMergeTreeSettings build the server-wide baseline once and share it with every session and every table created afterwards, but they applied compatibility from whichever context asked first. This PR makes them read it from the global context. It is not a bugfix: I found no path where the first caller is anything else. Server::main builds both at startup from the global context (Server.cpp#L3304-L3310), and in clickhouse-local I built the parent commit and measured it: a session's SET compatibility = '23.3' rolls back 0 MergeTree defaults there too, while --compatibility=23.3 rolls back 47, as before. It came from a review-bot finding on this PR and stays because it states in the code a rule the server already follows; 05058 pins that rule from the reader's side, and test_table_settings_source::test_compatibility_is_reported pins it on a real server, whose default profile is where the baseline reads it from: every setting compatibility rolls back is reported as compatibility and holds a value that is not the compiled-in default, and a server whose profile does not set it reports none. It touches code every MergeTree table depends on, so I am glad to drop it or move it to its own PR if you would rather keep this one to the tables.

6. Who may read system.table_settings — chosen: a SELECT grant on it, then SHOW TABLES per table. Easy to overturn. A row can say more than the table's CREATE query, so I compared each source with how ClickHouse already protects the same fact:

A row's value, by source Also visible through Protected there by
definition SHOW CREATE TABLE, system.tables.create_table_query SHOW COLUMNS / SHOW TABLES, secrets masked — here the same, plus the grant on the table
named_collection system.named_collections the collection's grants — enforced here
config values of the nats/rabbitmq sections (username, password, vhost) nowhere always [HIDDEN] here
config / compatibility values: the server's <merge_tree>, <distributed> sections system.merge_tree_settings, system.server_settings a SELECT grant
values with macros expanded (Kafka topics, keeper_path, …) system.macros a SELECT grant
shared_metadata (S3Queue state in Keeper) system.s3_queue_settings a SELECT grant

Four ways to go:

  • A. No grant, rows filtered by SHOW TABLES, like system.tables. SHOW TABLE SETTINGS then needs what SHOW COLUMNS needs, but whoever sees one MergeTree table reads the server's MergeTree configuration, its macros and Keeper state.
  • B. A SELECT grant on system.table_settings, then rows filtered by SHOW TABLES — what system.parts, system.data_skipping_indices, system.projections and system.s3_queue_settings do. SHOW TABLE SETTINGS needs the grant too, as SHOW INDEX needs one on system.data_skipping_indices.
  • C. No grant, each value masked by its source unless the reader may read the matching system table: precise, but every new source needs a rule, other is a catch-all, and the source column itself still says a config section set something.
  • D. B, with rows filtered by SHOW COLUMNS, as SHOW CREATE TABLE checks — stricter than system.tables, which shows the same definition under SHOW TABLES.

I implemented B. It is the pattern of every per-table introspection table except the three that show only definitions, it needs no per-source rules, and it is the safe end to start from: moving to A later stays compatible, moving from A to B after a release would not. Its one oddity: a user without the grant cannot read the settings of their own temporary table, which SHOW CREATE TEMPORARY TABLE shows without one. 05263 pins the grant and 05137 the SHOW TABLES filter. system.engine_settings follows system.merge_tree_settings in any case — it reports the same server-wide values — so it needs a SELECT grant under every option (05262).

Why source, and what enumerating every settings struct turned up

A plain settings struct records only that a value changed, not who changed it. So BaseSettings can now also record where each value came from, for traits declared with DECLARE_SETTINGS_TRAITS_WITH_ORIGIN, which every engine settings struct and MergeTreeSettings now use: one 4-bit SettingOrigin per setting in a CompactArray, about 185 bytes for MergeTree's 369 settings, kept the way custom_settings_map is kept for traits that allow custom settings. Every other settings class, core Settings included, holds an empty placeholder under [[no_unique_address]] and compiles the recording away with if constexpr: BaseSettings over a two-setting traits measures 32 bytes without origins, as before, and 64 with them. set, resetToDefault, markUnchanged, read, readBinary and the hot-reload path all keep the record in step, so nothing in BaseSettings is virtual for it, and the origin API does not compile for traits that do not record origins. An engine that assigns a value itself uses the typed set(setting, value, origin) that DECLARE_SETTINGS_TYPED_SET generates for its public settings class; an assignment through operator[] keeps the recorded origin, for a value adjusted in place such as by expanding macros. Whoever loads a value records where it came from as it assigns it - a server config section, compatibility, a named collection, the table's own definition - and the marks travel with every copy of the object, from the server's baseline or a database into each table. Most engines therefore report system.table_settings from their settings object alone, with no second look at the stored CREATE query. What is left per engine is what no loader sees: Kafka, NATS and RabbitMQ report the values they work with (expanded macros, generated ids), the queue engines what Keeper holds, and the engines with no settings struct - plain object storage, Join, Set, File, URL, the Log family - what their clause states. A value is recorded as the definition's only where the stored definition states it: a restart or a short ATTACH loads it again without writing it back, so a setting a loader adds then stays unattributed (05239). Wiring the engines in batches with a verification query each caught three inferences that all looked obvious:

Engine The inference Why it was wrong
Kafka changed but not in the definition ⇒ a named collection set it StorageKafka's constructor pins three format settings
Distributed a definition names settings canonically it may name any alias, so those were attributed to nothing
S3Queue not in the definition ⇒ held in Keeper only 14 of ~40 are; the rest are plain members - so the rebuild records shared_metadata at the line that reads each value from the metadata

Things worth knowing before they are read as bugs:

  • DeltaLakeLocal was registered against the wrong settings struct — a user-visible bug. Its creator builds DataLakeStorageSettings like its thirteen siblings, but its has_builtin_setting_fn named StorageObjectStorageSettings. That predicate decides which names of a CREATE's single SETTINGS clause stay with the engine (InterpreterSetQuery::applySettingsFromQuery), so a data lake setting that shares its name with a query setting — eleven do, e.g. iceberg_max_number_datafiles_to_compact — was applied to the CREATE query and silently dropped from the table. Enumerating settings is what made the slip visible (320 settings where DeltaLakeS3 reported 360). Fixed here; covered by 05194.
  • A Distributed table said four settings had been set that nothing set. finalizeDistributedSettings copies the server's distributed_background_insert_* settings into the ones the definition leaves out, and copying a field of the same type copies its changed bit with it - so a CREATE stating no settings reported four as changed, two of them holding the value they would hold anyway. The value decides there instead of the bit.
  • A MySQL database gave its tables default settings — a user-visible bug. DatabaseMySQL built each table with MySQLSettings{} instead of the settings of the database, so the database's SETTINGS clause reached its connection pool and nothing else: connection_auto_close = 0 on the database left every table disconnecting after each read. The tables now get the database's settings, and report them as other, since they are not the tables' own definition. Covered by test_mysql_database_engine::test_table_settings_for_mysql_database, which checks what the tables report; no test measures the connection reuse itself. This and the DeltaLakeLocal fix above can each move to a PR of their own if you would rather keep this one to the tables.
  • system.engine_settings threw on every query in [#59913] Implement system.engine_settings table #113269 as it stood — DatabaseDataLakeCatalogType::NONE had no string form. Fixed and covered.
  • A data lake engine lists the other formats' settings. Iceberg reports 4 paimon_* and 1 delta*, because the family shares one struct — and ClickHouse really does accept SETTINGS paimon_keeper_path on an Iceberg table.
  • Most of an engine's settings are format settings. Kafka reports 355, of which 35 are kafka_*.
  • MergeTree writes config values into the definition. Under <merge_tree><index_granularity>4096, the source is definition, not config: loadFromQuery materialises the immutable settings into the stored AST, so the value belongs to the table now and will not follow a later config change. A non-immutable one (merge_max_block_size) does report config.
  • A value a named collection supplied is reported as the collection's. The settings object records, as it loads the collection, which keys it actually took its values from - everything the collection holds, less what the engine arguments overrode - and a later assignment by the table's clause or by the engine itself forgets the mark; those left are reported as named_collection, told apart from a default, from what the session supplied and from what the table's own clause states. Nothing is looked up when the table is read, so a collection altered afterwards cannot speak for a table it did not build, and a key the engine arguments overrode is not attributed to it: a table's arguments are its definition, as its SETTINGS clause is, while a MySQL or PostgreSQL database's are reported as other in its tables, which state none of them. No comparison of values could do any of this, since a collection may well state the compiled-in default. The values themselves are hidden as system.named_collections hides them, since SHOW TABLES on one table is a weaker grant than reading a collection: a reader without that grant gets the names and [HIDDEN], which 05243 pins along with the two surfaces that refuse the same reader. Kafka, PostgreSQL, NATS, RabbitMQ and MySQL do this, all through one shared loader; YTsaurus goes through it too but reports none, because a collection supplies only its connection keys, not its settings.
  • A table reports the values it works with, not the ones it was given. Kafka, RabbitMQ and NATS all expand macros in their settings. Kafka generates a kafka_client_id and RabbitMQ a queue base when none is given (reported as other); RabbitMQ and NATS take credentials from their server config section when the table gives none (reported as config). Such a secret, and a macro from the server config expanded into a secret the table states, is the server's, and always [HIDDEN]. use_hive_partitioning reports what the definition states, which is what decides whether S3Queue/AzureQueue read hive columns from the path - not partitioning_mode, into which it is folded.
  • isValueChanged means nothing on a reconstructed settings object. StorageObjectStorageQueue::getSettings assigns every setting it knows, so attribution compares against the default instead. It also does not assign what it does not know - the shared format settings, which are most of the struct - so those kept a compiled-in default while being attributed to the definition: a table stating input_format_tsv_skip_first_lines = 2 reported 0, though the engine honours 2. They now report what the clause states, keyed off the one moment the rebuild's coverage is visible (enumeration reports a setting it assigned as other, one it never touched as default). 05269 compares a queue table's rows with system.s3_queue_settings, which still shows the default there; the only other difference is changed for a setting held in Keeper, which that table counts only where the CREATE query states it.
  • Three engines now report the settings they act on, not only what their clause states. Join keeps no settings struct, and the six of its eight settings that its clause leaves out come from the server's settings, read from the global context when the table is loaded - not from the creating session, which a test at CREATE and at ATTACH disproved. It reports all eight from the values it holds: definition if stated, default when equal to the default, other when not, as Distributed reports what it copies from the server. For Distributed, background_insert_sleep_time_ms and background_insert_max_sleep_time_ms default to 0, meaning "the server's setting", so they are measured against the default of that setting - their default is 100 and 30000 - and a table that takes it reports default (05196, 05246). It is listed in system.engine_settings now too, with the values a table created today would get, so its table rows and its engine rows agree. So is the Log family, whose disk and storage_policy nothing described before, since it keeps no settings struct either; its tables report both, with the disk the table keeps its data on - the one its storage_policy chose where it named no disk. An engine that rejects a SETTINGS clause can no longer register a settings enumeration at all - StorageFactory refuses it - where before system.engine_settings silently skipped one. Set reported nothing at all, although disk and persistent - the only two settings it acts on - are kept; both engines take those two rows from one helper now, so they describe them alike. The Kafka engine has two storages and only one of them reported: a table that keeps its offsets in Keeper reported 6 rows where a plain one reports 355, with its macros unexpanded; both share one implementation now. 05221, 05222 and 05223 cover them, including that the values reported are the ones the engines enforce.
  • Eleven more engines report their settings, where before they reported none. They all consumed their settings at construction, so system.engine_settings advertised settings whose tables showed nothing. The six plain object storage engines build no settings object at all - the clause becomes a FormatSettings, which carries no setting names - so they report what their own clause states, as File and URL do; what the clause leaves out stays unreported, since nothing holds it under its own name. A setting a clause states is described from what its engine reports to system.engine_settings, so the two tables cannot describe it differently; the base implementation does that for every engine now, and reads no definition at all for a view, a dictionary or a system table. PostgreSQL, QueryRunner and MaterializedPostgreSQL do have a settings object and only dropped it, so each keeps it and enumerates on demand, as Kafka and the queue engines do; PostgreSQL had nothing to keep, and its three creators - the engine, the PostgreSQL database and the postgresql table function - now pass the settings they build their connection pool from. PostgreSQLSettings overlays the whole of the creating session, which marks every setting changed and so says nothing about provenance, so the source is recomputed from the value: definition where the clause states it, default where it is the compiled-in default, other otherwise. An object storage row also carries the type, default, description and tier its settings struct declares, so an obsolete setting does not describe itself as a production one. With this no engine reports nothing any more, and 05139, which pinned the gap, is deleted rather than inverted; 05224 to 05228 replace it, with integration tests for the paths that need a real PostgreSQL, NATS or RabbitMQ. A table of a MaterializedPostgreSQL database is a different thing again: the replication settings belong to the database, and the table is listed as the nested table the data is materialized into, so what it reports is that table's settings.
  • Every settings struct was audited against what the tables report - all twenty-one, engine by engine, checked on a running server. It found the queue-table defect above (fixed here) and the known parallel_inserts bug, ObjectStorageQueue: parallel_inserts is declared in the table metadata and never written, so the setting has no effect #119018. Two smaller oddities are documented rather than reported: a data lake catalog's copy of its own settings into each of its tables is a no-op - harmlessly, since those storage_* settings are deprecated and getCatalog rejects them, so a copy that worked would break every catalog table; and after_processing_move_access_key_id prints in clear, which matches how engine arguments treat an access key id, while the data lake registry masks its own spelling of the same thing. Its own findings have since been fixed - see the two bullets above.
Secrets, access and performance
  • Secrets are masked through the existing per-engine registries under the same gate as SHOW CREATE TABLE. Masking here is per row rather than whole-statement, so is_masked tells a redaction apart from a value that is literally [HIDDEN] - and it is 1 only where something was hidden, since several of those rules render whatever they are given and a URI with no password in it comes back as it went in. A value is asked about under every name its setting answers to - whether enumerated, stated in the clause, or the effective value an engine reports - so a rule registered under an alias covers the setting however it is spelled.
  • All three settings tables mask a secret value the same way - system.engine_settings and system.merge_tree_settings too, although only the server configuration could put one there - and write their rows through one SettingRowWriter, so they cannot drift on masking or on alias rows. default is printed as compiled in, which is safe only while every secret engine setting defaults to empty; 05214 pins that, finding the secret settings from the masked query_log text rather than a list, so a secret added later is covered.
  • Access: a SELECT grant on system.table_settings, then SHOW TABLES per database and per table, plus displaySecretsInShowAndSelect for real values - see decision 6.
  • SHOW TABLE SETTINGS on a table that does not exist, or that the user may not see, is an error (UNKNOWN_TABLE, ACCESS_DENIED), as for SHOW CREATE TABLE, rather than an empty result that would read as a table with nothing changed (05240, 05137).
  • database and table are pushed into the scan, so naming one table does not open the rest of the database: 0.8 ms per query against 9.2 ms on 40 MergeTree tables. For table = '...' the name itself is the filter, with nothing listed first, and DatabasePostgreSQL::getTablesIterator now applies the name filter it used to ignore, before it fetches each table's structure - so a PostgreSQL database is asked about the one table named. Merge passes that filter too, and relies on it: a Merge table over a PostgreSQL database now reads only the tables its pattern names, where it used to read every table of that database (test_postgresql_database_engine). system.tables and system.columns call the iterator without one. engine is pushed down as well, applied as soon as a table is resolved and before its settings are read, as system.tables does: 2 ms against 10 ms for WHERE engine = 'Log' over 123 tables. A view, a dictionary and a system table are skipped without reading their definition at all, which halved a full scan of 65208 rows, from 31 ms to 16 ms.
  • A data lake catalog is asked for its tables with the table-name hint, as system.tables asks it. Counted against a mock Iceberg REST catalog, SHOW TABLE SETTINGS for one table dropped from 7 catalog requests to 3, and a database-only query from 13 to 8; the only extra request since then is one lookup per table whose metadata could not be resolved. A table whose metadata cannot be fetched still fails the query with the catalog's error under database_datalake_require_metadata_access (covered in test_database_iceberg). A Remote database keeps the plain iterator, so an unreachable server yields no rows rather than an error, whether the query names a table or only the database; SHOW TABLE SETTINGS looks the table up itself and reports the error (05215).
  • SHOW TABLE SETTINGS FROM t resolves t to a session temporary table first, as SHOW CREATE TABLE does, and reads the table once: a pattern is matched against every name a setting answers to by grouping the rows the table already returns, rather than by a second SELECT over it, which for a queue table would fetch its settings from Keeper twice.
  • A config section is still the source a table reports after a restart, which loads it from what it stored - and what it stored says nothing about that section, so the table takes it from the server's baseline again (test_table_settings_source::test_config_source_survives_a_restart; 05239 covers the same for the definition).
  • shared_metadata is covered without an S3 endpoint (05140), including a value in Keeper outranking what the table's own CREATE query states. 05219 pins the values a queue table reports for settings it keeps nowhere, and 05220 pins ALTER ... MODIFY SETTING / RESET SETTING reporting. A value an engine adjusts while it runs, which Reduce the Kafka streaming batch size after a memory limit error instead of retrying the same size #116522 is about, is reported as other until an engine reports it as its own source.

Known limitations

  • Kafka does not report what its <kafka> server config section supplies - the SASL credentials and the security protocol - when the table states none: system.table_settings shows the empty setting with source default, while the consumer uses the section's value. Reporting it properly means capturing the section's values when the table is built; left for a follow-up.
  • A queue table (S3Queue, AzureQueue) reports every setting held in Keeper as shared_metadata, and so as changed, even where the value is the compiled-in default - Keeper is where the table takes it from. SHOW CHANGED TABLE SETTINGS on a queue table therefore lists about a dozen such rows.
  • For the private repository's sync: MergeTreeSettings::loadFromQuery takes a LoadFromQuery struct instead of two booleans; MergeTreeSettings::dumpToSystemMergeTreeSettingsColumns and StorageMemory::getMemorySettingsRef are removed (getMemorySettings returns a snapshot); StorageEmbeddedRocksDB::getSettings returns a snapshot; applyChanges is applyDefinition on MemorySettings, RocksDBSettings and GenerateRandomSettings; DECLARE_SETTINGS_TRAITS_COMMON takes one more argument. 05267 and 05268 leave out the Shared* engines of that build. One contract changes without a compile error: a masking rule in an engine's SETTINGS_TO_HIDE now returns the masked value itself ([HIDDEN]), and ASTSetQuery adds the SQL quotes - all six public registries are converted, but a rule of the private build that still returns '[HIDDEN]' would print doubly quoted in SHOW CREATE TABLE. BaseSettings changes nothing for a settings struct that does not opt into DECLARE_SETTINGS_TRAITS_WITH_ORIGIN: the public macros keep their signatures, the origin record takes no space, and no serialized form includes it.

Size of the change

Most modified C++ files change a few lines — the DECLARE_SETTINGS_TRAITS_WITH_ORIGIN of each settings struct and one enumerateSettings declaration, plus its registration (enumerateCompiledDefaults<XSettings> for the engines that show their compiled defaults), and each loader recording the origin it assigns — and most of those are files #113269 already touched; the design lives in about fifteen files, most of them new.

Against the merge base; "≤ 20 lines" counts files that change 20 lines or fewer, "Also in #113269" counts files that pull request touched (63 in all).

Files Count Added Removed ≤ 20 lines Also in #113269
C++ (.h/.cpp), modified 134 1738 391 112 58
C++ (.h/.cpp), new 22 1987 0 3 2
Tests and other, modified 20 667 67 12 0
Tests and other, new 125 4074 0 60 0
Total 290 8416 444 177 60

One of the new files is existing code that only changed address: engineSettingsToHide.h is the masking registry list that used to sit in ASTSetQuery.cpp. It does not show up as a rename in git diff -M -C, because it is a function-level extraction - comparing it against the merge-base version is the fastest way to confirm nothing changed in the move.

This branch had extracted a second one, extractTableNameFilter.{h,cpp}, the filter pushdown system.tables already had; master has since extracted the same logic into the same two files for system.iceberg_history, so the merge takes master's and this pull request only calls it - with table as the column, since name here is the setting's name.

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added system.engine_settings, listing the settings each table engine accepts, and system.table_settings, listing the settings in effect for each table together with a source column saying where each value came from — a default, the server config, compatibility, the table's own SETTINGS clause, a named collection, or shared metadata in Keeper. SHOW [CHANGED] TABLE SETTINGS FROM <table> queries the latter.

system.merge_tree_settings and system.replicated_merge_tree_settings gain two columns: source, between changed and description, and alias_for at the end. They also gain a row for each alias of a setting, as system.settings already has - today one, allow_experimental_block_number_column, an alias of enable_block_number_column. So a query that reads these tables as a list of settings, one row per setting, should add WHERE alias_for = ''; one that selects every column sees two more; and one that reads columns by position rather than by name sees everything after changed move by one.

Both new tables are read as system.merge_tree_settings and system.parts are: with a SELECT grant on the table where select_from_system_db_requires_grant is on, its default. system.table_settings also shows only the tables the reader may SHOW TABLES - for an Alias table, the table it is an alias of too - and SHOW TABLE SETTINGS, which reads it, needs the same privileges. A secret is masked as in SHOW CREATE TABLE. The value of a setting a named collection supplied is reported as [HIDDEN], whole, unless the reader may read that collection from system.named_collections - secret as a whole, as that table and SHOW CREATE TABLE already treat a collection. A value a table takes from the server configuration's nats or rabbitmq section - the username, password or vhost of a table that states none of its own - and a macro from it expanded into a secret the table or its named collection states, are always [HIDDEN].

Two engines behave differently as a result, both because a setting they accepted was being ignored. A MySQL database now passes its own settings to the tables it makes rather than compiled-in defaults. The connection pool already took the database's SETTINGS - its size, timeouts and retries are unchanged - so what changes is connection_auto_close: with connection_auto_close = 0 on the database, or in its named collection, its tables keep up to connection_pool_size idle connections to the MySQL server open for every table that has been read, where they used to close them after each read. To keep the previous behaviour, remove it. And a DeltaLakeLocal table's SETTINGS clause is now stored as the table's own engine settings, as it already is for DeltaLake on S3 and Azure, rather than applied to the CREATE query and dropped. This changes only the settings whose names are also query settings; the one with an effect before was allow_experimental_delta_kernel_rs, which used to switch delta-kernel off for the CREATE itself and is now stored and ignored, as it is for the other DeltaLake engines. Separately, a Merge table over a PostgreSQL database now reads only the tables its pattern names: the database ignored the table filter Merge relies on, so such a table used to read every table of that database.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/118544]

buggins and others added 24 commits September 3, 2026 11:28
Pins what the table reports before engines start overriding
`getTableSettings`: each engine reports its `SETTINGS` clause, including the
ones that keep no settings struct of their own, a table with no clause
contributes no rows, and `source` is `definition` throughout.

The masking assertions matter most. A `Kafka` table's `kafka_sasl_password`
must read `[HIDDEN]` with `is_masked = 1`, and nothing else in that table -
or in any table of an engine with no secret settings - may be masked. Getting
this wrong in either direction is worse than a wrong value: masking too little
leaks a credential, masking too much hides a value with nothing to say it is
hidden.

Tagged `no-fasttest` because those assertions need `Kafka`, which is an
optional build.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…S` clause

First engine to override `getTableSettings`, and the shape the rest will
follow. A `Kafka` table now reports all 351 of its settings rather than the
five its definition happens to name, each with its default, type, description
and where the value came from.

`enumerateSettingsFromImpl` reads a `BaseSettings` instance into the common
form. It is deliberately the only per-struct exposure: `system.engine_settings`
will be moved onto it later and its `fillEngineSettingsColumns` deleted, so
that a settings struct is read in one place and the two tables cannot
disagree about the same setting.

A struct records only that a value differs from its default, never what
changed it, so the storage attributes. Three things can set a `Kafka`
setting - a named collection from the engine arguments, the `SETTINGS`
clause, and this storage's own constructor, which pins a few format settings.
The collection is consulted by name for the settings it really carries, rather
than inferring one from "changed but not in the definition": that inference
looked right and was wrong, attributing the constructor's
`input_format_skip_unknown_fields` to a collection the table never referenced.
Those keep `source = other`, which is what that value is for.

`IStorage::getSettingNamesStatedInDefinition` gives an override the names the
definition states, sharing the create-query read with the base implementation.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…`, `EmbeddedRocksDB` and `FileLog`

These engines take their settings from two places only - their compiled
defaults and the table's own `SETTINGS` clause - so each override is the
shared `attributeSettingsStatedInDefinition` over the struct's
`enumerateSettings`, and the interesting work is in neither.

Add the `default` column, now that there is something to put in it. It is
empty for a setting known only from a `SETTINGS` clause: an engine that keeps
no settings struct has no default to report, the same reason `description` and
`type` are empty there. A `Memory` table now shows `max_rows_to_keep = 100`
against a default of `0`, and a `Join` table still shows only `persistent`,
with nothing behind it.

`tier` and `is_obsolete` stay out for now. Unlike an empty default, which
reads as "none known", the natural values for them - `Production` and `0` -
are claims, and no engine that keeps no settings struct can support either.
They need `TableSetting::tier` to become optional first.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…saurus`

A `MySQL` table now reports all eight of its settings, so
`connection_pool_size = 7` is visible against its default of 16 rather than
only as a line in the `CREATE` query.

Each of these engines can also take settings from a named collection, and none
of them keeps the collection's name the way `StorageKafka` does. Rather than
inferring a collection from "changed but not stated in the definition" - the
inference that wrongly credited `StorageKafka`'s own constructor to one - a
setting these storages cannot account for reports `source = other`. Naming the
collection would mean each storage retaining it, which is a change to their
constructors and belongs on its own.

`MaterializedPostgreSQL` is left for later: it takes its settings by
`unique_ptr` in the constructor without keeping them.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…oing so

`Distributed` is the first engine to report a setting as coming from a config
section: it starts from the server-effective settings, the `distributed`
section applied over the compiled defaults, so anything that section changed
and the definition does not restate is `source = config`.

`Hive` reports only defaults and its definition. It has a `hive` config
section and `HiveSettings::loadFromConfig` to read it, but nothing calls that
function, so the path is dead and claiming `config` for it would be wrong.

Attribution now matches a setting's aliases as well as its name. A definition
may state any of them - `SETTINGS monitor_batch_inserts = 1` for
`background_insert_batch` - and matching only the canonical name reported the
value as coming from somewhere unaccounted for. Aliases were until now filed
as a question of whether a user can find a setting by its old name; an
unresolved one also makes the table state the wrong source. The names come
from `Traits::settingsToAliases`, which every settings struct generates.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…definition

A `MergeTree` table is created from the settings the server has in effect,
never from the compiled defaults, and `Context` builds those by applying the
`compatibility` setting first and the `merge_tree` config section second. Both
leave a setting merely "changed", so telling them apart means rebuilding the
two intermediate baselines and asking what each step altered. Config is tested
first, because it is applied second and so wins.

The extra baseline costs nothing in the ordinary case: `compatibility` is
empty by default, `applyCompatibilitySetting` then returns immediately, and no
setting can carry that origin, so it is not built at all.

The override sits on `MergeTreeData`, so both storages inherit it, with
`supportsReplication` choosing between the `merge_tree` and
`replicated_merge_tree` baselines exactly as `registerStorageMergeTree` does
when it creates a table.

With `compatibility = 23.3` a table reports 48 settings rolled back to their
older values, each against the current default - which is the question this
column exists to answer. Note that a setting the config supplies may still
report `definition`: `loadFromQuery` writes the immutable ones into the stored
`CREATE` query, so `index_granularity` really does live in the table's
definition afterwards and will not follow a later change to the config.

The test now lists the settings each definition names rather than every row.
It listed all of them while engines reported only their `SETTINGS` clause,
which was three rows and is now 366; pinning the value of every `MergeTree`
setting would make the reference churn whenever any default changed. That an
engine with a settings struct reports defaults, and one without does not, is
checked separately.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…eeper

These engines keep no settings object. `getSettings` rebuilds one from three
places: the table metadata in Keeper, which every replica shares; the metadata
object; and plain members of this storage. That is the case this accessor was
made a method on the storage for - an `ALTER ... MODIFY SETTING` run on
another replica changes the shared metadata, and this replica reports the new
value while its own `CREATE` query still states the old one.

Two things follow, both of which cost an attempt to get wrong.

`getSettings` assigns every setting it knows, so `isValueChanged` is true for
all of them and distinguishes nothing. Attribution compares each value with
its default instead, which is what `dumpToSystemEngineSettingsColumns` already
does against the table metadata, and for the same reason.

Only fourteen of the settings actually come from the shared metadata; the rest
are plain members. Marking everything the definition does not state as
`shared_metadata` would have credited Keeper with a couple of dozen settings
it never held - the same error as crediting a named collection for what
`StorageKafka`'s constructor sets. The fourteen are listed explicitly, and are
applied after the definition rather than before, because for them the shared
metadata is what the table uses.

Not exercised locally: creating one of these tables needs both S3 and Keeper.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
An `Iceberg`, `DeltaLake` or `Paimon` table now reports all 356 settings of
`DataLakeStorageSettings` rather than the handful its definition names.

The settings belong to the configuration, not to the storage:
`DataLakeConfiguration` holds them, and `StorageObjectStorage` has no way to
reach them. So the configuration answers for them, with a base implementation
returning nothing - plain `S3`, `GCS`, `AzureBlobStorage` and `HDFS` consume
their settings at creation and keep nothing to report, and fall back to the
`SETTINGS` clause their definition states.

`MaterializedPostgreSQL` is still on the base implementation for the same
reason: it takes its settings by `unique_ptr` in the constructor without
keeping them, so there is nothing to enumerate without changing how it is
built.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A `MergeTree` setting can be written under more than one name -
`allow_experimental_block_number_column` for `enable_block_number_column` -
and `system.merge_tree_settings` shows only the one it is declared under, so
looking it up by the other finds nothing. A user who knows a setting by its
older name has no way to reach it.

Follow `system.settings`: a setting gets its own row with `alias_for` empty,
and a further row per other name carrying the same values with `alias_for`
naming the one it is declared under.

The cost is small enough to have been worth measuring first, since these rows
are per table rather than per engine: two aliases across all 366 `MergeTree`
settings, five across `Distributed`, none at all for `Kafka`, the data lakes
or the queue engines.

The names were already to hand. Attribution collects them so that a definition
naming a setting by an alias is recognised, without which the value is
reported as coming from somewhere unaccounted for.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… has

`system.settings` and `system.merge_tree_settings` are in production and
between them settle what a settings table looks like. This one was missing six
of their columns: `min`, `max`, `disallowed_values`, `readonly`, `is_obsolete`
and `tier`.

They were left out on the grounds that constraints exist only for
`MergeTreeSettings`, so `min`, `max` and `disallowed_values` would be empty
almost everywhere. That objection does not survive contact with the tables it
was measured against: with no profile declaring a constraint, both are empty
for *every* row of `system.settings` and of `system.merge_tree_settings`.
Empty means no constraint, and says so honestly.

The twelve columns those tables share now appear here in their order, with
their meanings, so that what a reader knows about them carries over. This also
retires the `alterable` column drafted earlier: `readonly` already answers
whether something forbids changing a setting, with semantics that are settled
and shipped, and reports 1 for exactly the eleven settings
`MergeTreeSettings::isReadonlySetting` marks.

A `MergeTree` table now returns what `system.merge_tree_settings` returns, and
the test pins the one row where they differ: `loadFromQuery` writes the
immutable settings into the stored `CREATE` query, so `index_granularity` is
stated in the table's definition and `changed` there, while nothing set it on
the server.

`tier` is not nullable, matching those tables. For a setting known only from a
`SETTINGS` clause there is no settings struct to ask, and it reads
`Production`; such rows have an empty `default`, `type` and `description` too,
which is what marks them out.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
`system.engine_settings` and `system.table_settings` each walked a
`BaseSettings` instance and read the same accessors out of it, through two
separate per-struct functions: `fillEngineSettingsColumns` wrote columns,
`enumerateSettings` returned values. Twenty structs carried both, and the two
could drift - nothing stopped one table reporting a setting's tier or
description differently from the other.

The registration hook now returns `TableSettings`, the same type
`IStorage::getTableSettings` returns, so `system.engine_settings` differs from
`system.table_settings` only in whose instance it enumerates: a server-level
one rather than a table's. `FillEngineSettingsColumns.h` and the twenty
functions behind it are gone.

The constraint lookup was duplicated the same way and is now
`MergeTreeSettings::applyConstraints`, called by both.

Five structs needed `enumerateSettings` before their old function could go -
`Set`, `QueryRunner`, `StorageObjectStorage`, `PostgreSQL` and
`MaterializedPostgreSQL`. Their storages keep no settings object, so they
report nothing per table, but they can still describe their engine.

Roughly line-neutral: the saving is one mechanism where there were two, not
fewer lines. Both tables' tests are unchanged, and a `Memory` setting now
reads identically from either.

`dumpToSystemMergeTreeSettingsColumns` is untouched - it serves
`system.merge_tree_settings`, which is not part of this work.

Related: ClickHouse#59913

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
The name the issue asks for, over the table that does the work:

    SHOW [CHANGED] TABLE SETTINGS {FROM | IN} [db.]table [[NOT] [I]LIKE 'pattern']

rewritten into a `SELECT` over `system.table_settings`, the way `SHOW COLUMNS`
and `SHOW INDEXES` are rewritten over `system.columns`. `CHANGED` keeps the
settings something other than the default set, which on most tables is the
handful anyone is looking for.

It prints `name`, `value`, `changed` and `source`, and deliberately not
`description`: those run to paragraphs, and four columns fit a terminal where
five do not. Everything past that - descriptions, other engines, joining
`system.tables`, filtering on `source` - is a query against the table, which
is why the table is the feature and this is a convenience over it.

`SHOW TABLE SETTINGS` shares a prefix with two existing statements. `SHOW
TABLES` rejects the singular `TABLE` and restores its position, and `SHOW
[CHANGED] SETTINGS`, about the session's settings, is only reached when
`TABLE` does not follow. The parser goes before both so a mistyped statement
is diagnosed as this one rather than as `SHOW TABLES`, and the test checks all
three still parse as themselves.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
`source` distinguishes eight origins and only two of them were covered. The
two that matter most were not: a value a server config section supplies, and
one the `compatibility` setting rolls back. Neither can be reached from a
plain query - `Context` reads both once into a server-wide instance - so this
runs `clickhouse-local` with a config file and with `--compatibility`.

Covered: a `MergeTree` setting and a `Distributed` setting the config
supplies; the table's own `SETTINGS` clause winning over the config; that
clause naming a setting by an alias, which used to report the value as coming
from nowhere accountable; `compatibility` rolling settings back, each away
from its current default; and none of those origins appearing when nothing
sets anything.

`shared_metadata` stays uncovered here: reaching it means creating an
`S3Queue` table, which needs both S3 and Keeper, so the integration tests are
where it is first exercised.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
The source already skipped databases the filter excluded, but within a
database it opened every table: a scan naming one table still built the
settings of all of them. Reading a table's settings is not free - it reads
the stored `CREATE` query and reconstructs baselines - so the cost fell on
exactly the query the feature exists to serve.

Build a second filter expression over `{database, table}` and pass the
surviving names to `getTablesIterator`, which already accepts a predicate.

On 40 `MergeTree` tables, twenty scans naming one table each: 9.2 ms per
query before, 0.8 ms after.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
…ree` settings

`Context::getMergeTreeSettings` applies the global `compatibility` when it
builds the instance a table is created from, so reading a session's own
value here compared the server's effective settings against a baseline the
server never used, and could attribute a setting to `config` that came from
`compatibility` or the other way round.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
`ASTSetQuery::formatImpl` converted every change's `Field` to a `String` just
to hand it to `maskSettingValue`, which then looked the name up and, for
almost every setting, returned nothing. Formatting a query with secrets
hidden is on the query-logging path, so that was one wasted allocation per
setting on every logged query carrying a `SETTINGS` clause.

Add `canMaskSettingValue`, the same lookup without the value, and gate the
conversion on it. Both entry points now share one `findMask`, so which
settings are secret and what they look like masked cannot drift apart.
`format_avro_schema_registry_url` stays outside that lookup: it belongs to no
engine and masks only when the value really embeds a password, so it has no
rule that always yields a masked rendering.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
It runs `clickhouse-local` over `MergeTree` and `Distributed` with a config
file. Both engines are core and present in the fasttest build, and nothing
in the test reaches an external service, so the tag only hid the test from a
build that can run it.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
Its creator calls `getDataLakeStorageSettings` and builds a
`StorageLocalDeltaLakeConfiguration` from the result, exactly like the other
thirteen data lake registrations - but it was the only one of them whose
`has_builtin_setting_fn` named `StorageObjectStorageSettings`, the predicate
of the plain object storage engines.

Nothing depended on the answer before, so the slip was invisible. Enumerating
the settings makes it visible: `DeltaLakeLocal` reported 316 settings and
none of the data lake ones, where `DeltaLake`, `DeltaLakeS3` and
`DeltaLakeAzure` each reported 356.

Test both families for agreement rather than for a count, so it holds as
settings are added and passes in a build that has neither engine.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
…from

`docs/reference/statements/show.mdx` is generated in full from the `SHOW`
registration in `StatementFactory`, so a statement absent from that
registration appears in neither `system.statements`, `system.documentation`,
nor the published page. Every other `SHOW` variant has a section there.

Use anchors that no existing section uses, so the generated page keeps the
links it already has.

Also point `system.engine_settings` at `system.table_settings` for the
settings of one table. It said to read `SHOW CREATE TABLE`, which was the
best answer available when that description was written and is now the wrong
one - the `CREATE` query is exactly what can disagree with the settings in
effect.

Related: ClickHouse#116543
Related: ClickHouse#59913

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
Three of the eight `source` values appeared only in the enum declaration of
the column, never as a row any test produced. `named_collection` is the one
of those three that is reachable without external services: a collection can
be created with DDL, and `Kafka` is the only engine that keeps the name of
the one it was built from.

The test asserts the three `other` rows alongside it, because they are the
finding rather than noise - `StorageKafka`'s constructor pins those format
settings itself, so attributing everything unstated to the collection would
have credited it with settings it never carried.

`shared_metadata` still has no test: producing it needs both S3 and Keeper.
`runtime` has no producer at all yet.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
Four things the surrounding code does that this did not.

`ASTShowTableSettingsQuery` supports the AST JSON dialect now, as 68 of the
79 query nodes do and as its closest sibling `ASTShowColumnsQuery` does.
Without it `parseQueryToJSON('SHOW TABLE SETTINGS ...')` threw while the same
call on `SHOW COLUMNS` succeeded. `readJSON` rejects the payloads the parser
could not have produced - an empty table, or a `NOT`/`ILIKE` flag with no
pattern - because the formatter silently drops the latter.

It also overrides `updateTreeHashImpl`. Every field is a member rather than a
child, so the inherited implementation, which hashes only `getID()`, gave the
same hash to every `SHOW TABLE SETTINGS` query. Nothing keys off that today -
the query result cache takes only `ASTSelectQuery` and
`ASTSelectWithUnionQuery` - which is exactly why whoever adds the first
consumer would not notice.

`enumerateSettings.h` is renamed to `enumerateSettingsFromImpl.h` after the
one function it holds, per the naming rule for a file containing a single
function. The function keeps its name: every settings struct already has a
member called `enumerateSettings`, and the two should not be confused.

`StorageSystemTableSettings::createVirtuals` becomes public, as it is in
`StorageSystemColumns`, `StorageSystemTables`, `StorageSystemProjections` and
`StorageSystemDataSkippingIndices`.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
The branch was 1643 commits behind, and `git merge-tree` reported a real
conflict: master's `TimeSeries: choose inner engine families by
default_table_engine` appended functions where `enumerateSettings` had been
appended here. Both are additive, so both are kept.

Adding an engine that accepts settings but wiring no enumeration for it
leaves it silently absent from `system.engine_settings` -
`getFilteredEngines` skips an engine with no function, so there is no error
to notice. Six engines are legitimately absent, all of which keep no settings
struct, so the invariant can simply be listed: a seventh name appearing in
that test means an engine was added without being wired.

Those 1643 commits added none, and no existing system table changed shape.

Related: ClickHouse#116543
Related: ClickHouse#59913

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
Staging `contrib` wholesale in the merge commit did two things it should not
have.

`contrib/spdlog` and `contrib/wasmedge` are untracked working directories on
this machine, in neither `.gitmodules` nor master, and they were committed as
embedded git repositories. Untracked again; the directories stay on disk.

`contrib/libdivide` and `contrib/libucontext` are real submodules that master
had advanced. The working tree still held the older checkout because
`git submodule update` had not run after the merge, so staging the directory
recorded the stale commits over the ones the merge had taken. Both are back
to master's.

The diff against master now contains no `contrib` entry at all.

Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
Master moved 1390 commits in two days and
`src/Storages/TimeSeries/TimeSeriesSettings.cpp` conflicted for the second
time in three: `Rework the TimeSeries schema versioning` and its predecessor
both append helper functions to the end of that file, which is where
`enumerateSettings` had been sitting - line 204 of 209.

Resolved by taking master's helpers, and by moving `enumerateSettings` up
beside `enumerateEngineSettings` and `hasBuiltin`, where it belongs anyway.
The three are the same kind of accessor, and grouping them keeps the end of
the file free for whatever is appended next.

Not repeated across the other nineteen settings files, though `enumerateSettings`
sits within ten lines of the end in all of them. `MergeTreeSettings.cpp` looked
like the pressing case at 53 master commits in thirty days, but none of them
touch its tail: settings are added to the `DECLARE` list in the middle, and the
file only grows there. `TimeSeries` is the one place master genuinely appends
functions.

Related: ClickHouse#116543
Related: ClickHouse#59913

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DGgpj9TmsDY7PSPWevjpUM
@CLAassistant

CLAassistant commented Sep 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3146502]

Summary: ⏳

job_name test_name status info comment
Docs check (Mintlify) FAIL
No direct edits to generated or read-only docs FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Sep 7, 2026
buggins and others added 16 commits September 28, 2026 07:42
…t for an alias

The documentation of the two tables and the statement left out rules the code
enforces:

- `system.engine_settings` did not say it needs a `SELECT` grant, as
  `system.merge_tree_settings` does.
- `system.table_settings` did not say an `Alias` table is shown only to a user
  who may see its target, nor that a macro expanded into a secret is never shown;
  `SHOW TABLE SETTINGS` did not say an alias with a hidden target is an error.
- `is_masked` named the grant and the query setting, but not the server setting
  `display_secrets_in_show_and_select`, which is needed too.
- The shared `source` description said a named collection's value is hidden,
  which is `system.table_settings`'s rule and never applies to the engine rows of
  the other tables; it now says where.

The four pages are regenerated from these strings.

And the refusal of `SHOW TABLE SETTINGS` for such an alias now reads as the other
access errors do - the user, and the grant it lacks - without naming the target,
which `SHOW TABLES` on the alias alone does not reveal.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Drop includes nothing in their files uses, the declarations of the four
`distributed_background_insert_*` settings `StorageDistributed` no longer
reads, and the `query_context` parameter `StorageKafkaUtils::getTableSettings`
never read. `getEngineStatedInDefinition` has no caller outside
`TableSettingsHelpers.cpp`, so it moves into an anonymous namespace there.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Enumeration and `describeSettingsStatedInDefinition` each wrote their own
loop asking `maskEngineSettingValue` under a setting's name and aliases, and
`setEffectiveValue` asked under the declared name only, so a secret whose
masking rule is registered under an alias would have shown through the
effective value of `Kafka`, `NATS` or `RabbitMQ`. One overload taking the
`SettingDescription` now asks under every name, and all three use it.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Say each rationale once, where the mechanism lives - secrecy of server
secrets and named collections in `SettingRowWriter::masks`, the lifetime of
the views in `SettingDescription`, origin recording in `BaseSettings` - and
drop the restatements elsewhere. The comment on `IStorage::getTableSettings`
also no longer says the base reports nothing for a view: a materialized
view's own `ENGINE` can state settings, and the base reads them.

Also drop the double blank lines the change introduced.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Drop the per-engine restatement that the settings object records the
definition and a named collection - `BaseSettings` says that once - and the
comments narrating how the code used to behave. `StorageObjectStorage`
enumerates its configuration's settings only for a data lake, the one case
that reports them.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- `setOriginByValue` becomes `withOriginByValue`, returning the settings as
  `withOriginFromDefinition` does, and `Join` and the `Log` family use it
  instead of their own copies of the rule.
- `setEffectiveValueWithConfigFallback` reads the stated value from the
  settings object itself, so a call names the setting once.
- `MergeTreeSettings::enumerateSettingsWithConstraints` replaces the
  enumerate-then-`applyConstraints` pair that `MergeTreeData` and the engine
  enumeration each wrote.
- `system.table_settings` asks whether a filter reads a column through one
  lambda, and `SHOW TABLE SETTINGS` builds its `WHERE` clause once.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Say once what two neighbours both said - the secrets gate of the two engine
settings tables, the named collection override of `MySQLSettings` and
`PostgreSQLSettings`, why the replicated `MergeTree` family enumerates its own
settings - merge the two stacked comments on the `Alias` refusal of
`SHOW TABLE SETTINGS`, and write functions as `f` rather than `f()`.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`05055` and `05056` compared `system.engine_settings` and
`system.table_settings` with `system.merge_tree_settings` in one direction,
under the default configuration, and nothing compared them with
`system.replicated_merge_tree_settings` or `system.s3_queue_settings`.

- `05267`: every `MergeTree` family engine in `system.engine_settings` has
  exactly the rows of `system.merge_tree_settings`, or of
  `system.replicated_merge_tree_settings` for a replicated one, in every
  shared column, both ways.
- `05268`: the same under `<merge_tree>` and `<replicated_merge_tree>`
  sections that set one setting differently, and with `compatibility`.
- `05269`: `system.table_settings` agrees with `system.s3_queue_settings` on a
  queue table in names, types, descriptions and values compared as values,
  and the reference lists the two known differences, so a new one fails.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…settings-59913-116543

# Conflicts:
#	src/Storages/TimeSeries/TimeSeriesSettings.cpp
The `IStorage` base reads the stored definition through
`describeSettingsStatedInDefinition`, not `withOriginFromDefinition`, and
`Distributed` and the `Log` family also recompute origins with
`withOriginByValue`.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`StorageNATS::getTableSettings` told a URL or server list a macro supplied
by expanding the stated value with the server's current macros. A macro
removed from the config since the table was built made that throw: the
table's rows disappeared from `system.table_settings`, `SHOW TABLE SETTINGS`
answered with nothing, and the logged message quoted the stated URL,
credentials included, to any reader who asked for the server's logs with
`send_logs_level`. It now compares the stated values with the ones the
constructor built from the same expansion, as `RabbitMQ` already does.

The comment of `SHOW TABLE SETTINGS` now says that only the lookup of the
table is an error; settings that cannot be read are skipped, rather than
raised with a message that may quote a secret.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A table that states no authentication of its own takes it from the server's
`nats` or `rabbitmq` config section. Its password was always `[HIDDEN]`, but
the username, and the `rabbitmq` `vhost`, were shown to any reader of the
table's settings, though no other SQL surface shows them and
`SHOW CREATE TABLE` never contained them. A value an engine takes from its
server config section is now the server's, secret or not, and never shown.
The `<merge_tree>` and `<distributed>` sections are unaffected: their values
are the server's baseline, which `system.merge_tree_settings` already shows.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`ExecutablePool` assigns `max_command_execution_time` itself when its
definition does not state it, which marks the setting changed, so a table
stating nothing reported it with source `other` and `SHOW CHANGED TABLE
SETTINGS` listed it. The value now decides, as for what `Distributed` copies
from the server.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tion

The `ENGINE ... SETTINGS` of a materialized view belong to its inner table,
which reports them, and the view's own definition states none, so the base
implementation parsed each view's stored definition to find nothing. The
comment there also claimed the opposite since 4447d81.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…serve

`05264` counted the rows of an `Alias` table whose target the reader may not
see, but an alias states no settings and has no rows for any reader, so the
count passed with or without the check it meant to cover; the statement's
refusal is what the test pins. `05257` counted rows over every database,
which made it fail when another test left an unreachable external database;
it now counts under the two names the table could be reported under.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`system.engine_settings` described `ExecutablePool` by the compiled
defaults, so it said 10 for `max_command_execution_time` while a table
created on a server whose `max_execution_time` is lower takes that instead.
The engine now registers its own enumeration, which fills the value in as
the creator does, through the one function both use, and judges its source
by value as the table rows are.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@buggins

buggins commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Hello @nikitamikhaylov

I would like to provide a status update for this PR.

As you can see, PR diff has already diff of 2.5k lines of code (+0.5k comments + 0.5k blanks).
I expected to have x2 or x3 code size grow comparing to the source engine_settings PR #113269 we borrowed.
But actually now its code lines diff is about x9 times bigger.
It's not just a useless bloat, it's related to functionality not covered by original PR.

  • access checks (mandatory)
  • secret masking (mandatory)
  • filter pushdown database/table/engine (optional, but actually useful for big prod server, and removing it would not reduce the code size a lot).
  • column bitmap to copy data only for selected columns (minor optimization, but diff is only a few lines of code).
  • source(origin) tracking for the setting value (a big diff, but actually gives a lot of value for this feature)

Integration of settings enumeration for engine and table levels requires touching every engine setting struct and every storage engine .h and .cpp
but in most cases only a few lines of code have to be changed: 65% (102 of 156) source files have only 10 or less lines of code diff.

After a bunch of the recent commits, this PR is getting close to point when it becomes human readable and can pass automatic review from AI bot, and even become all-green once pr-autogenerated-docs label is added.

I'm doing manual code review of the changes and asking to fix my findings, and run AI /review periodically which often finds something to be fixed.
I don't expect global changes based on further investigation, only small refactoring and engine-specific edge case fixes.

A short overview of the feature implementation architecture.

Instead of direct filling of column data in setting enumeration code, I've introduced intermediate container:

  • struct SettingDescription with setting fields and a few helper fields for secure value masking and named collection tracking.
  • all setting enumerations return SettingDescriptions which is a std::vector
  • engine-level and table-level system tables implementation write column data from SettingDescription
    This contract simplifies interfacing between setting enumeration and system table columns writing code, allowing custom processing for both producer and consumer sides.

Interface between system tables implementation and storage engines:

  • Each storage engine which wants to publish its settings in system.engine_settings must provide StorageFeatures::enumerate_engine_settings_fn on registration.
  • Each storage engine which wants to publish its table-level settings in system.table_settings must overload IStorage::getTableSettings

Both system.engine_settings and system.table_settings are implemented in the same style as other similar system tables.
They include access checks, secret values masking, and filter pushdown.
Note: column metadata for common columns (including description) is shared between engine-level (engine_settings, merge_tree_settings, replicated_merge_tree_settings)
and table level (table_settings).

For many engines, engine-level settings may be collected from its default-created settings struct, and table-level settings - read from a settings struct instance it holds.
In this case integration is simple - one line changes in settings struct .h and .cpp, engine registration, and engine .h and .cpp
(there are helper functions, template functions, and macros to simplify it).

For tracking of setting value origin inside setting struct, structure is being declared with a new trait record_origin=true
This option extends struct with SettingOrigin array (4 bits per setting) and named_collection name string.
A few new BaseSetting methods add setters-with-origin and getters/setters of origin for setting fields.

For cases if storage engine does not store settings in its own settings struct (e.g. just uses table definition)
there are helper functions which may expose table metadata settings and/or named_collection entries.

Some engines like S3/AzureQueue, Kafka, NATS, RabbitMQ, Join, Set, Distributed, Object storages
and some others have custom ways of storing, updating, applying of their settings.
In this case, they have to implement custom enumeration for engine-level and/or table-level settings.

Some points to highlight.

  1. The PR label pr-autogenerated-docs will be required to pass the docs check.

  2. Nikita, you wrote a comment:

On a separate note, why do we need system.table_settings? Maybe we can just put everything inside system.tables?

It's easy to move system.table_settings to system.tables column or even make visible in both places.
But it would not change code size a lot.
Current implementation as a separate system table is similar to system.columns, system.constraints, systemc.projections...

  1. Under this PR, support of storage engine settings aliases is implemented, as additional rows alias_for column referring main setting.
    At first sight, it's useful feature - allows to see setting properties under old names (currently only 5 aliases: allow_experimental_block_number_column, monitor_batch_inserts, etc...)
    But I'm not sure it is really needed.
    Aliases are not only mixed in to engine_settings and table settings, but now as well visible in merge_tree_settings/replicated_merge_tree_settings as well (incompatible change).
    Actually, it's a small feature and removing of aliases will not reduce diff a lot, but will revert a few doc autogeneratoin files, and a other files. Just wanted to ask your opinion.
    Another option, hide aliases in merge_tree_settings.
    (described in PR description decision section under items 1, 2)

  2. Columns metadata is shared between engine-level system tables and table_settings. Is it ok for them to have the same description?
    Descriptions for some of columns were changed, and became longer. Makes sense to review. As other docs.

  3. Decision items 4, 5, 6 from PR description to be reviewed.

  4. This PR is marked as "Backward Incompatible Change" because there are new columns inserted in the middle of merge_tree_settings rows.
    Incompatibility could be reduced by appending them to the end, but IMHO it's inconvenient to place narrow columns after wide description column.
    Is it ok to place new columns in the middle?

  5. Since named_collection name is already saved for access control purpose, there is a possibility to add one more setting column, named_collection_name to display it - almost for free.

  6. If PR size is too big to be accepted, we may consider splitting into several parts, e.g.:

  • engine_settings code and common code shared between engine and table levels: ~1K lines
  • table_settings part
  • SHOW TABLE SETTINGS implementation (about 10% of code in this PR): ~10% of source lines

buggins and others added 7 commits September 28, 2026 22:03
…it names

`Merge` passes its table name pattern to the database's table iterator and
does not check it again, so it relies on the iterator to apply it.
`DatabasePostgreSQL::getTablesIterator` ignored that filter, so a `Merge`
table over a `PostgreSQL` database read every table in it, whatever its
pattern. This pull request made the iterator apply the filter, for
`system.table_settings`; the test pins what that changes for `Merge`.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The `nats` section also supplies a table's token and credential file, and
the `rabbitmq` section's `vhost` replaces the table's own rather than only
filling in an absent one. A value a named collection supplied is masked
whatever the secrets settings, unless the reader may read that collection.
And a materialized view reports no settings: its `ENGINE ... SETTINGS` belong
to its inner table.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`SettingOrigin` claimed its values were declared in the order engines apply
them, but `MergeTree` applies `compatibility` before its config section. And
`setEffectiveValue` claimed every `Config` value is hidden, which holds only
for an engine's own section such as `nats` or `rabbitmq`: the `<merge_tree>`
and `<distributed>` baselines are recorded by the settings object and shown.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rity tests

`05267` and `05268` compare every engine whose name ends in `MergeTree` with
`system.merge_tree_settings` or `system.replicated_merge_tree_settings`, but
nothing says which of the two the `Shared` engines of a private build match.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…fault

`background_insert_sleep_time_ms` and `background_insert_max_sleep_time_ms`
default to `0`, meaning "the server's setting", which a table creator fills
in. Judged against that `0`, every `Distributed` table, untouched or not,
reported both as changed with source `other`. They are now measured against
the default of the server setting they take, in `system.table_settings` and
`system.engine_settings` alike: an untouched table reports `default`, and one
on a server whose setting differs reports `other`.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…settings-59913-116543

# Conflicts:
#	src/Storages/IStorage.h
… its `try`

A failed `CREATE TABLE` or `INSERT` before the `try` would have left the
tables behind for `test_postgresql_fetch_tables`, which asserts the exact list
of tables in the public schema.

Related: ClickHouse#59913
Related: ClickHouse#116543

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-feature Pull request with new product feature labels Sep 29, 2026
@nikitamikhaylov

Copy link
Copy Markdown
Member

I’ve spent quite a bit of time reviewing the diff, and I don’t think it meets our quality standards. Its size and complexity make it difficult to follow, even as a maintainer, and I don’t see evidence of a thorough manual review + I don't think we need this many tests given that we don’t currently have comparable coverage right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-system-table system.* tables (introspection, system metadata, performance visibility). manual approve Manual approve required to run CI pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SHOW TABLE SETTINGS Implement system.engine_settings

4 participants