Repository navigation
Conversation
…one is set With --use_client_time_zone=1 the client parses DateTime string literals in its local time zone, but literals interpreted server-side (asynchronous INSERT, SELECT literals) use the session_timezone setting, which the client left empty. The server then fell back to its own default time zone, so an async INSERT of a string literal stored a different instant than the equivalent synchronous INSERT. Set session_timezone to the client local time zone in Client::connect() when use_client_time_zone is enabled and the user has not set session_timezone explicitly, so server-side interpretation matches the client-side (synchronous) path. An explicit --session_timezone still takes priority. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260701-113900 |
|
cc @azat @yariks5s — could you review this? The client left |
|
Workflow [PR], commit [6efe92f] Summary: ✅
AI ReviewSummaryThis PR now seeds Final Verdict
|
…g changes
The previous change seeded session_timezone once in Client::connect(), so it
only reflected the use_client_time_zone value at connect time. On an already
open connection, SET use_client_time_zone / per-query SETTINGS change the
setting without reconnecting, leaving two holes:
- turning use_client_time_zone on mid-session did not seed session_timezone,
so server-side literal parsing kept using the server time zone;
- turning it off left the auto-seeded session_timezone in place, so
server-side parsing never switched back.
Capture the client local time zone once on the first connect (before the
branch that may switch the process default to the server time zone), and seed
session_timezone from it in processParsedSingleQuery for every query whose
effective use_client_time_zone is set and that does not set session_timezone
explicitly. The seed is applied inside the transient per-query settings scope,
so it is recomputed for each query and reverted afterwards, tracking
use_client_time_zone changes in both directions without leaking state.
Extend the regression test to cover the command line flag, a mid-session SET,
a per-query SETTINGS, and turning use_client_time_zone back off.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Follow-up commit 4061501 addresses the review finding (one-shot Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260701-161500 |
The per-query session_timezone seed reads client_local_timezone, captured once in Client::connect(). It was captured via DateLUT::instance(), which folds in session_timezone: starting the client with an explicit --session_timezone (on a host whose real zone differs) cached that override value instead of the machine-local zone. A later SET session_timezone = DEFAULT then reseeded future queries from the cached override, so server-side literal parsing (async INSERT, SELECT) never returned to true use_client_time_zone semantics. Use DateLUT::serverTimezoneInstance().getTimeZone() instead, which reads the process default directly and ignores session_timezone. On the client with use_client_time_zone=1 setDefaultTimezone() is never called, so the process default stays the machine-local zone captured at DateLUT construction. Extends 04401_async_insert_use_client_time_zone to cover the --session_timezone=UTC start followed by SET session_timezone = DEFAULT. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Updated pre-PR validation gate after 6efe92f (session_timezone-agnostic capture). Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260701-182600 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code |
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRRespect use_client_time_zone for string datetime literals parsed on the server ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: cc fix PR author: @groeneai ClickGap · Finding: Triage metadata
|
…r-side DateTime parsing Test 04401_async_insert_use_client_time_zone (from ClickHouse#109051) requires the server to respect session_timezone when parsing DateTime text into columns without an explicit timezone. Upstream has this since PR ClickHouse#100647 (26.4, backported to 26.3/26.2) but stable-25.8 does not, so async inserts (TCP) and all inserts over HTTP were parsed in the server timezone. - DataTypeDateTime/DataTypeDateTime64: resolve the effective timezone (respects session_timezone via DateLUT::instance()) when creating the default serialization. Adapted from upstream doGetSerialization() to 25.8's doGetDefaultSerialization() API (no serialization object pool). - MutationsDateTimeLiteralVisitor: wrap DateTime string literals in mutation predicates/assignments with explicit toDateTime(..., tz) at ALTER time, since background mutation threads lack the session context. Adapted make_intrusive -> std::make_shared for 25.8 AST pointers. - Tests from the upstream PR: 02737 update, 04056, 04057. Co-Authored-By: Claude Fable 5 <[email protected]>
…r-side DateTime parsing Test 04401_async_insert_use_client_time_zone (from ClickHouse#109051) requires the server to respect session_timezone when parsing DateTime text into columns without an explicit timezone. Upstream has this since PR ClickHouse#100647 (26.4, backported to 26.3/26.2) but stable-25.8 does not, so async inserts (TCP) and all inserts over HTTP were parsed in the server timezone. - DataTypeDateTime/DataTypeDateTime64: resolve the effective timezone (respects session_timezone via DateLUT::instance()) when creating the default serialization. Adapted from upstream doGetSerialization() to 25.8's doGetDefaultSerialization() API (no serialization object pool). - MutationsDateTimeLiteralVisitor: wrap DateTime string literals in mutation predicates/assignments with explicit toDateTime(..., tz) at ALTER time, since background mutation threads lack the session context. Adapted make_intrusive -> std::make_shared for 25.8 AST pointers. - Tests from the upstream PR: 02737 update, 04056, 04057. Co-Authored-By: Claude Fable 5 <[email protected]>
Antalya 26.6 Backport of ClickHouse#109051 - Respect use_client_time_zone for string datetime literals parsed on the server
26.3 Stable backport of ClickHouse#109051: Respect use_client_time_zone for string datetime literals parsed on the server
…se-client-time-zone-108038 Respect use_client_time_zone for string datetime literals parsed on the server
Antalya 26.3 Backport of ClickHouse#109051 - Respect use_client_time_zone for string datetime literals parsed on the server
Closes: #108038
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
use_client_time_zonebeing ignored forDateTime/DateTime64string literals interpreted on the server (asynchronousINSERT,SELECTliterals). The client now propagates its local time zone assession_timezonewhenuse_client_time_zoneis enabled, so server-side parsing matches the synchronousINSERTpath.Description
Report: #108038
With
--use_client_time_zone=1, aDateTimestring literal inINSERT ... VALUESwas parsed using the server time zone whenasync_insertwas enabled (the default since 26.2), but correctly using the client time zone whenasync_insert=0:Root cause is client-side. The synchronous path parses the
VALUESblock on the client, using the client's local time zone. The asynchronous path sends the raw query to the server, which parses the literal later using thesession_timezonesetting. Withuse_client_time_zone=1the client leftsession_timezoneempty, so the server fell back to its own default time zone. The server-side parse already honorssession_timezonecorrectly; the client simply never told it the local time zone. The same gap affects any server-side interpretation of a string literal, for exampleSELECT toDateTime('2017-07-14 05:40:00').Fix: in
Client::connect(), whenuse_client_time_zoneis enabled and the user has not setsession_timezoneexplicitly, setsession_timezoneto the client's local time zone. An explicit--session_timezonestill takes priority. The default (use_client_time_zone=0) path is unchanged.Added a stateless regression test that fails before the change (async row stored in server tz) and passes after it (both async and sync rows stored in client tz).
Version info
26.7.1.548(included in26.7and later)