Repository navigation
Fix key analysis for toYYYYMMDDhhmmss, toHour and toMinute when the local clock goes back - #124530
Conversation
…ocal clock goes back Key analysis calls a function monotonic on a range when its factor transform is equal at both ends. toYYYYMMDDhhmmss had ZeroTransform (always monotonic), toHour used the local day and toMinute toStartOfHour, which counts hours elapsed since local midnight. None of them changes when the local clock goes back (a DST fall-back, the 30-minute change in Australia/Lord_Howe, 03:45 -> 02:45 in Pacific/Chatham, DateLUT repeating hour 23 on a day longer than 24 hours), so KeyCondition got a reversed or too narrow range and skipped matching granules; read in order and constant wrapping trusted the "always monotonic" claim. The factor is now the local day, the UTC offset and the instant at which the clock showed the start of the current local day (toHour, toYYYYMMDDhhmmss) or hour (toMinute). timezoneOffset and the displayed time split a lookup-table day at the same instant, and the table holds at most one offset change per day, so equal day and offset put both ends in one constant-offset run. There the third component only grows (by the period at a wrap, by an hour at each hour DateLUT repeats as 23), so equal factors mean the clock moved forward with time between the ends. Without the offset, a forward change on a day longer than 24 hours could bring the third component back to an earlier value. Outside the lookup table no two points share a factor. For toYYYYMMDDhhmmss the factor is constant for Date, Date32 and, inside the lookup table, for a fixed-offset time zone, so cross-day pruning is kept there. It does not keep the "always monotonic" claim: read in order asks without the time zone argument, and with one (toYYYYMMDDhhmmss(dt_utc, 'America/New_York')) the claim is wrong. Measured over 81 time zones and every transition day of the DateTime range (20,088 count() vs countIf pairs): 3,082 mismatches before, 0 after; 1,240 pre-1970 DateTime64 pairs in 5 zones: 171 before, 0 after. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the ToClockPeriodStartFactorImpl comment to the invariant it relies on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 6 findings) plus the reviewer's own cold review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261008-003400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261007-232600 |
|
Workflow [PR], commit [56cad74] Summary: ✅
AI ReviewSummaryThis PR tightens monotonicity analysis for Final Verdict✅ No findings. The implementation matches the stated bug, the new stateless coverage exercises the important planner paths, and the current LLVM Coverage ReportMeasured on commit 56cad74.
Changed lines: Changed C/C++ lines covered: 13/17 (76.47%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes32 object files changed (+17.96 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units133 translation units recompiled, 1017 s compile time in total, 133 of them have a recent master baseline. |
b0ae0f2
toHour and toTimeWithFixedDate over a pre-epoch DateTime and DateTime64 are fixed on master by ClickHouse#124530 and ClickHouse#124474, so their queries pass there and no longer test this change. toTimeWithFixedDate also rounds a pre-epoch DateTime64 down to whole seconds on master now, so the expected row of the removed DateTime64 case no longer exists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed primary key, partition key and skip index analysis that could skip or over-count rows, and
ORDER BYoptimization that could return rows in the wrong order, fortoYYYYMMDDhhmmss,toHourandtoMinuteover aDateTimeorDateTime64column when the local clock goes back, for example on the daylight saving time change inAmerica/New_Yorkor the 30-minute change inAustralia/Lord_Howe.Description
Related: #124474 (same mechanism for
timezoneOffsetandtoTimeWithFixedDate)On 26.3.33.24 and master, with
dt DateTime('America/New_York')as the sorting key holding 01:50 EDT and 01:10 EST of 2024-11-03,SELECT count() FROM t WHERE toYYYYMMDDhhmmss(dt) = 20241103015000returns 0 instead of 1, andORDER BY toYYYYMMDDhhmmss(dt) LIMIT 1returns the 01:50 row.toMinute(dt) = 50inAustralia/Lord_HoweandtoHour(dt) = 3inPacific/Chathamalso return 0 instead of 1.Key analysis calls a function monotonic on a range when its factor is equal at both ends.
toYYYYMMDDhhmmsswas always monotonic,toHourused the local day andtoMinutethe start of the hour counted from local midnight; none of them sees the clock go back.All three now use the local day, the UTC offset and the instant at which the clock showed the start of the current local day (
toHour,toYYYYMMDDhhmmss) or hour (toMinute), so equal factors mean the clock did not go back between the ends. FortoYYYYMMDDhhmmssthe factor is constant forDate,Date32and fixed-offset zones, which keep cross-day pruning.The price: in a zone with offset changes,
toYYYYMMDDhhmmssranges across local midnight are no longer pruned (896 rows read instead of 64 for an equality in the test).ORDER BY toYYYYMMDDhhmmss(x)no longer reads in order, and a sorting keytoYYYYMMDDhhmmss(x)no longer prunes by a condition onx, also in UTC: these callers do not see a time zone argument, and with one (toYYYYMMDDhhmmss(dt_utc, 'America/New_York')) the old claim is wrong.Validation: 15 of the test's 23 lines differ on master, and 10 of 11 mutations of the fix fail it. Over 81 zones, 20,088
count()vscountIfpairs: 3,082 mismatches on master, 0 with the fix.toString(dt, 'tz')has the same time zone argument hole; not changed here.Nullable(DateTime(tz))keys also need #121265.Workflow [PR]
Sync PR [sync-upstream/pr/124530]
Version info
26.10.1.2057-master(included in26.10and later)