Skip to content

Docs: document the transaction statements, KILL TRANSACTION, KILL PART_MOVE_TO_SHARD and EXPLAIN CURRENT TRANSACTION - #131664

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:docs-transaction-statements
Nov 15, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:docs-transaction-statements

Conversation

@groeneai

@groeneai groeneai commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131085

Changelog category (leave one):

  • Documentation (changelog entry is not required)

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

Document the experimental transaction statements BEGIN TRANSACTION, START TRANSACTION, COMMIT, ROLLBACK and SET TRANSACTION SNAPSHOT, and the KILL TRANSACTION, KILL PART_MOVE_TO_SHARD and EXPLAIN CURRENT TRANSACTION statements, in the SQL reference.

Description

First of the PRs for the statements without reference documentation that @ Blargian asked for in #131085. These statements parse on master but had no page or section.

ParserTransactionControl gets a BEGIN TRANSACTION documentation entry and is registered, so system.statements exposes it and the docs autogeneration fills the new docs/reference/statements/transactions.mdx (frontmatter and empty markers, like #131085). The KILL and EXPLAIN entries gain sections for the missing forms. The page is titled BEGIN TRANSACTION because the generator matches the title to the registered name; the sidebar says Transactions.

Each page and section states that the feature is experimental and how to enable it (the badges and note of the transaction functions), and the version it was introduced in: v22.4.0 for the transaction statements, v24.3.0 for the START TRANSACTION alias, v21.11.0 for KILL PART_MOVE_TO_SHARD (checked on the release tags). On the transactions concept page, the example now disables async_insert first, and the note on exceptions names the failures that leave the transaction running.

Validation: I checked every behaviour the pages describe on a server built from this branch, and the examples are copied from those runs. Four findings are on the pages: with the default async_insert = 1, an INSERT ... VALUES or INSERT ... SELECT inside a transaction throws; a query that cannot be parsed or has missing or invalid query parameters does not roll the transaction back, so COMMIT still commits it; SET TRANSACTION SNAPSHOT to an earlier CSN misses the rows of parts the server has already deleted; and writes outside transactions are visible to the next query of a running transaction. I regenerated the pages with autogenerate_docs.py --write --only 'statement:' and ran lychee_check.py --mode links (0 errors; corrupted anchors are reported), navigation_check.py and check_autogenerated_regions.py; the committed tree contains no generated text. 04926_system_statements fails without the new reference line and passes with it.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2369-master (included in 26.11 and later)

groeneai and others added 2 commits November 14, 2026 14:08
…ILL PART_MOVE_TO_SHARD and EXPLAIN CURRENT TRANSACTION forms

`BEGIN TRANSACTION`, `START TRANSACTION`, `COMMIT`, `ROLLBACK` and
`SET TRANSACTION SNAPSHOT` had no reference page, and the `KILL` and
`EXPLAIN` pages did not mention `KILL TRANSACTION`,
`KILL PART_MOVE_TO_SHARD` or `EXPLAIN CURRENT TRANSACTION`, although the
parsers accept them.

`ParserTransactionControl` gets a `BEGIN TRANSACTION` documentation entry
and is registered, so `system.statements` exposes it and the docs
autogeneration fills the new `docs/reference/statements/transactions.mdx`
page. The `KILL` and `EXPLAIN` entries gain sections for the missing forms.
Every page states that the feature is experimental, how it is enabled, and
the version each statement was introduced in (measured on the release
tags: v22.4.0 for the transaction statements, v24.3.0 for the
`START TRANSACTION` alias, v21.11.0 for `KILL PART_MOVE_TO_SHARD`).

Every behaviour on the pages was observed on a server built from this
branch, and the examples are copied from those runs. The generated
regions are left to the autogeneration workflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Transactions concept page: the example runs `SET async_insert = 0` before
  `BEGIN TRANSACTION`. With the default `async_insert = 1` its
  `INSERT ... FORMAT Values` inside the transaction threw
  `Async inserts inside transactions are not supported`.
- `COMMIT`: after a failed query, `ROLLBACK`, `SET TRANSACTION SNAPSHOT` and
  the `EXPLAIN` queries other than `EXPLAIN ANALYZE` still run; everything
  else throws `INVALID_TRANSACTION` until `ROLLBACK`.
- `KILL TRANSACTION`: the session of a killed transaction is in the same
  state as after a failed query (links to `COMMIT`), and the statement also
  needs `SELECT` on `system.transactions`.
- `KILL PART_MOVE_TO_SHARD`: needs `SELECT` on
  `system.part_moves_between_shards`; the two move privileges are needed only
  to cancel a move.
- `SET TRANSACTION SNAPSHOT`: the transaction keeps seeing its own changes,
  including with snapshot `1`.
- The `async_insert` sentence is scoped to `INSERT ... VALUES` and
  `INSERT ... SELECT`, the paths that were observed to throw.

Every changed sentence was checked on a server built from this branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Two review rounds; final head reviewed by both models.

Finding Verdict
⚠️ The transactions concept page example ran INSERT inside BEGIN TRANSACTION with the default async_insert = 1, which throws AGREE, fixed (the example disables async_insert first)
⚠️ After a failed query, EXPLAIN ANALYZE is rejected and SET TRANSACTION SNAPSHOT still runs AGREE, fixed (COMMIT and KILL TRANSACTION sections)
⚠️ KILL TRANSACTION / KILL PART_MOVE_TO_SHARD also need SELECT on their system table AGREE, fixed; the CLUSTER grant for ON CLUSTER is generic and documented on the GRANT page
💡 SET TRANSACTION SNAPSHOT keeps the transaction's own changes visible AGREE, fixed
💡 The INSERT sentence claimed more paths than were observed AGREE, scoped to INSERT ... VALUES / INSERT ... SELECT
💡 Over the MySQL protocol, COMMIT / ROLLBACK without a transaction return OK instead of throwing noted, not changed (the page describes the native and HTTP interfaces)
💡 Snapshot 3 does not show parts removed outside transactions (for example merge sources) noted, not changed (the page names what it adds: parts that transactions removed or rolled back)

@mintlify

mintlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 09f035a.

Approve preview

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: on master SELECT name FROM system.statements WHERE name = 'BEGIN TRANSACTION' is empty, and 04926_system_statements with the new reference line fails on the master binary (-BEGIN TRANSACTION).
b Root cause explained? Statement pages are generated from the documentation of the registered parsers. ParserTransactionControl had none and was not registered; the KILL and EXPLAIN entries lacked KILL TRANSACTION, KILL PART_MOVE_TO_SHARD and EXPLAIN CURRENT TRANSACTION, which the parsers accept.
c Fix matches root cause? Yes: the documentation is added at the source the generator reads; the new page has only frontmatter and empty markers, and no generated region is edited.
d Test intent preserved / new tests added? 04926_system_statements (the list of registered statements) gets the new name. No test of the docs pipeline itself.
e Both directions demonstrated? Yes: master binary + new reference fails, branch binary + old reference fails, branch binary + new reference passes 10/10 with randomized settings. Docs checks in both directions: the generator fails without the new page, lychee reports corrupted anchors, the navigation check fails without the navigation entry, the generated-regions check fails on a hand edit.
f Fix is general across code paths? Every undocumented form of these three parsers is covered (the five transaction statements, two KILL forms, one EXPLAIN kind). The other statement families are separate PRs.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (documentation). Each documented behaviour was run on a server built from this branch: native and HTTP sessions, with and without privileges, read-only, writing and failed transactions, the reserved snapshot values.
h Backward compatible? (maintainer-approved exception only) Yes: documentation strings and a documentation-only registration; no behaviour, setting or format change.
i Invariants and contracts preserved? Yes: one page per registered name with a matching title, every related name registered (04926), every new header has an anchor, every added link resolves on the regenerated pages.

Session id: cron:clickhouse-impl-slot-41:20261114-133100

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [09f035a]

Summary: ✅


AI Review

Summary

PR #131664 documents the experimental transaction control statements, KILL TRANSACTION, KILL PART_MOVE_TO_SHARD and EXPLAIN CURRENT TRANSACTION, registers the transaction reference page, and corrects the transaction guide. No actionable findings remain at head 09f035a260f70589049cece2a3672e95595349f1; both earlier snapshot-documentation findings are addressed.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors pr-documentation Documentation PRs for the specific code PR labels Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 09f035a26 with master b04bc0a81 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

6 object files changed (+38.05 KiB total), 0 added.

Object file Master PR Δ
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserTransactionControl.cpp.o 21.48 KiB 49.71 KiB +28.23 KiB (+131.42%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

13 translation units recompiled, 22 s compile time in total, 13 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-documentation Documentation (docs, examples, READMEs). label Nov 14, 2026
…tements

`SET TRANSACTION SNAPSHOT`: `MergeTreeTransaction::setSnapshot` only
changes the CSN the transaction reads at; `TransactionManager::
snapshots_in_use` still holds the snapshot the transaction started with,
and `VersionMetadata::canBeRemoved` compares removal CSNs against the
oldest of those. So once no running transaction started before a merge, a
mutation or another query removed a part, the part can be deleted, and a
transaction that sets an earlier snapshot (even before the cleanup)
silently misses its rows. No retention time is promised: a transactional
`TRUNCATE` or `DROP PARTITION` bypasses `old_parts_lifetime`. Observed:
after a transactional `ALTER TABLE ... DELETE`, the earlier snapshot
returns both rows right away and none after cleanup; a background merge
alone has the same effect; a transaction that started before the delete
keeps the old part.

Snapshot `3` also shows the parts of transactions that have not committed
yet: `EverythingVisibleCSN` returns before any CSN check, and a second
session reads another session's uncommitted insert with it.

A query that cannot be parsed or whose query parameters are missing or
invalid fails before the scope that rolls the transaction back, so the
transaction stays `RUNNING` and a later `COMMIT` commits the earlier writes
(observed over HTTP and the native client); analysis and execution errors
do roll it back. The concept page's note that every exception prevents the
commit is corrected the same way. The `KILL
TRANSACTION` section now defers to the `COMMIT` section instead of
repeating a broader claim.

`KILL PART_MOVE_TO_SHARD ON CLUSTER` checks both move privileges on `*.*`,
since the initiator does not know the target tables
(`05082_kill_and_system_on_cluster_access_types`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…apshot

A non-transactional insert gets `Tx::NonTransactionalTID` and creation CSN 1,
which `VersionInfo::isVisible` accepts for every snapshot, and a
non-transactional removal hides the part for every snapshot. Observed on a
server built from this branch: while a transaction runs, an `INSERT`,
`TRUNCATE TABLE` or `ALTER TABLE ... DELETE` from another session outside a
transaction changes its next `SELECT`; the same insert inside a committed
transaction, or with `implicit_transaction = 1`, does not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@alexey-milovidov alexey-milovidov 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.

Acceptable.

@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 15, 2026
Merged via the queue into ClickHouse:master with commit e208fd4 Nov 15, 2026
193 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 15, 2026
murphy-4o added a commit to groeneai/ClickHouse that referenced this pull request Nov 16, 2026
ClickHouse#131664 added the declaration while ClickHouse#126158 enabled modernize-use-nodiscard; each passed CI on its own, together they break the clang-tidy build on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-documentation Documentation (docs, examples, READMEs). pr-documentation Documentation PRs for the specific code PR 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.

3 participants