Repository navigation
fix!: one shape for a column ref, and the adapter sends only what the server can read - #65
Merged
Merged
Conversation
…to__ column assertSyncCompatible read the table's columns with pragma_table_info, which does not list generated columns. A generated column named rowid passed the shadow check, and its probe `SELECT rowid` succeeded, so the default ORDER BY rowid sorted by the generated value. It now reads pragma_table_xinfo. A column named __proto__ cannot be carried on a row object: workerd sets each column on a plain object, so that name sets the row's prototype (to null for a NULL) instead of becoming a key. No snapshot or delta holds the column, and SQL can match on it where the evaluator reads the prototype. Such a table is now refused at registerSync. BREAKING CHANGE: registerSync now throws for a table with a generated column named rowid, or a column named __proto__. Both used to register. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… SQL
The compiler read a ref's path[0] in `where`, and the last path element in
`orderBy`, and ignored every other field. The evaluator reads the whole
ref: on @tanstack/db 1.0 it drops path[0] when it equals sourceAlias, and
it walks a longer path into the value. So a hand built ref with
sourceAlias, or an orderBy path of two elements, gave a snapshot that the
deltas, and the client's own order, disagreed with.
A ref in `where`, `orderBy` and a cursor must now be exactly
{ type: "ref", path: [name] }, which is what the library's client sends
on 0.8.6, 0.9.2 and 1.0.0-rc.1.5 (measured through the adapter). Any
other shape is refused like a query off the floor: reset, an empty page,
or a rejected readSyncSnapshot.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… refused tables
ADR-0013: a ref is read only when it is exactly { type: "ref", path: [name] },
the shape the library's client sends on 0.8.6, 0.9.2 and 1.0.0-rc.1.5, in
`where`, `orderBy` and a cursor alike. Records what was measured, the rule,
and what else it refuses.
ADR-0007: registerSync refuses a generated column named rowid and a column
named __proto__, and says why each is a fault of the table.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e subset On @tanstack/db 0.8.6 an orderBy pushed through a subquery or a join reaches the source collection with refs such as ["sub", "body"] or ["f", "name"], and every version sends a nested field as a longer path. The server refuses those refs, since it cannot tell which of them sorting by the last element would get right, so such a live query read as no rows. On main the first of them worked. An orderBy and a limit only let the server send fewer rows; the client sorts and cuts what it holds. So when a term is not a column ref in the one shape the server reads, the on-demand adapter now asks for the whole `where` subset instead: no orderBy, limit or offset, and for a load more no cursor. The decision is made once at the top of loadSubset, so the request key, the watch, the covered fetch and the SSR read all agree. The rule moves to src/wire/column-ref.ts (columnRefProblem), shared by the compiler and the adapter. tests/client-ref-shapes.test.ts runs a fixed list of query shapes through the real adapter and Durable Object and records, per version line, the refs core asks for; it checks that no refused ref reaches the wire and that each query ends ready with the rows @tanstack/db gives over the same data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An orderBy term of null, a function with no args, and a function named after an Object.prototype member (`name in COMPARATORS` followed the prototype chain and wrote broken SQL) threw from compileSubsetQuery, so a sub or a fetch got no reply and stayed loading. A function whose args is a map with `length` compiled, while the evaluator throws on it. Each is now an UnsupportedPredicateError: reset, an empty page, or a rejected readSyncSnapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The __proto__ check compares the name exactly, as a row's keys are; a case-insensitive compare passed every test before this one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ADR-0023 amendment: an orderBy the server cannot sort by is not sent; where the decision is made, how the watch and cover rules treat the unbounded request, what a later cursor or tie request does, the shared rule, and the cost. ADR-0013 amendment (unmerged, corrected): what the client sends now includes the three 0.8.6 shapes, the rule lives in src/wire/column-ref.ts, and the four frames that threw are refused. ADR-0007 amendment (unmerged, corrected): a generated rowid breaks only reads with no orderBy; registerSync throws on every wake and fails the whole object, and the column must be renamed in a migration before it. README: the refused table shapes in the schema note, the cost of an orderBy the server cannot sort by beside the other ordering notes, and a where on a nested field under known limitations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On 0.9 and later a limited query ordered by a nested field also makes a tie request whose `where` holds the nested path. The server refuses it: on the socket an empty page and an error line, in a server render a thrown read, so preload() rejected and the query ended in `error`. A standalone `where` on a nested field read as no rows. The adapter now sends the tightest request the server can read that holds every row core asked for. A top-level conjunct holding a ref that fails columnRefProblem is dropped; any other node holding one is dropped whole as its conjunct, so nothing is widened inside an `or` or a `not`. A widened request also drops its orderBy and limit. The client filters, sorts and cuts the rows it holds. The tie request widens to the base `where`, which shares the acquisition and sends no frame. A cursor request whose covering watch was opened with no limit and has its snapshot already holds every row it asks for, so it sends nothing. tests/client-ref-shapes.test.ts adds `where` shapes (a nested field alone and inside an `and`, an `or` and a `not`), a server render of every shape through SsrSnapshotTransport and readSyncSnapshot, and pins that a rewritten request is shared and released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o fetch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An orderBy term holding a bigint and no usable expression or col made JSON.stringify in the error message throw, so a sub or a fetch got no reply. An orderBy that is not an array was ignored without a word, and with a limit returned the first rows by rowid. Both are refused now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RENAME COLUMN works on a generated rowid (virtual or stored) and on a __proto__ column (plain or generated) with rows, and the table then registers. Dropping a STORED column and adding it back fails on a table with rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ADR-0023 amendment (unmerged, rewritten): the adapter sends the tightest request the server can read; where the widening is applied, what the watch's where is, how key and cover treat a widened request, what a cursor request does (and when it sends nothing), the cost, and the 0.8.x subquery the rule cannot see. ADR-0013 amendment (unmerged, corrected): the tie request, the where widening, and what each of the six malformed frames did. ADR-0007 amendment (unmerged, corrected): RENAME COLUMN for every case; dropping and adding a stored generated column fails on a table with rows. README: the ordering note covers a where and a server render, the limits state the cost and the 0.8.x subquery that orders by the wrong column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… server can read
Merges the column reference change. The server reads a ref only when it is
exactly { type: "ref", path: [name] }, and refuses a table with a generated
column named rowid or a column named __proto__. The on-demand adapter drops an
orderBy the server cannot sort by and the conjuncts of a where it cannot read,
and asks for the rest. Adds the changelog entries and the wording the last
review asked for.
BREAKING CHANGE: registerSync throws for a table with a generated column named
rowid or a column named __proto__.
Co-Authored-By: Claude Fable 5.2 <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.
The SQL that builds a snapshot and the client's evaluator that decides the deltas must read the same column, or the client holds wrong rows. The review of the missing column fix (#63) found four ways to break that on main. Fixing them on the server exposed a query shape the library's own client sends, so this change also teaches the on-demand adapter to send only what the server can read.
The server
{ type: "ref", path: [name] }, inwhere,orderByand both halves of a cursor. A hand built ref withsourceAliasor another field, or a path of more than one element, is refused like an operator off the floor. Before,orderBytook the last element of a path whilewhererequired exactly one, and the 1.0 evaluator read a ref withsourceAliasdifferently from the SQL.registerSyncrefuses two table shapes. A generated column namedrowidpassed the compatibility check and then shadowed the default row order. A column named__proto__cannot be carried on a row object.The client
On
@tanstack/db0.8.6 the client sends a two elementorderBypath for an ordinary query: a subquery withorderByandlimit. Main sorted it by the last element, which happened to be right. The strict server rule refused it, and the live query ended ready with no rows. The server cannot tell that path from a nested field or another table's column, where the last element is wrong.So the on-demand adapter now sends a request the server can read that contains the one core asked for:
orderBythe server cannot sort by is dropped, with itslimit;wherethat the server cannot read is dropped, and the rest is sent. Nothing is widened inside anot.The client filters, sorts and cuts the rows it holds, so the query is right. One rule in
src/wire/column-ref.tsis used by the compiler and the adapter.Effects:
orderByor awhereon a nested field, which was refused and read as no results, now works on the socket and in a server render, on every version.Breaking change
registerSyncthrows for a table with a generated column namedrowidor a column named__proto__. It runs in the constructor on every wake, so the whole object fails. Rename the column withALTER TABLE … RENAME COLUMNin a migration that runs beforeregisterSync. Do not drop a stored generated column and add it back; that fails on a table with rows.Costs to know
wherematches, however small itslimit. Awhereon a nested field alone loads the whole collection, which then stays loaded while any other query on that collection is mounted.whereis not widened. On a nested field it is still refused.Verification
tests/client-ref-shapes.test.tsruns live queries through the real adapter and Durable Object, on the socket and in a server render, and compares each with@tanstack/db's own answer over local rows. It also writes down the ref shapes each version line sends, so the weekly job against the newest release fails when core sends another shape.whereand failed a server render. Round three ran 40,000 randomwhereshapes per version (none sent narrower than asked) and a mutant of every adapter rule (each fails a test). Verdict: mergeable.Not pinned by a test: the key order of a rebuilt
and(a wrong order costs one extra fetch, no wrong rows), and dehydrate then hydrate for the widened shapes (the reviewer ran it by hand and it converged).The decisions are dated amendments to ADR-0013, ADR-0023 and ADR-0007.
🤖 Generated with Claude Code