Repository navigation
perf(postgres-driver): skip relation array types when loading user defined types - #11587
Conversation
|
Claude finished @ovr's task in 2m 29s —— View job Review complete — approach is sound; 1 medium, 3 low. Main gap: the O(n²) map build behind the reported stall is untouched.Full review (4 inline comments)
SummaryThe diagnosis is correct and the catalog query is right. No security surface here — the query is static with no interpolation, and it runs against catalog tables only. Findings
Not runI did not run |
cf5f17a to
7a9fc13
Compare
|
Claude finished @ovr's task in 2m 8s —— View job Review: approach is sound, one perf gap left on the table — 0 blocking, 1 medium, 3 low (all previously filed, still open)Full review — click to expandTodos
VerdictThe diagnosis is right and the fix is the correct shape. Postgres creates a composite row type plus an array over it for every relation, so FindingsThis is a synchronize re-run on an unchanged tree (
Security: nothing relevant — no user input reaches this SQL, it's a static catalog query. Docs: not required for an internal driver change. Not doneI did not run the driver test suite — it needs Docker/testcontainers ( |
| // | ||
| // Postgres creates a row type for every relation and an array type over it, so | ||
| // selecting all of typcategory = 'A' returns one row per relation in the database. | ||
| // That's why there is a NON EXIST filter. |
There was a problem hiding this comment.
Typo — "NON EXIST" should be NOT EXISTS, and the comment explains what is filtered but not the part a future reader will actually stumble on: why it is safe to drop those oids (relation row-type arrays only appear as a column type for whole-row aggregates, which this driver does not issue) and why relkind <> 'c' is the carve-out (it keeps standalone CREATE TYPE ... AS (...)). Suggest folding the commit-message rationale in here:
| // That's why there is a NON EXIST filter. | |
| // Postgres creates a row type for every relation and an array type over it, so | |
| // selecting all of typcategory = 'A' returns one row per relation in the database, | |
| // which does not scale on deployments with many schemas/tables. The NOT EXISTS | |
| // below drops arrays over relation row types: they can only be the type of a | |
| // column for whole-row aggregates, which this driver never issues. Arrays over a | |
| // standalone CREATE TYPE ... AS (...) have relkind = 'c' and are kept. |
7a9fc13 to
69ab7c8
Compare
|
Claude finished @ovr's task in 1m 1s —— View job Review: approach is sound — 0 blocking, 3 low. Correction: my earlier "medium" (O(n²) map build) was wrong and I've resolved it.Full review — click to expandTodos
VerdictSynchronize re-run on an unchanged tree ( Postgres creates a composite row type plus an array over it for every relation, so Security: nothing relevant — static catalog SQL, no interpolation, no user input. Docs: not required for an internal driver change. Correction to my earlier reviewI previously filed a Medium claiming the Findings — all three previously filed, still unresolved, still applicable at the same lines, so no duplicates posted
Not runI did not run the driver suite — it needs Docker/testcontainers ( |
…fined types #11149 needed array-typed columns to map to `text`, and selected all of `typcategory = 'A'` to get there. Postgres creates a row type and an array over it for every relation, so that selects one row per relation in the database: the map stopped scaling with the types in use and started scaling with the size of the catalog. On a multi tenant deployment with a schema per tenant this reached ~63k rows, and the map build behind it is quadratic. Those relation array types are only ever the type of a column for queries that aggregate whole rows, which this driver does not issue, and a plain composite column is already unsupported since `typcategory = 'C'` has never been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept, they are real user defined types. Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations: | query | rows | | -------------------- | ---- | | typcategory in UEA | 3317 | | this one | 108 | The oids #11149 relies on are unaffected: `_text` 1009 and `_int4` 1007 are still loaded, as are enums, enum arrays and extension types such as hll. CrateDB, which inherits this through CrateDriver, returns the same 24 rows for both queries and supports the correlated NOT EXISTS. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
69ab7c8 to
bc6446c
Compare
|
Claude finished @ovr's task in 43s —— View job Review: approach is sound — 0 blocking, 2 low (both already-filed threads, no duplicates posted)Full review — click to expandTodos
VerdictSynchronize re-run. Tree is functionally identical to what I reviewed at Postgres creates a composite row type plus an array over it for every relation, so The map build at
Security: nothing relevant — static catalog SQL, no interpolation, no user input. Docs: not required for an internal driver change. Findings — both previously filed and still unresolved, so re-affirming rather than duplicating
The test-coverage thread I filed earlier (nothing observes that relation row-type arrays are now excluded; Not runI did not run the driver suite — it needs Docker/testcontainers ( |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #11587 +/- ##
===========================================
- Coverage 84.06% 59.15% -24.91%
===========================================
Files 257 227 -30
Lines 81582 18157 -63425
Branches 0 3672 +3672
===========================================
- Hits 68581 10741 -57840
+ Misses 13001 6868 -6133
- Partials 0 548 +548
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…fined types (#11587) #11149 needed array-typed columns to map to `text`, and selected all of `typcategory = 'A'` to get there. Postgres creates a row type and an array over it for every relation, so that selects one row per relation in the database: the map stopped scaling with the types in use and started scaling with the size of the catalog. Those relation array types are only ever the type of a column for queries that aggregate whole rows, which this driver does not issue, and a plain composite column is already unsupported since `typcategory = 'C'` has never been loaded. Arrays over a standalone `CREATE TYPE ... AS (...)` are kept, they are real user defined types. Measured on postgres:16 with 150 schemas of 20 tables, 3209 relations: | query | rows | | -------------------- | ---- | | typcategory in UEA | 3317 | | this one | 108 |
Check List
Description of Changes Made (if issue reference is not provided)
#11149 made
loadUserDefinedTypesselect all oftypcategory = 'A'so that array-typed columns map totext, but Postgres creates a row type and an array over it for every relation, so that returns one row per relation in the database — on a multi tenant deployment with a schema per tenant this reached ~63k rows, and the quadratic map build behind it blocked the event loop for minutes on every cold driver. Arrays over relation row types are now skipped, which brings the same database down to ~116 rows while leaving everything the driver actually maps in place:_text1009 and_int41007 that #11149 relies on, enums, enum arrays, extension types such as hll, and arrays over a standaloneCREATE TYPE ... AS (...). Verified on postgres:16 (150 schemas of 20 tables: 3317 rows before, 108 after) and on CrateDB 5.10, which inherits this throughCrateDriverand returns the same 24 rows for both queries. Astream (user defined type)test covers both a composite array and a domain column, and it fails withUnable to detect typeif therelkind <> 'c'carve-out is removed.