Skip to content

Add a setting to throw exception when no query to kill - #85023

Merged
alexey-sitnikov-ch merged 40 commits into
ClickHouse:masterfrom
zwy991114:kill_throw_if_noop
Sep 30, 2026
Merged

alexey-sitnikov-ch merged 40 commits into
ClickHouse:masterfrom
zwy991114:kill_throw_if_noop

Conversation

@zwy991114

@zwy991114 zwy991114 commented Aug 4, 2025 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

Added the kill_throw_if_noop setting, enabled by default, which makes local KILL QUERY and KILL MUTATION statements throw NO_QUERY_TO_KILL when their selection produces no eligible target. ON CLUSTER execution remains tolerant of empty matches. Set kill_throw_if_noop = false to preserve the previous behavior.
Related #83348

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

Version info

  • Merged into: 26.10.1.1092-master (included in 26.10 and later)

@yariks5s yariks5s self-assigned this Aug 4, 2025
@yariks5s yariks5s added the can be tested Allows running workflows for external contributors label Aug 4, 2025
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aaec9e3]

Summary: ✅


AI Review

Summary

This PR adds the kill_throw_if_noop setting, keeps ON CLUSTER and TEST tolerant of empty matches, and updates a broad set of KILL tests. The interpreter changes look coherent overall, but the branch still has one contract-coverage gap around the new default and the PR changelog entry no longer matches the current code.

PR Metadata
  • Changelog category: Improvement matches the current branch now that kill_throw_if_noop defaults to false.
  • Changelog entry: required, but it still says the setting is enabled by default and that failures use NO_QUERY_TO_KILL. The current code defaults to false and raises NOTHING_TO_KILL only when the setting is enabled.
  • Exact replacement: Adds the \kill_throw_if_noop` setting for local `KILL QUERY` and `KILL MUTATION`. When set to `true`, empty matches raise `NOTHING_TO_KILL`; by default, empty matches remain a no-op. `ON CLUSTER` execution remains tolerant of empty matches.`
Findings
  • ⚠️ [tests/queries/0_stateless/05291_kill_throw_if_noop_live_query.sh:7-24] The new empty-match coverage still forces kill_throw_if_noop = 1/0 while the section text and reference output describe that path as "the default". Because the implicit default is now false, the branch still lacks a focused regression test that a local no-op KILL QUERY / KILL MUTATION remains non-throwing without an explicit setting, and the current test narrative in this file and section 19 of 05060_kill_query_without_processes_grant is already wrong. Suggested fix: make one absent-match case rely on the implicit default and update the echoed/reference text accordingly.
Final Verdict

Request changes. Fix the stale changelog entry and add one no-op test that uses the implicit default before merging.

LLVM Coverage Report

Measured on commit aaec9e3.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 61/61 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 4, 2025
@zwy991114
zwy991114 force-pushed the kill_throw_if_noop branch from c6f3e54 to e0e85bc Compare August 6, 2025 07:51
@zwy991114
zwy991114 force-pushed the kill_throw_if_noop branch from 3c758c1 to 3f63dfe Compare August 7, 2025 02:47
@zwy991114

Copy link
Copy Markdown
Contributor Author

@yariks5s Hi, any suggestions in failed tests?

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

Dear @yariks5s, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@yariks5s yariks5s self-assigned this Sep 22, 2025

@yariks5s yariks5s left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

@zwy991114
zwy991114 requested a review from yariks5s September 26, 2025 03:16
@yariks5s

Copy link
Copy Markdown
Member

Could you please update with master once more?

@zwy991114

Copy link
Copy Markdown
Contributor Author

Could you please update with master once more?

Of course, I've done.

@yariks5s

Copy link
Copy Markdown
Member

@zwy991114 can we please also add a tests with enabled setting that kills the existing query? It should not throw an error and we need to check it in tests.

@alexey-sitnikov-ch

Copy link
Copy Markdown
Contributor

@zwy991114 Hi, would you consider renaming the error code from NO_QUERY_TO_KILL to NOTHING_TO_KILL and making the message depend on the command?

  • KILL QUERY: No query to kill
  • KILL MUTATION: No mutation to kill

Currently, KILL MUTATION may return No query to kill, which can confuse users because they are trying to kill a mutation, not a query. If changing the error code would cause compatibility issues, adjusting the message alone would still improve clarity.

Thanks.

@zwy991114

Copy link
Copy Markdown
Contributor Author

good idea!

zwy991114 and others added 5 commits September 23, 2026 12:06
Conflicts resolved:
- `InterpreterKillQueryQuery.cpp`: kept master's reduced/self-kill descriptor
  path (`selfKillDescriptors` from ClickHouse#117999) and re-applied the empty-match
  throw (`NOTHING_TO_KILL`) after descriptor selection.
- `SettingsChangesHistory.cpp`: kept both new 26.10 entries (master's
  `analyzer_compatibility_allow_cte_redefinition` and ours
  `kill_throw_if_noop`).

Verified: full build clean; `05233_kill_throw_if_noop`, `00417_kill_query`,
`01003_kill_query_race_condition` pass against the merged binary.

Co-Authored-By: Claude Code <[email protected]>
The self-kill path merged from zwy/master (ClickHouse#117999) documents that a user
holding neither `SELECT` on `system.processes` nor `KILL QUERY` gets "no rows
rather than reporting an error" when naming an id that is not running as
them. With `kill_throw_if_noop` enabled (the default), that no-op now throws
instead, so say so explicitly in the statement docs.

Co-Authored-By: Claude Code <[email protected]>
…row_if_noop

# Conflicts:
#	src/Core/SettingsChangesHistory.cpp
@alexey-sitnikov-ch

Copy link
Copy Markdown
Contributor

@yariks5s hi, please review this PR one more time.
Thank you

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread src/Parsers/ParserKillQueryQuery.cpp Resolved
# Conflicts:
#	tests/integration/test_phantom_parts_in_mutations/test.py
Comment thread src/Parsers/ParserKillQueryQuery.cpp Resolved

@yariks5s yariks5s left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change is really simple, the finding is not severe, the only change we need to think about is about enabling it by default, we need a good reason for that

Comment thread src/Core/Settings.cpp Outdated
- 1 - Enable
)", 0, \
{"25.12", false, true, "New setting. Add optimization to remove unused columns in query plan."}) \
DECLARE(Bool, kill_throw_if_noop, true, R"(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also a question: do we really want it to be enabled by default? This is a backward-incompatible change, then. That is not bad, but we need a good reason for this incompatible change and for it to be noted (change the changelog category). For me, having it set to false by default is just fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yariks5s I feel the same. Potentially it can break existing "kill" automations because they will get exception in some cases. Personally I would like to keep it disabled by default and let users to adopt code 1st.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zwy991114 its better to keep default=false for this parameter. It will be change to 'true' next release/pr.
What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexey-sitnikov-ch I agree with this approach as well; in fact, I also wanted to set the default value to false from the start.

@yariks5s

Copy link
Copy Markdown
Member

I just saw the initial issue by Nikita mentioning that it can be enabled by default. Ok, but we need to change the changelog category to the backwards incompatible change in this case

@yariks5s

Copy link
Copy Markdown
Member

Also, the relevant test has failed in CI, due to timeout. It would be nice to speed up the test so there is no chance it fails with timeout in the CI.

Future PR or relase will change default to true

Removed redundant integration test (there is stateless test already).
Comment on lines +7 to +24
# `kill_throw_if_noop` is enabled by default. `05233_kill_throw_if_noop.sql` covers the absent
# query_id / mutation_id cases; this test covers the rest of what the former integration suite
# `test_kill_throw_if_noop` exercised: `user = currentUser()` matching nothing (sections 1-2),
# killing a running query without throwing (section 4), `KILL MUTATION` with an empty match
# (sections 5-6), and the `TEST` dry runs staying previews instead of throwing (sections 3, 7).
# A dedicated, otherwise idle user keeps the `currentUser()` outcome deterministic while
# stateless tests run in parallel.

ID="${CLICKHOUSE_TEST_UNIQUE_NAME}"
USER="kq_$ID"

$CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS $USER"
$CLICKHOUSE_CLIENT -q "CREATE USER $USER IDENTIFIED WITH no_password"
$CLICKHOUSE_CLIENT -q "GRANT SELECT ON system.numbers TO $USER"
$CLICKHOUSE_CLIENT -q "GRANT SELECT(query_id, user, query) ON system.processes TO $USER"

echo "-- 1. user = currentUser() matches only the caller's own rows, and the KILL statement itself is excluded; with the dedicated user idle otherwise, the match is empty and the default throws"
OUT=$($CLICKHOUSE_CLIENT --user "$USER" -q "KILL QUERY WHERE user = currentUser() SETTINGS kill_throw_if_noop=1" 2>&1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new stateless coverage still does not actually pin down the default value here. The header says kill_throw_if_noop is enabled by default, section 1 says "the default throws", and section 19 of 05060_kill_query_without_processes_grant still says the same thing, but the empty-match queries themselves all force kill_throw_if_noop = 1 or 0.

That means a future flip back to true would leave these no-op cases green while the test narrative and reference output say the opposite. Can we make at least one empty-match KILL QUERY / KILL MUTATION case use the implicit default and update the echoed/reference text accordingly?

@yariks5s

Copy link
Copy Markdown
Member

Still looks good to me

@alexey-sitnikov-ch
alexey-sitnikov-ch added this pull request to the merge queue Sep 30, 2026
Merged via the queue into ClickHouse:master with commit 5e014d3 Sep 30, 2026
439 of 441 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 30, 2026
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-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants