You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1e61bf8
Browse filesBrowse the repository at this point in the historyBrowse files
fix(driver-sql): a savepoint derived from the caller's transaction reaches its key-type reading (ADR-0155 D-0, O2)
updateMany on an object whose updated_at is only presumed issues its
stamped attempt in a savepoint attemptWithoutPoisoning opens on the
caller's transaction, so the leaf compiled under a transaction object the
door never primed under and was refused (500) on every write, text keys
included. The lookup and the prime now walk knex's parentTransaction
chain: a savepoint sees what its parent sees, so the parent's reading
holds there; a savepoint's own reading never reaches its parent.
Live PG pin: on a fresh driver, a managed object in the presumed
updated_at state, text and character(4) keys, a predicate updateMany with
the write-form leaf in a caller transaction answers the list's rows and
touches them. The changeset, the anchor and the prime's docblock say so,
and the docblock names the savepoint's effect on concurrent statements on
the same transaction.
Claude-Session: https://claude.ai/code/session_01L9qibyXo4gSy8DJPNz4ANz
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: .changeset/35906-pg-share-grant-key-type.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ No visible change on its own: nothing writes a `SharedRecordIds` leaf yet. The s
11
11
12
12
-**PostgreSQL, a key that is not text.** The compiled subquery `id IN (SELECT record_id FROM sys_record_share WHERE …)` now projects `record_id` cast to the base type of the column it is compared with: `CAST(NULLIF(record_id, '') AS <type>)`. A federated table keyed by `integer`, `bigint`, `smallint`, `numeric`, `uuid`, `character(n)` or a domain over one of them answers the same rows as the id list of the same grants: `07` names 7, an upper-case or braced uuid names its lower-case twin, and a padded grant names a `character(n)` key. Before, an integer or uuid key failed the statement with `DATABASE_ERROR` (42883), and a `character(n)` key silently missed a padded grant.
13
13
-**A malformed grant id** (`abc` against an integer key) fails the statement with `DATABASE_ERROR` / 500, the same answer the id list gives for it.
14
-
-**How the type is known.** The driver reads the column types of the compared table from `pg_catalog` once, the first time a statement holding the leaf reaches that table, and keeps the answer for the life of the driver. A statement with no leaf reads nothing. A failed or empty catalog read records nothing and is asked again by the next statement.
14
+
-**How the type is known.** The driver reads the column types of the compared table from `pg_catalog` once, the first time a statement holding the leaf reaches that table, and outside a transaction keeps the answer for the life of the driver (inside one, see the next bullet). A statement with no leaf reads nothing. A failed or empty catalog read records nothing and is asked again by the next statement.
15
15
-**No reading, no statement.** On PostgreSQL a statement whose leaf is compared with a table the driver holds no catalog reading of is refused with `INTERNAL_ERROR` / 500 (logged once), and never runs uncast, which on a `character(n)` key would miss a padded grant silently. A table has no reading when the catalog read fails or finds no such relation; nothing is recorded, and the next statement reads the catalog again.
16
-
-**Read where the statement runs.** A statement in the caller's transaction reads the catalog on that transaction's own connection, inside a savepoint: it needs no second pooled connection, it sees a table the transaction created, and a failed read rolls back the savepoint alone, so the caller's transaction stays usable. That reading is kept for that transaction only. A statement outside a transaction reads on the pool and the reading is kept for the life of the driver.
16
+
-**Read where the statement runs.** A statement in the caller's transaction reads the catalog on that transaction's own connection, inside a savepoint: it needs no second pooled connection, it sees a table the transaction created, and a failed read rolls back the savepoint alone, so the caller's transaction stays usable. That reading is kept for that transaction only, and reaches every savepoint derived from it, so a write the driver itself retries in a savepoint (an `updateMany` on an object whose `updated_at` column is only presumed) compiles with it; a reading a savepoint takes never reaches its parent. Each transaction therefore pays one savepoint and one catalog read per table it compares a leaf against. A statement outside a transaction reads on the pool and the reading is kept for the life of the driver.
17
17
-**Unchanged, and what text keys get.** A `text` or `varchar` key, which is every table the platform creates, compiles to exactly step 3's statement, with no cast. What is new for it: the first leaf statement on that table (once per driver, or once per transaction inside one) is preceded by the catalog read, and if that read fails, or finds no such relation, the statement is refused with `INTERNAL_ERROR` / 500 instead of being run. SQLite, MySQL, SQL Server and Oracle compile exactly as before and read no catalog; SQLite answers the list's rows by column affinity. MySQL and SQL Server keys are not measured against a live server yet. An Oracle `RAW(16)` uuid key is expected to fail the statement (ORA-01465, by reading: the subquery converts a dashed uuid grant to `RAW` implicitly, where the id list binds its undashed hex); it is not measured, and is tracked on #35952.
Copy file name to clipboardExpand all lines: scripts/adr-anchors/packages__drivers__driver-sql__src__fixed-read-leaf-key-type.ts.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3,5 +3,5 @@
3
3
"adrs": [
4
4
"ADR-0155"
5
5
],
6
-
"invariant": "ADR-0155 D-0, D2, O2 (ruled A): on PostgreSQL the fixed-read leaf's inner read projects `record_id` cast to the BASE type of the outer key column (a domain resolved to the type under it, no typmod), read once per physical table from the catalog by `primeFixedReadLeafKeyTypes` before the synchronous compile, so an integer, uuid or character(n) key answers the rows today's id list answers and a malformed grant id fails the statement as a list member does. A text or varchar key takes no cast (step 3's statement). \"No reading\" is kept apart from \"read: a text key\": a failed or empty catalog read records nothing, and a leaf compared with a table that has no reading (no door primed it, the catalog read failed or found no relation) or whose type cannot be spelled as one identifier is REFUSED in ADR-0139 D3's envelope (INTERNAL_ERROR / 500, logged once per knex client), never compiled uncast. A door in the caller's transaction reads the catalog on that transaction's connection inside a savepoint (so a held pool cannot time it out, a table the transaction created is read, and a failed read leaves the transaction usable) and keeps that reading for that transaction only; with no transaction it reads on the pool. Every door that compiles a `where` calls the prime beside its other catalog primes, so a door that skips it refuses every leaf; each door is pinned as the first statement of a fresh driver."
6
+
"invariant": "ADR-0155 D-0, D2, O2 (ruled A): on PostgreSQL the fixed-read leaf's inner read projects `record_id` cast to the BASE type of the outer key column (a domain resolved to the type under it, no typmod), read once per physical table from the catalog by `primeFixedReadLeafKeyTypes` before the synchronous compile, so an integer, uuid or character(n) key answers the rows today's id list answers and a malformed grant id fails the statement as a list member does. A text or varchar key takes no cast (step 3's statement). \"No reading\" is kept apart from \"read: a text key\": a failed or empty catalog read records nothing, and a leaf compared with a table that has no reading (no door primed it, the catalog read failed or found no relation) or whose type cannot be spelled as one identifier is REFUSED in ADR-0139 D3's envelope (INTERNAL_ERROR / 500, logged once per knex client), never compiled uncast. A door in the caller's transaction reads the catalog on that transaction's connection inside a savepoint (so a held pool cannot time it out, a table the transaction created is read, and a failed read leaves the transaction usable) and keeps that reading for that transaction and the savepoints derived from it (knex `parentTransaction`, as the presumed-`updated_at` write path's `attemptWithoutPoisoning` opens), never the reverse; with no transaction it reads on the pool. Every door that compiles a `where` calls the prime beside its other catalog primes, so a door that skips it refuses every leaf; each door is pinned as the first statement of a fresh driver."
0 commit comments