Repository navigation
Check allow_statistics only when validating a mutation, not when running it - #117351
Conversation
…nning it `ALTER TABLE ... MATERIALIZE STATISTICS` (and `DROP STATISTICS`) was validated with the submitting session's `allow_statistics` and then checked again during execution, where the background context reads the server-default profile rather than that session. With a profile that disables statistics and the same session-level opt-in `ADD STATISTICS` honours, the statement was accepted and then failed forever: `mutations_sync = 1` returned `UNFINISHED`, and without it the mutation sat in `system.mutations` retrying and wedging the table's mutation queue until a manual `KILL MUTATION`. The setting gates the DDL - whether statistics may be declared on a table - so only the submitting session's value is meaningful, and the check belongs to validation alone. Background merges materialize the declared statistics regardless of the setting, so refusing the explicit verb at execution time protected nothing. Closes: #115448
|
Workflow [PR], commit [1709bb8] Summary: ✅
AI ReviewSummaryThis PR moves the Findings
Final VerdictStatus: Minimum required actions:
LLVM Coverage ReportMeasured on commit 1709bb8.
Changed lines: Changed C/C++ lines covered: 14/15 (93.33%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 31 s compile time in total, 8 of them have a recent master baseline. |
…tistics-session-gate
…tions Address the review finding on the previous commit: moving the `MATERIALIZE STATISTICS` gate into the `dry_run` pass of `MutationsInterpreter::prepare` left it bypassable, because `MATERIALIZE STATISTICS` parses into a `MutationCommands` segment only and the dry-run `MutationsInterpreter` is the sole pass over those - it is skipped entirely when the user sets `validate_mutation_query = 0`. Apply the gate exactly once instead, unconditionally at submission time in `InterpreterAlterQuery`, next to the other always-on mutation validation, and drop both execution-time checks from `MutationsInterpreter`. `ADD/DROP/MODIFY STATISTICS` keep their own always-on gate in `AlterCommands::validate`. The `validate_mutation_query = 0` bypass turned out to exist on master too: with `allow_statistics = 0` in the server profile, `ALTER TABLE ... MATERIALIZE STATISTICS a SETTINGS validate_mutation_query = 0` is accepted and runs, so this closes a real hole rather than one the previous commit introduced. Tests: the stateless test is renumbered to `05175` after the master merge (`05085` is taken) and extended with the `validate_mutation_query = 0` case. The half of the reproducer that needs a server profile - which a stateless test cannot set - moves to a new integration test `test_statistics_mutation_session_gate`; both of its cases fail on master and pass with this change, verified locally. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…tistics-session-gate # Conflicts: # src/Interpreters/InterpreterAlterQuery.cpp
…e the anonymous namespace Fixes the `readability-static-definition-in-anonymous-namespace` clang-tidy error that failed `Build (arm_tidy)`: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117351&sha=52aadbd9fa57776566945813040202829c18cd11&name_0=PR&name_1=Build%20%28arm_tidy%29 PR: #117351 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…tistics-session-gate Conflicts with the removal of `validate_mutation_query` on master: keep `checkStatisticsMutationsAreAllowed` and master's always-on validation, and reword the helper's comment, which referred to the now obsolete setting.
… tests The setting is obsolete on master and has no effect, so the cases only repeated the ones above them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117351&sha=a09e8993e66fe4f3f9dd983aa69011ea10dda299&name_0=PR&name_1=AST%20fuzzer%20(amd_debug) ( Also merged master (conflicts with the removal of |
|
Fix in progress: #110020 ("Decide parallel replicas eligibility with the subquery's own context"), open since 2026-07-10 and tracked by #113292 as you say. It is not merged, so it is not on One refinement to the diagnosis: the
#110020 tracks the enclosing (sub)query context down both traversals, including the UNION and Since this is the eighth time I have been asked about this STID, the useful part is probably that the diagnosis is not what is holding it up. #110020 is mergeable and conflict free today, its last full CI run was clean (0 failures across 271,754 rows), and no human review has been submitted on it in the 75 days it has been open; I requested devcrafter and KochetovNicolai on 2026-09-21 and have had no reply yet. The fuzzer is seeding from my own |
|
🕵 Thanks @groeneai for the refined diagnosis and the link to #110020. The Merged master again (no conflicts; the two touched translation units build). The only red check on the previous head was |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117351&sha=bdf713b45ce501234960cc83cd6c26388cb2d2d2&name_0=PR ( |
|
Investigated. This PR does not cause it: the whole It is the arm slow mode that came with the PIE release build (#117449, re-landed in #119284). Master-vs-master arm runs with the whole test more than 10% slower on one side: 1 of 1049 before #117449, 0 of 38 in its first day, 1 of 213 while it was reverted, 52 of 782 since #119284 (27 on the candidate side, 25 on the reference); amd 1 of 2082. It follows the run, not the build: a master build that was slow in one run is slow in its other runs at the base rate (4.8% vs 4.9%). Here the slow side stayed slow through both confirmation restarts ( No fixing PR exists yet, because the fix is your call, which I asked in #122447 (comment): (A) build |
|
🕵 Thanks @groeneai for the analysis. On the new head ( |
|
Fixing PR for the datetime_comparison arm_release perf red: #125278 |
|
📊 Cloud Performance Report ✅ AI verdict: This PR moves the allow_statistics check for MATERIALIZE/DROP STATISTICS mutations out of MutationsInterpreter and into submission-time validation in InterpreterAlterQuery. Plain SELECT queries never run that code. ClickBench Q30 (+21.1%) and Q31 (+20.6%) are both GROUP BY aggregations and both show the same wall-clock rise with flat CPU time, which points to a slower or busier run rather than extra work from this PR. Q31 is downgraded from regression to not sure. Q30 stays not sure because its delta falls inside master's normal range, and that call agrees with the diff. No performance impact is attributed to this change. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Cherry pick #117351 to 26.7: Check `allow_statistics` only when validating a mutation, not when running it
…ng a mutation, not when running it
Cherry pick #117351 to 26.8: Check `allow_statistics` only when validating a mutation, not when running it
…ng a mutation, not when running it
Cherry pick #117351 to 26.9: Check `allow_statistics` only when validating a mutation, not when running it
…ng a mutation, not when running it
Backport #117351 to 26.8: Check `allow_statistics` only when validating a mutation, not when running it
Backport #117351 to 26.9: Check `allow_statistics` only when validating a mutation, not when running it
Backport #117351 to 26.7: Check `allow_statistics` only when validating a mutation, not when running it
| auto share_lock = table->lockForShare(context->getCurrentQueryId(), settings[Setting::lock_acquire_timeout]); | ||
| auto metadata_snapshot = table->getInMemoryMetadataPtr(context, true); | ||
| table->checkMutationIsPossible(*mutation_commands, settings); | ||
| checkStatisticsMutationsAreAllowed(*mutation_commands, settings); |
There was a problem hiding this comment.
A highly specific check in a generic handler. Should that not be in checkMutationIsPossible?
| { | ||
| if (!context->getSettingsRef()[Setting::allow_statistics]) | ||
| throw Exception(ErrorCodes::INCORRECT_QUERY, "Alter table with statistics is disabled. Turn on allow_statistics"); | ||
| /// `allow_statistics` gates the DDL: whether statistics may be declared on a table. Only |
There was a problem hiding this comment.
A long comment about deleted code.
Closes: #115448
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
ALTER TABLE ... MATERIALIZE STATISTICS/DROP STATISTICSfailing forever and wedging thetable's mutation queue when a server profile sets
allow_statistics = 0and the statement enables itper-session, the same opt-in
ADD STATISTICShonours. Also close a hole whereMATERIALIZE STATISTICSignoredallow_statistics = 0altogether undervalidate_mutation_query = 0.Description
allow_statisticswas checked twice: once when the statement was validated, with the submittingsession's value, and once again while the mutation ran — where the background context reads the
server-default profile, not that session. So the statement was accepted and then failed on every
retry:
mutations_sync = 1returnedCode: 341 UNFINISHEDwrappingAlter table with statistics is disabled, and without it the mutation sat insystem.mutationswithis_done = 0forever, blocking every later mutation on the table until a manualKILL MUTATION.allow_statisticsgates the DDL — whether statistics may be declared on a table — so only thesubmitting session's value is meaningful for it, and the check belongs to submission alone. The
behaviour was already inconsistent in the same direction:
ADD STATISTICSunder the same sessionopt-in succeeds, and background merges materialize the declared statistics regardless of the setting,
so refusing the explicit verb at execution time protected nothing.
The gate is therefore applied exactly once, unconditionally at submission time in
InterpreterAlterQuery, next to the other always-on mutation validation, and both execution-timechecks are removed from
MutationsInterpreter. Placing it there rather than in the dry-run pass ofMutationsInterpreter::preparematters:MATERIALIZE STATISTICSparses into aMutationCommandssegment only, and that dry-run pass — the sole validation over those commands — is skipped when the
user sets
validate_mutation_query = 0. That bypass exists on master today:ALTER TABLE ... MATERIALIZE STATISTICS a SETTINGS allow_statistics = 0, validate_mutation_query = 0is accepted and runs.
ADD/DROP/MODIFY STATISTICScarry anAlterCommandand keep their ownalways-on gate in
AlterCommands::validate.Tests
tests/integration/test_statistics_mutation_session_gateis the reported reproducer: a serverprofile with
allow_statistics = 0, a statement opting back in per session, and an assertion thatthe mutation finishes and the table is not wedged for later mutations. It also pins that without the
opt-in the statements are still refused up front, including under
validate_mutation_query = 0. Bothof its cases fail on master and pass with this change, verified locally.
05175_materialize_statistics_session_gatepins the submission-time rejection for all three verbs,with and without
validate_mutation_query, and that the statements complete with the setting on.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/117351]
Version info
26.10.1.2167-master(included in26.10and later)26.9.19.9,26.8.27.9,26.7.30.11