Skip to content

Apply the server's TimezoneUpdate before clickhouse-client parses the data of input() and RETURNING - #131177

Merged
qoega merged 1 commit into
ClickHouse:masterfrom
groeneai:client-input-timezone-update-before-parsing
Nov 13, 2026
Merged

qoega merged 1 commit into
ClickHouse:masterfrom
groeneai:client-input-timezone-update-before-parsing

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130445

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed clickhouse-client parsing the data of INSERT ... SELECT ... FROM input(...) partly or entirely in its own time zone instead of the session_timezone the server uses for the query (for example one set in a user profile with apply_settings_from_server = 0). This also fixes a data race on session_timezone in the client.

Description

On 26.10, INSERT INTO t SELECT * FROM input('d DateTime') FORMAT Values sent by clickhouse-client as a user whose profile sets session_timezone (with apply_settings_from_server = 0) evaluates the first toDateTime(...) rows in the client's time zone and the rest in the profile's (17-24 of 500 rows wrong on official 26.10.2.103 and 26.3.60.2). Plain DateTime text values were parsed in the client's time zone in every row, now in the profile's.

The server sends TimezoneUpdate right after the input-schema Data (also for INSERT ... RETURNING with client data), and the protocol defines it as applying to the rows the client sends. receiveSampleBlock returned at the schema, so the update was read after sendDataFromPipe started the parsing pipeline, and onTimezoneUpdate wrote session_timezone of client_context while the pipeline thread read it in DateLUT::instance: the data race La Casa Del Dolor (amd_tsan) reports since RETURNING is fuzzed (master, #130445).

For an INSERT whose data the server reads through input (input() or RETURNING), over a remote connection to a server that sends it, receiveSampleBlock now reads on to the TimezoneUpdate, so it is applied before any parsing thread exists. Servers that send it first (#118415) still work; older servers and clickhouse-local are unchanged.

The new test fails 20/20 on master and passes 100/100 with the fix; against 26.3, 26.10 and master servers the fixed client parses every row in the server's zone, with no added wait.

🤖 Generated with Claude Code


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

Version info

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

…data

The server sends `TimezoneUpdate` right after the input-schema `Data` of the
`input` initializer (also used by `INSERT ... RETURNING` with client data), and
the protocol defines it as applying to the rows the client is about to send.
`receiveSampleBlock` returned at the schema, so the update was read by
`receiveLogsAndProfileEvents` only after `sendDataFromPipe` had started the
parsing pipeline, and `onTimezoneUpdate` wrote `session_timezone` of
`client_context` while the pipeline thread read it in `DateLUT::instance`:
a data race, and, when the server's `session_timezone` differs from the
client's (a profile `session_timezone` with `apply_settings_from_server = 0`),
the first rows of the INSERT parsed in the client's time zone.

For an INSERT whose data the server reads through `input` (an `input` SELECT
or `RETURNING`), over a remote connection to a server new enough to send the
update, `receiveSampleBlock` now reads on to the `TimezoneUpdate`, so it is
applied on the main thread before any parsing thread exists. A server that
sends it before the schema is handled by the existing case; `LocalConnection`
sends no update and is excluded.

Reported by La Casa Del Dolor (amd_tsan):
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130445&sha=f5439ede34c44107959c68017dfe1f3caedafbf0&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29
ClickHouse#130445
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=4951f241cfaff37833813a18a5544f0ab312ca64&name_0=MasterCI&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29

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

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

Pre-publication review by an independent model (engine: codex; 0 findings in both rounds) plus my own cold review.

# Sev Finding Verdict Evidence / action
1 ⚠️ The fix also changes how plain DateTime text values of input() data are parsed (the input format resolves the time zone when it is created); the first test covered only toDateTime(...) rows AGREE, fixed @ 6e5bd61 the test mixes both row shapes; plain text rows measured: 500/500 in the client's zone on 26.10.2.103 and 26.3.60.2, 500/500 in the server's with the fix
2 💡 Description and changelog entry said only "the first rows" AGREE, fixed PR description names both shapes
3 💡 The commit message still says "the first rows" noted, not blocking the PR description is accurate

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261113-013900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05628_client_insert_input_timezone_update prints 2000 2 0 on master in 20/20 randomized runs: every plain text row and about 12-17 of each INSERT's 500 toDateTime(...) rows are parsed in the client's time zone.
b Root cause explained? The server sends TimezoneUpdate right after the input-schema Data; receiveSampleBlock returned at the schema, so the update was read and written into client_context only after the parsing pipeline thread had started reading session_timezone.
c Fix matches root cause? Yes. The client reads the update where the protocol puts it, before sendData creates any parsing thread; nothing writes the setting during parsing any more. No guard at the race site.
d Test intent preserved / new tests added? New test for input() and RETURNING, each INSERT mixing toDateTime(...) rows and plain text rows, with a guard line that fails if the client and profile time zones coincide. No existing test changed.
e Both directions demonstrated? Master client: 20/20 FAIL. Fixed client against the master server: 20/20 OK. Fixed build: 100/100 OK (50 randomized, 50 not).
f Fix is general across code paths? Every onTimezoneUpdate caller checked: the INSERT data loops get no update from a conforming server any more, SELECT never gets one, the other readers ignore it and parse nothing, LocalConnection sends none.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked stdin, inline and FROM INFILE data, async_insert 0/1, with and without a profile time zone, servers 26.3 / 26.10 / master, and an exception instead of the schema. Types: N/A (packet order, not a type).
h Backward compatible? (maintainer-approved exception only) Yes. No setting or protocol change; servers older than revision 54464 and clickhouse-local take the old path. The time zone of input data changes to the one the protocol specifies: the first toDateTime(...) rows, and every plain text row (500 of 500 were in the client's zone on 26.10.2.103 and 26.3.60.2).
i Invariants and contracts preserved? client_context settings no longer change while a client pipeline thread is alive. An exception while waiting returns false as before, so no data is sent.

Session id: cron:clickhouse-impl-slot-6:20261113-012100

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6e5bd61]

Summary: ✅


AI Review

Summary

Reviewed #131177 at 6e5bd614499e5b8b9f14a7d4bf937fc59b921fbb. The client applies TimezoneUpdate before creating parsing pipelines for client-fed input and RETURNING inserts, fixing inconsistent time-zone interpretation and the concurrent update of session_timezone. No actionable findings. The new regression test, 05628_client_insert_input_timezone_update, passed Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-cli clickhouse-client (interactive CLI) and client library. labels Nov 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6e5bd6144 with master acd88ab8f (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.67, programs/clickhouse-keeper ×0.63 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.3 s 13.2 s +8.9 s (+210%)
Compile time of recompiled translation units

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

Job report

@qoega qoega self-assigned this Nov 13, 2026
@qoega
qoega added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 74c7bf9 Nov 13, 2026
604 of 608 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 13, 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-cli clickhouse-client (interactive CLI) and client library. pr-bugfix Pull request with bugfix, not backported by default 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