Skip to content

Cherry pick #117351 to 26.7: Check allow_statistics only when validating a mutation, not when running it - #125654

Merged
robot-clickhouse merged 11 commits into
backport/26.7/117351from
cherrypick/26.7/117351
Oct 14, 2026
Merged

robot-clickhouse merged 11 commits into
backport/26.7/117351from
cherrypick/26.7/117351

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #117351

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 10 commits August 31, 2026 14:27
…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
…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
…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]>
…-session-gate

Check `allow_statistics` only when validating a mutation, not when running it
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 13, 2026
# Conflicts:
#	src/Interpreters/InterpreterAlterQuery.cpp
#	src/Interpreters/MutationsInterpreter.cpp
@robot-clickhouse
robot-clickhouse merged commit d2dd153 into backport/26.7/117351 Oct 14, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.7/117351 branch October 14, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants