Repository navigation
fix(cubesql): Handle array-typed columns in streaming SQL mode - #11149
Conversation
Signed-off-by: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com>
|
Claude finished @MazterQyou's task in 1m 34s —— View job Claude PR ReviewReviewed the four-file change. Overall this is a focused, well-scoped fix that brings streaming-mode behavior in line with the non-streaming path (both now JSON-stringify non-scalar values) and is backed by a unit test in Verdict: LGTM — 0 high, 1 medium, 2 low. DetailsFindingsMedium — In Low —
Low —
Notes / Praise
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #11149 +/- ##
==========================================
- Coverage 83.68% 79.20% -4.49%
==========================================
Files 257 474 +217
Lines 79384 96934 +17550
Branches 0 3563 +3563
==========================================
+ Hits 66434 76774 +10340
- Misses 12950 19642 +6692
- Partials 0 518 +518
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:
|
…11586) `loadUserDefinedTypes` built its oid -> typname map with a reduce that spread the accumulator on every row, copying the whole map n times. That is quadratic and fully synchronous, so it blocks the event loop. This went unnoticed while the query only selected `typcategory in ('U', 'E')` (~20 rows on a stock Postgres). #11149 added `'A'` so that array-typed columns get mapped, and Postgres auto-creates an array type for every relation — the row count now scales with the number of tables in the database, not with the number of actual user defined types. Measured on postgres:16, `SELECT count(*) FROM pg_type WHERE typcategory in ('U', 'E', 'A')`: | tables in database | rows | spread reduce | in-place loop | | ------------------ | ---- | ------------- | ------------- | | 0 | 313 | 6.3 ms | 0.12 ms | | 5000 | 5313 | 2355 ms | 0.45 ms | | ~20000 | - | 35116 ms | 1.10 ms |
…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>
…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>
…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>
…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 |
…11586) `loadUserDefinedTypes` built its oid -> typname map with a reduce that spread the accumulator on every row, copying the whole map n times. That is quadratic and fully synchronous, so it blocks the event loop. This went unnoticed while the query only selected `typcategory in ('U', 'E')` (~20 rows on a stock Postgres). #11149 added `'A'` so that array-typed columns get mapped, and Postgres auto-creates an array type for every relation — the row count now scales with the number of tables in the database, not with the number of actual user defined types. Measured on postgres:16, `SELECT count(*) FROM pg_type WHERE typcategory in ('U', 'E', 'A')`: | tables in database | rows | spread reduce | in-place loop | | ------------------ | ---- | ------------- | ------------- | | 0 | 313 | 6.3 ms | 0.12 ms | | 5000 | 5313 | 2355 ms | 0.45 ms | | ~20000 | - | 35116 ms | 1.10 ms |
…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
This PR fixes handling array-typed columns in streaming mode. Related test is included.
This behavior is not documented and unsupported, so it should not be relied upon. The fix is being landed to bring streaming and non-streaming modes in line.