Skip to content

Add prepared statements functionality to ArrowFlight SQL server. - #103047

Merged
yakov-olkhovskiy merged 40 commits into
masterfrom
impr-arrowflight-prep-statements
May 12, 2026
Merged

yakov-olkhovskiy merged 40 commits into
masterfrom
impr-arrowflight-prep-statements

Conversation

@yakov-olkhovskiy

@yakov-olkhovskiy yakov-olkhovskiy commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Add prepared statements functionality to ArrowFlight SQL server.

closes #102886

Version info

  • Merged into: 26.5.1.587

@clickhouse-gh

clickhouse-gh Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [361ed00]

Summary: ✅


AI Review

Summary

This PR adds prepared statement support for Arrow Flight SQL (create/bind/execute/close, limits, TTL, and integration tests), but there are still correctness gaps in prepared execution semantics. Verdict: request changes.

Findings

❌ Blockers

  • [src/Server/ArrowFlight/ArrowFlightServer.cpp:1515-1543] CreatePreparedStatement swallows all exceptions during SELECT schema inference and still creates a handle. This can accept semantically invalid statements (for example unknown tables / access-denied queries) at prepare time and defer real failures unexpectedly to execute time.

    • Suggested fix: only ignore inference failures known to be placeholder-substitution artifacts; propagate semantic/auth/metadata exceptions.
  • [src/Server/ArrowFlight/ArrowFlightServer.cpp:1229-1240] CommandPreparedStatementUpdate can execute prepared SELECT statements through the generic DoPut path, succeed, and return update metadata instead of rejecting statement-kind mismatch.

    • Suggested fix: for CommandPreparedStatementUpdate, validate resolved AST kind and reject non-update statements with Invalid.
  • [src/Server/ArrowFlight/ArrowFlightServer.cpp:1229-1234] Prepared updates still allow INSERT ... FORMAT Arrow while this path does not provide the expected Arrow stream for that prepared execution model, leading to misleading success/no-op behavior instead of explicit rejection.

    • Suggested fix: reject prepared-update execution for INSERT ... FORMAT Arrow unless full streaming semantics are implemented for this flow.
ClickHouse Rules
Item Status Notes
Deletion logging ✅
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ⚠️ Prepared statement prepare/execute semantics remain inconsistent in failure handling and statement-kind validation.
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ⚠️ Prepared update path still accepts unsupported/misleading execution forms.
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Do not swallow semantic/auth errors in CreatePreparedStatement.
  2. Reject CommandPreparedStatementUpdate for non-update statements.
  3. Reject unsupported prepared-update forms such as INSERT ... FORMAT Arrow (or implement full streaming support for them).

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 17, 2026
Comment thread src/Server/ArrowFlight/CallsData.h Resolved
Comment thread src/Server/ArrowFlight/CallsData.cpp Resolved
…er_user server setting with default 100, add corresponding tests
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Apr 18, 2026
Regression from ClickHouse#92141: server aborts with signal 6 during `loadDataPart`
in debug and sanitizer builds when a part directory contains a leftover
`txn_version.txt.tmp` file with no corresponding `txn_version.txt`. This
state is produced by `VersionMetadataOnDisk::loadMetadata` case 2 (an
incomplete write that was not atomically renamed). It returns a
`VersionInfo` with `creation_tid = Tx::DummyTID` and
`creation_csn = Tx::RolledBackCSN`.

`Tx::DummyTID = {NonTransactionalCSN, DummyLocalTID, Nil} = {1, 2, Nil}`
has `start_csn == NonTransactionalCSN` but `local_tid == DummyLocalTID`
— which fails the invariant asserted in `TransactionID::isNonTransactional`.
The new `VersionMetadata::validateInfo` (added by ClickHouse#92141) and
`VersionInfo::wasInvolvedInTransaction` both call `isNonTransactional` on
the loaded `creation_tid`, so the assertion aborts the server.

Two changes:
- `TransactionID::isNonTransactional`: widen the assertion to allow the
  `DummyTID` special case. The function still correctly returns `false`
  for `DummyTID` because `local_tid == DummyLocalTID != NonTransactionalLocalTID`.
- `VersionMetadata::validateInfo`: early-return for rolled-back parts
  (`creation_csn == RolledBackCSN`). Such parts are marked `Outdated`
  immediately after loading by `MergeTreeData::loadDataPart` and cleaned
  up, so the live-part invariants validated here do not apply.

CI reports showing the crash:
- PR ClickHouse#103047: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103047&sha=ec0124d77b94c97a4b1b48049b0215b1dddb94a5&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29
- PR ClickHouse#102961: same `Stateless tests (amd_debug, distributed plan, s3 storage, parallel)` check

Regression test `04104_transaction_version_metadata_dummy_tid_load.sh`
deterministically creates the scenario by dropping a bogus
`txn_version.txt.tmp` into a part directory and running `DETACH` +
`ATTACH`. Before the fix the server aborts with signal 6 at
`TransactionID.h:90`; after the fix the rolled-back part is marked
`Outdated` and invisible.

Session: cron:clickhouse-ci-task-worker:20260418-221500
Comment thread src/Server/ArrowFlight/CallsData.cpp Resolved
@yakov-olkhovskiy
yakov-olkhovskiy requested a review from Diskein May 2, 2026 13:43
@yakov-olkhovskiy

Copy link
Copy Markdown
Member Author

@Diskein there is also a corresponding update for docs which I'm trying to keep relevant - it should help you to keep track of changes this PR brings:
ClickHouse/clickhouse-docs#6124

@clickhouse-gh

clickhouse-gh Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 91.39% (435/476) · Uncovered code

Full report · Diff report

@yakov-olkhovskiy

Copy link
Copy Markdown
Member Author

@Diskein could you please review - I think it's ready to merge

@Diskein Diskein left a comment

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.

Looks good, just some remarks, follow-up questions and nitpicking 😄

}

{
auto & by_exp = prep_statements.get<ByExpirationTime>();

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.

boost::multi_index really shines here! 🎉

@yakov-olkhovskiy
yakov-olkhovskiy added this pull request to the merge queue May 12, 2026
Merged via the queue into master with commit 6d5199c May 12, 2026
962 of 970 checks passed
@yakov-olkhovskiy
yakov-olkhovskiy deleted the impr-arrowflight-prep-statements branch May 12, 2026 22:40
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Add prepared statements to the Arrow Flight SQL interface.

3 participants