Repository navigation
Exempt metadata statements from workload scheduling - #118419
Conversation
…kload DDL queries (CREATE, ALTER, DROP, RENAME, OPTIMIZE, TRUNCATE, MOVE) currently share the workload setting with regular queries, so administrative statements compete with runtime queries for the same query-slot and memory-reservation limits. This adds a ddl_workload query setting used in place of workload for DDL queries, gated by the use_ddl_workload server setting (default off) as a transition switch for this backward-incompatible change. When enabled, the effective workload of a DDL query is overridden right after its SETTINGS are applied and before the workload classifier is first acquired, so query-slot admission, memory reservation, and CPU/IO scheduling all follow ddl_workload through the single cached classifier. When ddl_workload is unset it defaults to the default workload, isolating DDL from whatever workload regular queries use.
|
Workflow [PR], commit [41be802] Summary: ✅
AI ReviewSummaryReviewed #118419 at Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units1378 translation units recompiled, 9160 s compile time in total, 1378 of them have a recent master baseline. |
A single count(*) query finishes before the test can poll its query slot, so the previous assertions saw inflight=0 and failed (both the DDL and the plain workload case). Keep queries continuously in flight with a small pool and wait until the workload's inflight count reaches the target, mirroring tests/integration/test_scheduler_query.
…bled Aligned semantics for the DDL workload feature: - use_ddl_workload off (default): DDL and administrative queries (schema DDL plus access control and SYSTEM) are exempt from workload query-slot and memory-reservation admission, so they never queue behind regular queries. - use_ddl_workload on: they are admitted under the ddl_workload workload instead of the workload setting (default "default"). Implementation: - Classify DDL by query kind in a shared isDDLQuery() (ProcessList), used by both the admission exemption in ProcessList::insert and the workload override in executeQuery. Scope: Create/Drop/Undrop/Rename/Alter/Optimize/Move, Grant/Revoke, System. - Apply the enabled-path override through checkSettingsConstraints/applySettingChange instead of a raw setSetting, so a profile that pins or constrains workload is still honored for DDL. - Extend the integration test to cover both the exempt-by-default and the ddl_workload-when-enabled modes.
Folding gate-off DDL into is_unlimited_query also skipped the hard server limits guarded by the same flag (max_concurrent_queries, max_concurrent_queries_for_all_users, max_concurrent_queries_for_user, and the per-kind insert/select caps), so a heavy DDL could enter past the server's hard concurrency limit and crowd out regular traffic. Narrow the exemption: a dedicated skip_workload_admission flag skips only the workload query-slot and memory-reservation block. DDL still counts against the server-wide max_concurrent_queries* limits, as intended.
…eload use_ddl_workload is hot-reloadable and was read in two places (the workload override in executeQuery and the admission-skip in ProcessList::insert); a config reload between the two reads could mix modes for a single query. Read it once at the insert site and pass the resulting skip decision to ProcessList::insert as a parameter, so the override and the admission-skip are always derived from the same value.
ddl_workload is an independent setting with its own constraints (via user profile); it is intentionally not subject to the constraints on workload. Route DDL under ddl_workload with a plain override instead of the constraints-checking path, and document the intended behavior in the setting description.
# Conflicts: # src/Core/SettingsChangesHistory.cpp
…o ddl-workload # Conflicts: # src/Core/SettingsChangesHistory.cpp
…rkload # Conflicts: # src/Core/SettingsChangesHistory.cpp
… the ddl_workload contract The ddl_workload / use_ddl_workload descriptions implied DDL is uniformly exempt (when disabled) or admitted under ddl_workload (when enabled). DDL wrapped by EXECUTE AS or PARALLEL WITH runs as an internal query and is exempt from workload admission regardless of the setting; document that exception so the descriptions do not over-promise.
…bservable The regular/ddlwl workloads had no per-workload limit, so no semaphore node exists at their path and system.scheduler inflight_requests for them is always 0 (the query slot is counted at the ancestor 'all'). Add max_concurrent_queries to each so the slot registers at their own semaphore and the test can observe it, matching test_scheduler_query.
…kHouse/ClickHouse into ddl-workload # Conflicts: # src/Core/SettingsChangesHistory.cpp
…o ddl-workload # Conflicts: # src/Core/Settings.cpp # src/Core/SettingsChangesHistory.cpp
…_workload setting in 26.9 Co-Authored-By: Claude Opus 4.8 <[email protected]>
It only clears a cache, like the other `CLEAR ... CACHE` commands. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai, This is unrelated to this PR (none of its commits touch |
|
The fix is my #127906 (open). It is the same stack: the stress job runs stateless tests through the embedded web terminal, |
…ata statement Co-Authored-By: Claude Opus 5.5 <[email protected]>
azat
left a comment
There was a problem hiding this comment.
I have some concerns about complexity around detecting which query is considered metadata query
| - [Workload Scheduling](/concepts/features/configuration/server-config/workload-scheduling) | ||
| )", 0) \ | ||
| DECLARE(Bool, use_metadata_workload, false, R"( | ||
| Controls how metadata statements participate in workload scheduling. When disabled (default), they are exempt from workload scheduling — query-slot and memory-reservation admission, CPU and IO — while still being subject to the server-wide `max_concurrent_queries`, `max_concurrent_queries_for_all_users` and `max_concurrent_queries_for_user` limits. When enabled, they are scheduled under the workload named by the `metadata_workload` query setting instead of `workload`. Metadata statements change only metadata and do not read or write table data: DROP, DETACH, TRUNCATE, RENAME, GRANT, REVOKE, MOVE of access entities, CREATE and ALTER of objects other than tables (workloads, resources, access entities, functions, named collections, ...), CREATE of tables (not dictionaries, tables with the `Dictionary` engine, `AS` another table, or replicating engines such as `MaterializedPostgreSQL`, which may load data from their source) without a `SELECT` (a `SELECT`, also of a view, is analyzed and may read its sources) and without data (not `CLONE AS`, `FROM` a path, `AS` a table function, or an engine without the columns, which reads its source to infer the structure), ALTER without commands that copy parts or run synchronously (MOVE, REPLACE, FETCH, FREEZE and ATTACH PARTITION or PART, EXECUTE, MODIFY QUERY), and SYSTEM, except commands that read or send table data (PREWARM MARK CACHE, PREWARM PRIMARY INDEX CACHE, LOAD PRIMARY KEY, FLUSH DISTRIBUTED, RELOAD DICTIONARY, RELOAD DICTIONARIES, RELOAD EMBEDDED DICTIONARIES, RESTART REPLICA, RESTART REPLICAS, RESTORE REPLICA, RESTART DISK, INSTRUMENT REMOVE, and ALLOCATE MEMORY, which allocates memory). ATTACH and UNDROP, which load the existing data of a table or database (e.g. parts, or the saved rows of `Join` and `Set`), are scheduled under `workload`. A statement with a subquery, a SQL user-defined function or a function that reads data (a dictionary function, `file`, `joinGet`) anywhere (e.g. in an engine argument) is scheduled under `workload`, because it may read data while the statement is analyzed. Deleting data counts as a metadata change, and so does flushing the in-memory rows of a `Buffer` table when it is altered, dropped or detached. Mutations (ALTER ... UPDATE, DELETE, MATERIALIZE ..., APPLY ..., REWRITE PARTS) are scheduled under `workload`, because some engines (e.g. `Memory`) run them in the query. Other statements, such as CREATE ... AS SELECT, OPTIMIZE, BACKUP, RESTORE and CHECK TABLE, are scheduled under `workload` like regular queries. A metadata statement wrapped by another statement (e.g. `EXECUTE AS <user> <stmt>` or `X PARALLEL WITH Y`) runs as an internal query: it skips query-slot and memory-reservation admission regardless of this setting, and its CPU and IO are scheduled under the `workload` of the wrapping statement. |
| DECLARE(String, metadata_workload, "default", R"( | ||
| Name of the workload used to schedule metadata statements when the server setting `use_metadata_workload` is enabled. Such statements are then scheduled under this workload instead of the `workload` setting for every resource (query-slot and memory-reservation admission, CPU and IO). Defaults to the `default` workload. Has no effect when `use_metadata_workload` is disabled: then metadata statements are exempt from workload scheduling, though still subject to the server-wide `max_concurrent_queries*` limits. | ||
|
|
||
| Metadata statements change only metadata and do not read or write table data: DROP, DETACH, TRUNCATE, RENAME, GRANT, REVOKE, MOVE of access entities, CREATE and ALTER of objects other than tables (workloads, resources, access entities, functions, named collections, ...), CREATE of tables (not dictionaries, tables with the `Dictionary` engine, `AS` another table, or replicating engines such as `MaterializedPostgreSQL`, which may load data from their source) without a `SELECT` (a `SELECT`, also of a view, is analyzed and may read its sources) and without data (not `CLONE AS`, `FROM` a path, `AS` a table function, or an engine without the columns, which reads its source to infer the structure), ALTER without commands that copy parts or run synchronously (MOVE, REPLACE, FETCH, FREEZE and ATTACH PARTITION or PART, EXECUTE, MODIFY QUERY), and SYSTEM, except commands that read or send table data (PREWARM MARK CACHE, PREWARM PRIMARY INDEX CACHE, LOAD PRIMARY KEY, FLUSH DISTRIBUTED, RELOAD DICTIONARY, RELOAD DICTIONARIES, RELOAD EMBEDDED DICTIONARIES, RESTART REPLICA, RESTART REPLICAS, RESTORE REPLICA, RESTART DISK, INSTRUMENT REMOVE, and ALLOCATE MEMORY, which allocates memory). ATTACH and UNDROP, which load the existing data of a table or database (e.g. parts, or the saved rows of `Join` and `Set`), are scheduled under `workload`. A statement with a subquery, a SQL user-defined function or a function that reads data (a dictionary function, `file`, `joinGet`) anywhere (e.g. in an engine argument) is scheduled under `workload`, because it may read data while the statement is analyzed. Deleting data counts as a metadata change, and so does flushing the in-memory rows of a `Buffer` table when it is altered, dropped or detached. Mutations (ALTER ... UPDATE, DELETE, MATERIALIZE ..., APPLY ..., REWRITE PARTS) are scheduled under `workload`, because some engines (e.g. `Memory`) run them in the query. Other statements, such as CREATE ... AS SELECT, OPTIMIZE, BACKUP, RESTORE and CHECK TABLE, are scheduled under `workload` like regular queries. |
|
|
||
| bool isMetadataQuery(const IAST * ast) | ||
| { | ||
| if (!ast || hasSubquery(*ast)) |
There was a problem hiding this comment.
Is it possible to pass ast=nullptr?
| case ASTSystemQuery::Type::REFRESH: | ||
| return true; | ||
| /// Read or send table data on the thread group of the query, or allocate memory. | ||
| case ASTSystemQuery::Type::ALLOCATE_MEMORY: |
There was a problem hiding this comment.
It allocates memory bypassing query pipeline, do we really need it here?
Also, do we really want to keep this complex interface, why not just count all "SYSTEM" as "metadata"?
|
|
||
| /// ALTER commands that change only metadata or delete data. A mutation only enqueues its work, which | ||
| /// runs under `mutation_workload`. A new command has to be classified here. | ||
| static bool isMetadataAlterCommand(const ASTAlterCommand & command) |
There was a problem hiding this comment.
Same here, do we really want to keep this complexity instead of just considering any ALTER as "metadata"?
Because even for i.e. ALTER REWRITE PARTS, it will not be done from the query context anyway (at least for RMT/SMT)
| bool populates = create->attach || create->is_dictionary || !create->as_table.empty() | ||
| || (create->storage && create->storage->engine | ||
| && (create->storage->engine->name == "Dictionary" || create->storage->engine->name.starts_with("Materialized"))); | ||
| return !has_select && !reads_table_function && !infers_structure && !populates && !create->is_populate && !create->is_clone_as |
There was a problem hiding this comment.
Maybe just checking for SELECT/table function will be enough?
| } | ||
| else | ||
| { | ||
| /// Exempt from workload scheduling. `workload` is left as is, so the `max_concurrent_queries*` |
There was a problem hiding this comment.
I guess comment for ExemptClassifier is enough
| static const ClassifierPtr exempt_classifier = std::make_shared<ExemptClassifier>(); | ||
| classifier = exempt_classifier; |
There was a problem hiding this comment.
| static const ClassifierPtr exempt_classifier = std::make_shared<ExemptClassifier>(); | |
| classifier = exempt_classifier; | |
| static const ClassifierPtr metadata_exempt_classifier = std::make_shared<ExemptClassifier>(); | |
| classifier = metadata_exempt_classifier; |
# Conflicts: # src/Interpreters/ProcessList.cpp
|
Let me simplify this a lot. I feel like dropping settings and just keeping metadata-related queries out of workload scheduling is the right thing - simple and straightforward. There will be no way to eliminate DDL queries, but it doesn't seem to be a big issue at the moment. We can add it later if necessary. I was trying to make every query that is possibly reading any data use workload scheduling. Bots found 20 exotic ways to use a metadata statement to read data. That's where this classification complexity came from. I think you are right, and I will just drop it all for simplicity. We can address it on a case-by-case basis if necessary. |
…ettings Removes `metadata_workload` and `use_metadata_workload`: a metadata statement is always exempt. Statements are classified by kind: DROP / DETACH / TRUNCATE, UNDROP, RENAME, access control, SYSTEM, CREATE without a `SELECT` or a table function, and ALTER without commands that copy parts (`MOVE`, `REPLACE`, `FETCH`, `ATTACH`, `FREEZE` partition, `EXECUTE`). Everything else stays under `workload`. With nothing to reload, the mode no longer has to be fixed at query start, and the classifier needs no workload name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai, This failure also appears on unrelated PR #111166 (Add |
|
This is the same abort as on #111166 (same frames: |
|
|
||
| bool isMetadataQuery(const IAST * ast) | ||
| { | ||
| if (!ast) |
There was a problem hiding this comment.
Is it possible not to have IAST here? Maybe accept const IAST & instead?
There was a problem hiding this comment.
Done in 41be802: isMetadataQuery(const IAST & ast). The caller checks out_ast before calling it.
| /// Copy parts in the query. | ||
| case ASTAlterCommand::MOVE_PARTITION: | ||
| case ASTAlterCommand::REPLACE_PARTITION: /// Also ATTACH PARTITION ... FROM | ||
| case ASTAlterCommand::FETCH_PARTITION: | ||
| case ASTAlterCommand::ATTACH_PARTITION: | ||
| case ASTAlterCommand::FREEZE_PARTITION: | ||
| case ASTAlterCommand::FREEZE_ALL: | ||
| case ASTAlterCommand::EXECUTE_COMMAND: | ||
| return false; |
There was a problem hiding this comment.
I am still not sure about this
Since we are limited in what we can "schedule" here (no pipeline)
Plus use the same queue for regular queries and ALTER PARTITION can be wrong
But probably not a big deal
There was a problem hiding this comment.
It's not only about the pipeline. We have IO scheduling which is unrelated to pipelines, so it make some sense. Also, a query slot is something unrelated that triggered this whole PR initially.
There was a problem hiding this comment.
Agreed, it's imperfect. These commands copy whole partitions on the caller's thread group, though, and nothing else schedules them. Exempting them would make the heaviest form of ALTER completely unscheduled, which seems worse than sharing workload with regular queries. Everything else in ALTER (mutations included) is metadata. A separate queue for partition operations could come later.
…_scheduler_query The test needs a single node with SQL-defined resources only, so it reuses the existing scheduler test cluster instead of starting another one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Statements that change only metadata, such as
DROP,DETACH,TRUNCATE,RENAME,GRANT,REVOKE,SYSTEM,CREATE TABLEwith columns, andALTERthat changes the schema, are now exempt from workload scheduling (query-slot and memory-reservation admission, CPU and IO), so they do not queue behind regular queries. The server-widemax_concurrent_queries*limits still apply. Previously they were scheduled under theworkloadsetting like any other query.Metadata statements share the
workloadsetting with regular queries, so under load they queue for query slots, memory reservations, CPU and IO behind data-heavy traffic. This PR exempts them.executeQuerymarks a metadata statement on its context (isMetadataQuery), andContext::getWorkloadClassifierthen returns a classifier that maps every resource to an emptyResourceLink. The mark is copied to child contexts, so the sub-queries the statement runs are exempt too.workloaditself is not changed, so the server-widemax_concurrent_queries*limits still apply, and sub-queries sent to other servers are scheduled there underworkload.isMetadataQuerydecides by the kind of statement:DROP/DETACH/TRUNCATE,UNDROP,RENAME,GRANT,REVOKE,MOVEof access entities,SYSTEM,CREATE/ATTACHwithout aSELECTor a table function, andALTERwithout commands that copy parts in the query (MOVE,REPLACE,FETCH,ATTACH,FREEZEpartition,EXECUTE);CREATE ... AS SELECT, views,OPTIMIZE,BACKUP,RESTORE, stays underworkload.The classification is best effort: a metadata statement can still do data work that its text does not show (e.g. a target engine that loads or flushes data, or a stored expression with a subquery). A metadata statement wrapped by
EXECUTE ASorPARALLEL WITHruns as an internal query; its CPU and IO follow the wrapping statement'sworkload.Workflow [PR]
Sync PR [sync-upstream/pr/118419]
Version info
26.11.1.2005-master(included in26.11and later)