Skip to content

perf: group INSERT split tuples by shard - #1864

Merged
jkaczman merged 3 commits into
mainfrom
jk-insert-split-by-shard
Oct 21, 2026
Merged

jkaczman merged 3 commits into
mainfrom
jk-insert-split-by-shard

Conversation

@jkaczman

Copy link
Copy Markdown
Contributor

If we have a query we're re-writing for INSERT split that has multiple tuples that resolve to the same shard, this now groups those into a singular query, as opposed to the previous code always splitting each individual tuple into its own statement. This should produce massive speedup for large splits.

Motivated by subqueries, where we'll have cases like INSERT INTO .. SELECT FROM generate_series(..), which will be passed through here and involve massive amount of data.

Future work here will be figuring out how to handle those massive cases further, e.g., we'll need to impose a per-query limit of how much we batch depending on Postgres's limits (w.r.t bind parameters and query sizes). Also, need to figure out a good way to pass the evaluated subquery data rows and row description into the Query Engine without re-writing the top-level statement when we have an INSERT split, so that we don't have to put together unnecessary intermediate string(s), which will just be re-written again to be split apart by INSERT split.

Fixes #1818.

@jkaczman
jkaczman added this pull request to stack #1863 October 20, 2026 20:44
@jkaczman
jkaczman force-pushed the jk-insert-split-by-shard branch from d67b1a3 to 8b9cb46 Compare October 21, 2026 01:56
Base automatically changed from jk-subquery-routing-assertions to main October 21, 2026 03:57
@jkaczman
jkaczman force-pushed the jk-insert-split-by-shard branch from 8b9cb46 to 141368c Compare October 21, 2026 03:57
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.60479% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...frontend/router/parser/rewrite/statement/insert.rs 97.22% 3 Missing ⚠️
...uter/parser/rewrite/statement/insert_split_plan.rs 97.43% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectPgDog
Branchjk-insert-split-by-shard
TestbedIntel v1

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectPgDog
Branchjk-insert-split-by-shard
TestbedIntel v1
Click to view all benchmark results
BenchmarkThroughputBenchmark Result
operations / second (ops/s) x 1e3
(Result Δ%)
Lower Boundary
operations / second (ops/s) x 1e3
(Limit %)
cpu-per-txnBenchmark Result
Measure (units)
(Result Δ%)
Upper Boundary
Measure (units)
(Limit %)
pooler-v2📈 view plot
🚷 view threshold
29.21 ops/s x 1e3
(-0.36%)Baseline: 29.31 ops/s x 1e3
29.02 ops/s x 1e3
(99.36%)
📈 view plot
🚷 view threshold
34.25 units
(+0.36%)Baseline: 34.13 units
34.47 units
(99.37%)
🐰 View full continuous benchmarking report in Bencher

@jkaczman
jkaczman merged commit 8c4dc49 into main Oct 21, 2026
50 checks passed
@jkaczman
jkaczman deleted the jk-insert-split-by-shard branch October 21, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor INSERT split to batch multiple INSERT tuples based on shard routing

1 participant