Repository navigation
Daylight saving, planner scale, query pruning and the 1.0 final report - #28
Merged
Merged
Conversation
Two claims the design rests on had no test. Clock changes: a daily grid in Europe/Berlin runs local midnight to local midnight, so the day the clocks go forward is 23 hours of real time and the day they go back is 25. Unit tests pin the windows, the period a boundary instant belongs to, and that the UUIDv7 codec encodes those same shifted instants contiguously; an integration test maintains such a table across the March transition and checks both pg_get_expr and where rows actually land. Scale: tests/unit/test_scale.py reads a tree of 18 001 nodes in two statements whatever its size, plans a converged one to a no-op inside a loose time budget, finds a single missing bucket among thousands, and shows that facts are gathered per lifecycle unit rather than per leaf. A planner that turned quadratic now fails the suite instead of a maintenance window.
…nal report Three pages the 1.0 research promised and never wrote. Query a partitioned table: a lifecycle that is correct buys nothing at read time unless the query constrains the partition key. The page shows, from plans measured on 17, what each method prunes on, why an expression over the key prunes nothing, when pruning moves to executor start, and how to build a predicate in an encoded key's own type. The same measurements are added to the verified-semantics page, together with the Berlin day that lasts 23 hours. The maintenance plan gains a section on cost: two statements to read any tree, a third only when a policy asks for facts, planning linear in the nodes. The final report answers the questions the research set out with, in one place: what the ten systems do, which abstractions that forced, what changed, what was measured, what each project would still write itself, what is deliberately not covered, and what looks worth doing next.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
… type The executor is built from protocols so that a repository can be written against any driver, but its attach recovery caught SQLAlchemyError. A repository on psycopg, asyncpg or a Django connection raises something else, the clause did not match, and three behaviours were lost at once: the compensating move-back of rows already taken out of the DEFAULT partition — which left them in a table invisible through the parent — the benign handling of a race with another worker, and the reconcile-and-retry on a DEFAULT conflict. The helpers behind the clause were already driver-neutral: pg_sqlstate reads sqlstate or pgcode off the exception or its orig, so a bare psycopg.Error and an asyncpg.PostgresError answer like a SQLAlchemy one. Only the catch named a vendor. It now catches Exception and decides on the SQLSTATE, which keeps every existing path identical for SQLAlchemy and gains the same recovery for everyone else; anything unrecognised, SQLSTATE or not, still leaves after the reconciled rows have been put back. No public API changes and nothing new for a repository author to implement — the contract is only that the driver's exception is allowed through, which the extension guide now says. Closes #29.
… for themselves Three settings live on two objects and have to agree: the orphan marker prefix, the DDL timezone and the boundary codec. Passing one of them to a single collaborator is silent, which is the part worth fixing. The marker prefix is the one that matters to maintenance: the repository stamps it on detach, the metadata provider looks for it when discovering orphans, and a disagreement means nothing detached is ever seen again — no error, just partitions accumulating. PartitionLifecycleService now refuses that pair where the two first meet, structurally, the way the calculator/DDL timezone pair is already refused; a repository or provider that declares no prefix is trusted and skipped. Both now expose marker_prefix, and OrphanMarkerAware is the protocol that says so. The other two are used by is_partition_closed alone, and the object that knows both is the table's own TimeBoundaries — it chose the calendar, the timezone and the encoding. It can now be handed over directly, is_partition_closed(name, boundaries=config.time_boundaries), so reader and writer cannot disagree; the constructor arguments stay for callers without a config at hand. DropPartition also carries the bounds it was planned with. DETACH clears relpartbound, so by drop time the catalog no longer records where a partition sat and its name is the only evidence left — which the planner already decodes to decide the drop. Reporting it costs nothing, puts the period in the plan a reader sees, and gives an export a typed window without a second guess at the name. Refs #27.
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.
Closes the four things the 1.0 research promised and left open. No library code changes — tests and documentation only.
Daylight saving
Every timezone test stood on Europe/Moscow, which never moves its clocks, so the calendar's behaviour across a transition was unpinned. Europe/Berlin now covers it:
2026-03-28 23:00+00→2026-03-29 22:00+00, 23 real hours) and the day that gains one (25 hours), for which local day an instant on either side of the change belongs to, and for the UUIDv7 codec encoding those same shifted instants with adjacent days still contiguous;pg_get_exprand where rows at 21:30Z and 22:30Z actually land — 23:30 and 00:30 in Berlin, one local day apart.HourPeriodCalculatoralready refuses a non-UTC zone for this reason; that stays.Planner scale
tests/unit/test_scale.pypins the three cost claims the architecture rests on, against a tree of 18 001 nodes (2 000 monthly branches × 8 hash buckets):get_actual_treeissues exactly two statements for one branch and for two thousand — no query per partition;CREATE, both inside a loose time budget (measured ~0.15 s, budget 10 s — enough to fail a quadratic planner, not enough to flake on CI);fact_targetsnames 2 000 targets, not 16 000: facts are gathered per lifecycle unit, never per leaf.The numbers are written up in
concepts/plan.mdunder "What a plan costs".Query pruning
New guide,
guide/querying.md, built from plans measured on PostgreSQL 17 against twelve leaves (three months × four buckets): what each partitioning method prunes on, why an expression over the key prunes nothing, when pruning moves to executor start (Subplans Removed), how to build a predicate in an encoded key's own type, and why a local calendar makes a UTC-day predicate span two partitions. One measurement corrected a common assumption: a naiveTIMESTAMPliteral against atimestamptzkey does prune, just at executor start rather than at planning time. The same tables are added to the verified-semantics page, together with the Berlin day.Final report
design/final-report.mdanswers the questions the research set out with, in one place: what the ten systems do, which abstractions that forced, what changed in the codebase, the public API before and after, what was measured rather than assumed, a per-project migration matrix (what each wrote itself → what replaces it → what stays application code), what is deliberately not covered, and what looks worth doing next.Checks
ruff check,ruff format --check,mypyclean; 2 444 unit tests pass; the touched integration module passes in both the aio and sync mirrors. The docs site builds locally (39 pages) — worth noting because the Docs workflow only runs onmaster, so a broken nav entry would not surface on this PR.