Conversation
chrono represents a parsed :60 second as 59 with nanos >= 1e9, a value that sorts before the following second while the epoch family (extract epoch, casts to mz_timestamp, timestamp subtraction, date_bin, precision rounding) counts it at or past that second. That breaks the monotonicity contracts persist filter pushdown narrows ranges with: an interior leap value escapes the endpoint-derived range, so a part holding one could be wrongly discarded. Roll :60 over at the parse boundary, matching Postgres, so the leap representation never enters a timestamp. TIME keeps it: rolling a time over would wrap to 00:00:00 and reverse its ordering, and the whole-second leap time is provably harmless (fractional leap seconds are rejected at parse for all types). add_date_time is the other way a leap representation reached a timestamp. It passed a leap-second TIME's raw nanos straight through, so DATE + TIME '23:59:60' still constructed one and disagreed with the equivalent timestamp literal. It now rolls over the same way. Both rollovers can overflow chrono's range: TIMESTAMP '262142-12-31 23:59:60' parses, because that is chrono's max date and the leap value passes the HIGH_DATE check, and adding the rollover second overflows. Overflow reports out of range in the timestamp, timestamptz, and DATE + TIME paths instead of panicking. Closes: PER-63 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
chrono represents a parsed
:60second as second 59 with nanos >= 1e9. That value sorts before the following second, while the epoch family (extract epoch, casts tomz_timestamp, timestamp subtraction,date_bin, precision rounding) counts it at or past that second. The two orders disagree, which breaks the monotonicity contracts persist filter pushdown narrows ranges with. An interior leap value escapes the range derived from a part's endpoints, so a part holding one could be discarded even though it matches.Closes: PER-63
Description
Roll
:60over into the next minute at the parse boundary, matching PostgreSQL, so the leap representation never enters a timestamp.TIMEkeeps the leap representation. Rolling a time over would wrap it to00:00:00and reverse its ordering, and the whole-second leap time is provably harmless, because fractional leap seconds are rejected at parse for every type.add_date_timewas the other way in. It passed a leap-secondTIME's raw nanos straight through, soDATE + TIME '23:59:60'still constructed the representation and disagreed with the equivalent timestamp literal. It now rolls over the same way.Both rollovers can overflow chrono's range.
TIMESTAMP '262142-12-31 23:59:60'parses, because that is chrono's maximum date and the leap value passes theHIGH_DATEcheck, and adding the rollover second then overflows. Overflow reports out of range in the timestamp, timestamptz, andDATE + TIMEpaths instead of panicking. The timestamptz path had been folding that overflow into an invalid-input-syntax detail string, so it now reports the same out-of-range error kind the timestamp path does.Effect on the frozen storage source casts
The rollover sits in the shared inner parse functions, so it also reaches
parse_timestamp_legacyandparse_timestamptz_legacy, the frozen wrappers behind the storage source castsCastStringToTimestampandCastStringToTimestampTz. That is a deliberate exception to the stability contract inmz_storage_types::sources::casts, chosen rather than stumbled into, and it is recorded at those casts' eval arm.Storage wants the rollover for the same reason SQL does. Source-cast output is exactly what filter pushdown reads back later, so scoping the rollover to the non-legacy path would have left the bug alive on the path that matters most, and would have made a
TIMESTAMP '...:60'literal disagree with a source-ingested'...:60'.No migration accompanies the change, because the inputs whose output differs cannot reach those casts. They are built only for a PostgreSQL source column of type
timestamportimestamptz(mz_sql::pure::postgres::pg_type_to_cast_func), so their input is PostgreSQL's own text output for that type. PostgreSQL normalizes:60at input and has no leap representation to emit, which is confirmed against PostgreSQL 16:'2015-06-30 23:59:60'::timestampstores and renders as2015-07-01 00:00:00. Atextcolumn takes no cast at all, so user-supplied:60text never routes here either.CastStringToMzTimestampshares the same parse but converts to epoch milliseconds, which already counted a leap value at the following second, so its output is unchanged.Verification
leap_second_rollover_at_max_date_errorsinstrconv.rscovers the overflow at the maximum date and pins the error kind on both the timestamp and timestamptz paths.timestamp_frozen_leap_secondincasts.rsis the cross-release pin for the frozen storage casts. It asserts the rolled-over output forCastStringToTimestampandCastStringToTimestampTz, the unchangedCastStringToMzTimestampvalue, and the out-of-range error on the maximum date. It lives with the other error-snapshot tests, which are absolute rather than comparative, so it catches a future change to the frozen behavior in a way the parity tests cannot. Theparity_timestampandparity_timestamptzinputs also gained:60cases, so the storage and SQL casts cannot silently diverge on them.test/sqllogictest/explain/pushdown.sltpins the rolled-over values for timestamp and timestamptz literals, for themz_timestampcast that pushdown narrows on, and forDATE + TIME.🤖 Generated with Claude Code
https://claude.ai/code/session_01KUZqx24SBfhHeRdZPN76QR