Repository navigation
feat!: read a hypertable through a time bound - #39
Open
systemfsoftware-bot wants to merge 3 commits into
Open
systemfsoftware-bot wants to merge 3 commits into
systemfsoftware-bot wants to merge 3 commits into
Conversation
hypertable() returns a declaration that is not a Drizzle table, so
db.select().from(hypertable) does not compile. within({ gte, lt }) returns a
Drizzle subquery with the time bound written into it, latest() finds the newest
row with probes that widen from the chunk interval, and unsafeUnbounded()
returns the plain table for migrations and admin code. A continuous aggregate
declared over a view with a bucketColumn gets the same within.
BREAKING CHANGE: the table property of a hypertable and the view property of a
continuous aggregate are no longer public.
…d probe only one minute past now
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.
A query on a hypertable that names no time range plans every chunk and takes an
AccessShareLockon each chunk and its indexes. At a few thousand chunks, oneORDER BY time DESC LIMIT 1exhaustsmax_locks_per_transaction(SQLSTATE 53200). This makes the bounded read the only read the types allow.API
within({ gte, lt })returns a DrizzleSubquery, not a pre-filtered builder: chaining.where()on a builder replaces the earlier one, so a caller could erase the bound.Datebounds are written astimestamptzliterals, not$n, so chunk exclusion is plan-time even in a generic prepared plan; a column/table/subquery bound is refused (type and runtime). The generated SQL:select "time", "v" from (select "time", "v" from "m" where (("m"."time" >= '2026-01-01T00:00:00.000Z'::timestamptz) and ("m"."time" < '2026-01-02T00:00:00.000Z'::timestamptz))) "m"latestprobes[until-2i, until)first (untildefaults to one minute past now), then windows four times wider going back, up tomaxLookbackChunksintervals in total (iischunkTimeInterval, 7 days when unset). With a 14-day interval the captured probes span 28, 112 and 448 days, newest first. A steady-state caller finds its row on the first probe. The result is tagged so "nothing recent" is not confused with "nothing".unsafeUnbounded()is the named escape hatch an app can ban with a lint rule.continuousAggregate(view, { bucketColumn })gives an aggregate the samewithinandunsafeUnbounded. A continuous aggregate's materialization is a hypertable, so an unbounded read locks all of its chunks too. An aggregate declared withoutbucketColumn, or by name, has nowithin.tableand the aggregate'svieware no longer public properties (breaking).The compiler is the evidence (final diff)
Scratch file importing the package source, removed after the run:
tscreports exactly two errors, on lines 6 and 9:Limit
The types guard what the app imports. The app still has to export the Drizzle table for drizzle-kit, and
db.select().from(thatTable)compiles. Keep the table in a schema module and import only the hypertable in application code, and banunsafeUnboundedoutside migrations.Review
Gemini adversarial review found five P0s; fixed: literal Date bounds (plan-time exclusion), column bounds refused, per-bound validation, finite-range checks in
latest,latestaccepts any drizzle db. A continuous aggregate must be declared over.existing()views (as before);.as()-built views are not supported bybucketColumn.P1s from the review that were not taken: single-query shortcut when
whereis absent (the first probe already hits in steady state), interval parsing (intervals are validated toN unitform before they reach it), and exporting the internal relation accessors.