Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions integration/rust/tests/integration/subqueries/tests/insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ INSERT INTO subpackages (id, user_id) SELECT id, id FROM subusers ORDER BY id DE
-- verify: SELECT * FROM subpackages ORDER BY id
INSERT INTO subpackages (id, user_id, order_id) SELECT suborders.id, suborders.user_id, suborders.id FROM suborders JOIN subusers ON suborders.user_id = subusers.id

-- case
-- what: INSERT INTO .. SELECT .. JOIN on suborders.id = subusers.id (the sharding key of suborders is user_id, not id)
-- route select: 0,1
-- sql: SELECT * FROM subusers u
-- route select: 0,1
-- sql: SELECT o.id, u.id FROM suborders o JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) u(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON o.id = u.id
-- route insert: 0,1
-- sql: INSERT INTO subpackages (id, user_id) SELECT u.c1, u.c2 FROM unnest($1::pg_catalog._int8, $2::pg_catalog._int8) u(c1, c2)
-- verify: SELECT * FROM subpackages ORDER BY id
INSERT INTO subpackages (id, user_id) SELECT o.id, u.id FROM suborders o JOIN subusers u ON o.id = u.id

-- case
-- what: WITH a AS (..), b AS (SELECT .. FROM a) INSERT .. FROM a JOIN b .., one CTE over another
-- route select: 0,1
Expand Down
187 changes: 187 additions & 0 deletions integration/rust/tests/integration/subqueries/tests/select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ SELECT COUNT(*) FROM (SELECT 1 AS one FROM subusers WHERE status = 'VIP' LIMIT 4
-- sql: SELECT count(*) FROM (SELECT 1 FROM unnest($1::pg_catalog._int4) u(c1)) subquery_for_count(one) WHERE false
SELECT COUNT(*) FROM (SELECT 1 AS one FROM subusers WHERE status = 'nobody' LIMIT 40) subquery_for_count;

-- case
-- what: .. WHERE <col> IN (<sq>), <sq> returns an error
-- route select: 0,1
-- sql: SELECT 1 / 0 FROM subusers
SELECT * FROM subusers WHERE id IN (SELECT 1 / 0 FROM subusers);

-- case
-- what: Derived table with an inner-table that returns an empty response.
-- Want to make sure that the OIDs returned are correct (if present)
Expand Down Expand Up @@ -302,3 +308,184 @@ WITH a AS (
WITH a AS (
SELECT id, status FROM subusers
) SELECT x.id, y.id FROM a x JOIN a y ON x.status = y.status ORDER BY x.id, y.id;

-- case
-- what: .. FROM subusers u JOIN suborders o ON u.id = o.user_id (the sharding keys of both tables)
-- used by: Mastodon, which joins accounts to users with Account.joins(:user) on accounts.id = users.account_id
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/lib/feed_manager.rb#L21
-- route select: 0,1
-- sql: SELECT u.id, u.username, o.id AS order_id FROM subusers u JOIN suborders o ON u.id = o.user_id ORDER BY o.id
SELECT u.id, u.username, o.id AS order_id FROM subusers u
JOIN suborders o ON u.id = o.user_id
ORDER BY o.id;

-- case
-- what: JOIN on suborders.id = subusers.id (the sharding key of suborders is user_id, not id)
-- used by: Mastodon, which joins notifications to the accounts that sent the notifications on accounts.id = notifications.from_account_id
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/models/notification.rb#L108
-- route select: 0,1
-- sql: SELECT * FROM subusers u
-- route select: 0,1
-- sql: SELECT o.id, o.user_id, u.username FROM suborders o JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) u(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON o.id = u.id ORDER BY o.id
SELECT o.id, o.user_id, u.username FROM suborders o
JOIN subusers u ON o.id = u.id
ORDER BY o.id;

-- case
-- what: JOIN on x.status = y.status (the sharding key of subusers is id)
-- used by: Mastodon, which joins follows to the followed accounts on follows.target_account_id = target_accounts.id to suggest accounts to follow
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/models/account_suggestions/friends_of_friends_source.rb#L14
-- route select: 0,1
-- sql: SELECT * FROM subusers y
-- route select: 0,1
-- sql: SELECT x.id, y.id, x.id AS __pgdog_order_col0, y.id AS __pgdog_order_col1 FROM subusers x JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) y(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON x.status = y.status ORDER BY x.id, y.id
SELECT x.id, y.id FROM subusers x
JOIN subusers y ON x.status = y.status
ORDER BY x.id, y.id;

-- case
-- what: LEFT JOIN on x.status = y.status (the sharding key of subusers is id)
-- used by: Mastodon, which LEFT JOINs accounts to follows on follows.target_account_id = accounts.id to show admins the most followed accounts of a server
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/lib/admin/metrics/dimension/instance_accounts_dimension.rb#L27-L33
-- route select: 0,1
-- sql: SELECT * FROM subusers y
-- route select: 0,1
-- sql: SELECT x.id, y.id, x.id AS __pgdog_order_col0, y.id AS __pgdog_order_col1 FROM subusers x LEFT JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) y(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON x.status = y.status ORDER BY x.id, y.id
SELECT x.id, y.id FROM subusers x
LEFT JOIN subusers y ON x.status = y.status
ORDER BY x.id, y.id;

-- case
-- what: .. FROM subusers x CROSS JOIN subusers y
-- used by: not Mastodon or Rails, but CROSS JOIN was free to add, since Postgres parses CROSS JOIN as an inner JOIN without an ON clause
-- route select: 0,1
-- sql: SELECT * FROM subusers y
-- route select: 0,1
-- sql: SELECT x.id, y.id FROM subusers x CROSS JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) y(id, username, status, profile, signed_up, last_ip, tags, media_ids) ORDER BY 1, 2
SELECT x.id, y.id FROM subusers x
CROSS JOIN subusers y
ORDER BY 1, 2;

-- case
-- what: .. FROM suborders o NATURAL JOIN subusers u (id is the only shared column between the two tables)
-- used by: not Mastodon or Rails, but NATURAL JOIN was free to add, since Postgres parses NATURAL JOIN as an inner JOIN on the shared columns between the two tables
-- route select: 0,1
-- sql: SELECT * FROM subusers u
-- route select: 0,1
-- sql: SELECT o.id, u.username FROM suborders o NATURAL JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) u(id, username, status, profile, signed_up, last_ip, tags, media_ids) ORDER BY 1
SELECT o.id, u.username FROM suborders o
NATURAL JOIN subusers u
ORDER BY 1;

-- case
-- what: .. FROM suborders o JOIN substates s ON s.state = o.state (substates isn't sharded)
-- used by: Mastodon, which joins statuses to oauth_applications to find the apps that users post with the most
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/lib/annual_report/most_used_apps.rb#L20
-- route select: 0,1
-- sql: SELECT o.id, s.shipping FROM suborders o JOIN substates s ON s.state = o.state ORDER BY o.id
SELECT o.id, s.shipping FROM suborders o
JOIN substates s ON s.state = o.state
ORDER BY o.id;

-- case
-- what: .. FROM "suborders" INNER JOIN "subusers" ON "subusers"."id" = "suborders"."id" (without an alias)
-- used by: Mastodon, which leaves out the notifications from suspended accounts with Notification.without_suspended, i.e., joins(:from_account), which Rails writes without an alias
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/models/notification.rb#L108
-- route select: 0,1
-- sql: SELECT * FROM subusers
-- route select: 0,1
-- sql: SELECT suborders.id, subusers.username FROM suborders JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) subusers(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON subusers.id = suborders.id ORDER BY suborders.id
SELECT "suborders"."id", "subusers"."username" FROM "suborders"
INNER JOIN "subusers" ON "subusers"."id" = "suborders"."id"
ORDER BY "suborders"."id";

-- case
-- what: .. FROM suborders JOIN subusers ON .. WHERE subusers.id = 3
-- We use the name subusers as the alias of the fetched rows, so subusers.id = 3 refers to the fetched rows, not to the table subusers
-- The router doesn't route by subusers.id = 3, since the fetched rows are a derived table (#2064)
-- route select: 0,1
-- sql: SELECT * FROM subusers
-- route select: 0,1
-- sql: SELECT suborders.id, subusers.id FROM suborders JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) subusers(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON subusers.id = suborders.id WHERE subusers.id = 3
SELECT "suborders"."id", "subusers"."id" FROM "suborders"
INNER JOIN "subusers" ON "subusers"."id" = "suborders"."id"
WHERE "subusers"."id" = 3;

-- case
-- what: .. FROM "subusers" LEFT OUTER JOIN "suborders" ON "suborders"."id" = "subusers"."id" (without an alias)
-- used by: Mastodon, which LEFT JOINs statuses to mentions with account.statuses.left_outer_joins(:mentions) to list the posts of other accounts without boosts (exclude_reblogs=true)
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/lib/account_statuses_filter.rb#L49
-- route select: 0,1
-- sql: SELECT * FROM suborders
-- route select: 0,1
-- sql: SELECT subusers.id, suborders.id FROM subusers LEFT JOIN (SELECT u.c1, u.c2, u.c3, u.c4 FROM unnest($1::pg_catalog._int8, $2::pg_catalog._int8, $3::pg_catalog._text, $4::pg_catalog._timestamptz) u(c1, c2, c3, c4)) suborders(id, user_id, state, created_at) ON suborders.id = subusers.id ORDER BY 1, 2
SELECT "subusers"."id", "suborders"."id" FROM "subusers"
LEFT OUTER JOIN "suborders" ON "suborders"."id" = "subusers"."id"
ORDER BY 1, 2;

-- case
-- what: .. FROM suborders JOIN subusers ON .. WHERE suborders.id IN (SELECT .. FROM subusers ..)
-- We rewrite this statement twice (first the subquery in WHERE, then the JOIN)
-- Without the `|=` in `send_query_string`, simple-protocol clients would receive ParseComplete and BindComplete before the rows
-- route select: 0,1
-- sql: SELECT subusers.id FROM subusers WHERE subusers.status = 'VIP'
-- route select: 0,1
-- sql: SELECT * FROM subusers
-- route select: 0,1
-- sql: SELECT suborders.id FROM suborders JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($8::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($11::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($2::pg_catalog._int8, $3::pg_catalog._text, $4::pg_catalog._text, $5::pg_catalog._jsonb, $6::pg_catalog._date, $7::pg_catalog._inet, $9::pg_catalog._int4, $10::pg_catalog._int4, $12::pg_catalog._int4, $13::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) subusers(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON subusers.id = suborders.id WHERE suborders.id IN (SELECT u.c1 FROM unnest($1::pg_catalog._int8) u(c1)) ORDER BY 1
SELECT "suborders"."id" FROM "suborders"
INNER JOIN "subusers" ON "subusers"."id" = "suborders"."id"
WHERE "suborders"."id" IN (SELECT "subusers"."id" FROM "subusers" WHERE "subusers"."status" = 'VIP')
ORDER BY 1;

-- case
-- what: .. FROM suborders o JOIN subusers u ON .. WHERE o.user_id = 2 (o.user_id is the sharding key of suborders)
-- used by: Mastodon, which lists the notifications of the current account with current_account.notifications.without_suspended (WHERE notifications.account_id = ..)
-- - https://github.com/mastodon/mastodon/blob/v4.3.0/app/controllers/api/v1/notifications_controller.rb#L59
-- route select: 0,1
-- sql: SELECT * FROM subusers u
-- route select: 0
-- sql: SELECT o.id, u.id FROM suborders o JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($7::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($10::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($1::pg_catalog._int8, $2::pg_catalog._text, $3::pg_catalog._text, $4::pg_catalog._jsonb, $5::pg_catalog._date, $6::pg_catalog._inet, $8::pg_catalog._int4, $9::pg_catalog._int4, $11::pg_catalog._int4, $12::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) u(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON u.id = o.id WHERE o.user_id = 2 ORDER BY 1, 2
SELECT o.id, u.id FROM suborders o
JOIN subusers u ON u.id = o.id
WHERE o.user_id = 2
ORDER BY 1, 2;

-- case
-- what: .. FROM subusers x LEFT JOIN subpackages y ON x.id = y.order_id (subpackages doesn't have any rows)
-- We send empty unnest(..) arrays in place of subpackages y
-- route select: 0,1
-- sql: SELECT * FROM subpackages y
-- route select: 0,1
-- sql: SELECT x.id, y.id FROM subusers x LEFT JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5 FROM unnest($1::pg_catalog._int8, $2::pg_catalog._int8, $3::pg_catalog._int8, $4::pg_catalog._timestamptz, $5::pg_catalog._timestamptz) u(c1, c2, c3, c4, c5)) y(id, user_id, order_id, shipped_at, estimated_arrival_time) ON x.id = y.order_id ORDER BY 1, 2
SELECT x.id, y.id FROM subusers x
LEFT JOIN subpackages y ON x.id = y.order_id
ORDER BY 1, 2;

-- case
-- what: JOIN on x.status = y.status with parameters in ON and WHERE
-- route select: 0,1
-- sql: SELECT * FROM subusers y
-- route select: 0
-- sql: SELECT x.id, y.id FROM subusers x JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($9::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($12::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($3::pg_catalog._int8, $4::pg_catalog._text, $5::pg_catalog._text, $6::pg_catalog._jsonb, $7::pg_catalog._date, $8::pg_catalog._inet, $10::pg_catalog._int4, $11::pg_catalog._int4, $13::pg_catalog._int4, $14::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) y(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON x.status = y.status AND y.username <> $2 WHERE x.id = $1 ORDER BY 1, 2
-- $1 = 1
-- $2 = nobody
SELECT x.id, y.id FROM subusers x
JOIN subusers y ON x.status = y.status AND y.username <> $2
WHERE x.id = $1
ORDER BY 1, 2;

-- case
-- what: .. WHERE id <= $1 AND id IN (SELECT .. FROM suborders o JOIN subusers u ON .. WHERE o.id >= $2)
-- route select: 0,1
-- sql: SELECT * FROM subusers u
-- route select: 0,1
-- sql: SELECT u.id FROM suborders o JOIN (SELECT u.c1, u.c2, u.c3, u.c4, u.c5, u.c6, ($8::pg_catalog._varchar)[u.c7 + 1:u.c7 + u.c8], ($11::pg_catalog._int8)[u.c9 + 1:u.c9 + u.c10] FROM unnest($2::pg_catalog._int8, $3::pg_catalog._text, $4::pg_catalog._text, $5::pg_catalog._jsonb, $6::pg_catalog._date, $7::pg_catalog._inet, $9::pg_catalog._int4, $10::pg_catalog._int4, $12::pg_catalog._int4, $13::pg_catalog._int4) u(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)) u(id, username, status, profile, signed_up, last_ip, tags, media_ids) ON o.id = u.id WHERE o.id >= $1
-- route select: 0,1
-- sql: SELECT id FROM subusers WHERE id <= $1 AND id IN (SELECT u.c1 FROM unnest($2::pg_catalog._int8) u(c1)) ORDER BY id
-- $1 = 3
-- $2 = 2
SELECT id FROM subusers
WHERE id <= $1 AND id IN (SELECT u.id FROM suborders o JOIN subusers u ON o.id = u.id WHERE o.id >= $2)
ORDER BY id;

6 changes: 3 additions & 3 deletions integration/rust/tests/integration/subqueries/todo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@
-- relevant to subqueries
--
-- Sharding key on one side only
-- [A1] [select] .. FROM <st1> JOIN <st2> ON <st1>.<col> = <st2>.<key>
-- [DONE] [A1] [select] .. FROM <st1> JOIN <st2> ON <st1>.<col> = <st2>.<key>
-- condition: <col> has sharding key values of rows on other shards
-- [A1 A2 A3 A4 Q5] [insert] INSERT INTO <st1> SELECT .. FROM <st2> JOIN .. ON ..
-- [DONE] [A1 A2 A3 A4 Q5] [insert] INSERT INTO <st1> SELECT .. FROM <st2> JOIN .. ON ..
-- relevant to subqueries
-- case: co-located on the key
-- case: key on one side only

-- Sharding key on neither side
-- [A1] [select] .. FROM <st1> <join> <st2> ON <st1>.<col> = <st2>.<col>
-- [DONE] [A1] [select] .. FROM <st1> <join> <st2> ON <st1>.<col> = <st2>.<col>
-- case: <join> = JOIN
-- case: <join> = LEFT JOIN

Expand Down
7 changes: 7 additions & 0 deletions pgdog/src/frontend/client/query_engine/multi_step/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub(crate) async fn fetch_rows(
.await?;

let mut row_description = None;
// TODO(jkaczman): We should return an error if `data_rows` grows past a limit well below 1 GB (e.g., 100 MB) to ensure that we don't run out of memory
// Currently, we keep all fetched rows in memory, then send the rows to the shards in Bind msg, which Postgres will reject if it's over 1 GB
//
// PERF(jkaczman): We could remove the intermediate Vec `data_rows`, and instead copy the rows directly into the unnest(..) arrays as we read them to avoid extra allocations
// Currently, we allocate a DataRow in `data_rows` per row that we read
// We then copy all of the rows into the arrays when we do the subquery rewrite in `new_select_with_unnest`
// Based on some rudimentary benchmarking I did, this would remove roughly 35% of instructions corresponding to the JOIN overhead
let mut data_rows = Vec::new();
let mut error = None;

Expand Down
Loading
Loading