Repository navigation
A GROUP BY of a timestamptz's unit groups by a stored 15-minute bucket first (#1146) - #1149
Merged
Merged
Conversation
…t first (WIP, #1146) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… boundary, and a float's sum keeps its plan (WIP, #1146) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mn's a statement, every other key whole (#1146) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…se note (#1146) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tagspace
marked this pull request as ready for review
November 18, 2026 14:07
tagspace
marked this pull request as draft
November 18, 2026 15:08
tagspace
marked this pull request as ready for review
November 18, 2026 16:04
# Conflicts: # release-notes/next.md # src/duck/sync.ts
… and the inner keys are the GROUP BY's alone (#1146) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # release-notes/next.md
A key that reads no column (a literal, a parameter, a cast of either) was matched by its form, so every equal literal in the list, the HAVING and the ORDER BY took its inner column's place: a type modifier, EXTRACT's field, an interval's quantity. Such a statement now keeps today's plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
From Claude (Opus 5.5)
Closes #1146
What it does. Beside each
timestamptzcolumn, a synced table now holds an INTEGER: the value's 15 minutes of UTC. The first sync, the poll, the stream (whole rows and carried updates) and compaction each write it. A GROUP BY of the column's hour, day, week, month, quarter or year, planned in a zone other than UTC, groups by the bucket first. It works out the local unit once a bucket, instead of once a row (src/duck/bucket-group.ts). On a table every row of which its bucket decides, a cold query reads the bucket and not the time. Nothing is refused.How the 1980 and infinity guard holds without going stale (round 2, the owner's decision)
BUCKET_NONE(-1). A NULL stays NULL. Every write path computes it from the row, so the write that adds such a row marks it in its own transaction.tests/fixtures/duck-plans.json).getvariable. A session variable is set before the statement and folded in at bind, outside the statement's transaction. A write committed in between would meet a flag still saying "clean". The bucket's own statistics have no such gap.Other decisions
tests/duck-bucket-zones.test.tsasserts this exact list over every zone the engine knows. The session's zone is folded in at bind, and in these zones every row is truncated from its time.timestamp without time zonegets no bucket. Its truncation never reads the session zone.Measured on a laptop against main (5026d3d). The source has 50 M orders with two timestamptz columns, joined to 2.5 M customers, times in order with their own microseconds. Warm, over the Postgres API, min of 2 alternating runs. "Read cold" is the statement's SQL in a fresh engine instance over the file, with the engine's buffer cold: the profiler's
total_bytes_read, then its time. The page cache was not cleared.WHERE created_at >= …) reads the time for its own filter.The benchmark's customer's year (not built). The joined query also groups by
date_trunc('year', c.created_at), which is worked out per joined row after the join. By hand on the head's 50 M file, Kathmandu, warm, same answers:So moving a second column's unit below the join would take the query to about a third of main's time. That is a change of its own.
Tested
tests/duck-time-bucket.test.tsholds every unit and every aggregate to Postgres (PGlite). It covers UTC, New York, Kolkata, Kathmandu, Lord Howe, Chatham, St. John's and Casey, with rows at and 1 µs either side of every change and month start, and rows before 1980, infinite and NULL.tests/duck-bucket-zones.test.tschecks the zones, the engine's aggregates and the bucket's values.tests/integration/duck-time-bucket.itest.tschecks the bucket through the first sync, a poll, compaction and the stream, with Kathmandu answers equal to psql.scripts/fails-without.tsPROVED each new test against e971531, and the first round's tests against 6889195.issue 1146|date_trunc|histogram|time literals grouped) gave 2165 statements, 0 differ.Left out: the integer join key (#1144), and the per-customer unit above.
🤖 Generated with Claude Code