Repository navigation
Saturate toLastDayOfMonth and toLastDayOfWeek at the Date maximum - #118642
Conversation
`toLastDayOfMonth(toDate('2149-06-04'))` returned `1970-01-24` and
`toLastDayOfWeek(toDate('2149-06-02'))` returned `1970-01-01`: the last day of
the month or of the week is past the `Date` maximum (2149-06-06) and the
`DayNum` result wrapped around 65535.
Both functions declare themselves always monotonic, so `KeyCondition` uses them
for primary-key range analysis, and the wrapped value inverted the mapped range:
`SELECT count() FROM t WHERE toLastDayOfWeek(d) = toDate('2149-05-31')` returned
`0` where `countIf` counts 7, so rows were lost even for a result that is in
range.
The `Date32` and `DateTime64` overloads of both functions already clamp; the
`Date` ones did not, because they compute through the 16-bit `DayNum`. They now
compute in the extended range and clamp the same way, which is also what the
same call on a `Date32` argument returns. Saturation keeps the functions
monotonic, so the pruning is correct again.
Closes: #117697
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [11d272d] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict✅ Approve. No inline review comments posted. LLVM Coverage ReportMeasured on commit 11d272d.
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units132 translation units recompiled, 942 s compile time in total, 132 of them have a recent master baseline. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118642&sha=d05289ca7ceccc88e1e83da605fd187fba311356&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The failing test is I could not find an open issue tracking this flakiness (the related feature issue #116844 is about the quota accounting, not the flaky wait). |
|
Not open as a PR yet, and the reason is on the record. I root-caused this on 2026-09-09 and posted the write-up as a comment on #116844 rather than as a new issue, which is why the search did not turn it up: Short version: this is a server-side bug in the temporary-lock path, not a test bug and not #116843's quota formula. if (tmp_locks_quota > 0 && has_replica_without_locks)
{
tmp_locks_quota = 0;
return;
}A consumer that arrives with Five narrow fixes do not hold (all refuted in that comment): What survives is yield state scoped to the storage and shared by every I will take your instruction as the go-ahead for that shape, implement it, and link the PR here. If you want the flaky wait tracked apart from #116844, I can open a dedicated issue for it. |
|
No fix PR yet, and I want to say why rather than leave the request open. I designed the fix I committed to above (yield state shared by all
Both come from the same gap: nothing tells an incumbent that the lockless replica actually wants a I have written the analysis, the options and a recommendation up on the tracking issue: Happy to implement whichever shape the Kafka owners prefer. Two narrowings worth having here: the test |
|
🕵 Thank you for the thorough write-up on both counts — the root cause in Yes, please do open a dedicated issue for the flaky wait itself. #116844 is about the quota accounting, so the flakiness of Nothing here blocks this pull request — the failure is unrelated to it, and the integration test passed on the current commit after the latest merge from |
|
Filed: #119632, tracking the flaky wait itself rather than the quota accounting. It leads with the test Understood on the rest: I am not forcing the protocol change from this side, and the design question stays |
Closes: #117697
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
toLastDayOfMonthandtoLastDayOfWeekof aDateargument now saturate at theDatemaximum (2149-06-06) instead of wrapping around to 1970. The wrapped result also silently dropped matching rows through primary-key pruning.Description
toLastDayOfMonth(toDate('2149-06-04'))returned1970-01-24andtoLastDayOfWeek(toDate('2149-06-02'))returned1970-01-01: the last day of the month or of the week is past theDatemaximum and theDayNumresult wrapped around65535. Both functions declare themselves always monotonic, soKeyConditionused them for primary-key range analysis and the wrapped value inverted the mapped range -SELECT count() FROM t WHERE toLastDayOfWeek(d) = toDate('2149-05-31')returned0wherecountIfcounts 7, so rows were lost even for a result value that is perfectly in range.Both functions already clamp for
Date32/DateTime64arguments; theDateoverloads did not, because they computed throughDayNum, which is 16-bit. They now compute in the extended range and clamp the same way, which is also what the same call on aDate32argument returns. With saturation the monotonicity claim holds, so the pruning is correct again.Workflow [PR]
Sync PR [sync-upstream/pr/118642]
Version info
26.9.1.1303(included in26.9and later)