Skip to content

test: optionally assert SQL sent to shards in subquery test suite - #2039

Open
jkaczman wants to merge 1 commit into
mainfrom
jk-subqueries-test-suite-assert-sql
Open

jkaczman wants to merge 1 commit into
mainfrom
jk-subqueries-test-suite-assert-sql

Conversation

@jkaczman

Copy link
Copy Markdown
Contributor

The subquery test suite runs statements against both us and Postgres, and then compares the responses to ensure exact wire protocol conformity.

Previously, I only opted to support asserting the kind (select, delete, update, etc) of statement and which shards those statements were sent to (e.g., -- route select: 0,1 expecting a select to be sent to both shard 0 and 1). This, however, does not give us the capability to truly ensure queries are being sent as we expect (if for some reason the re-write returned correct rows in our specific test case, but wouldn't otherwise due to being incorrectly rewritten), e.g., fetching subusers with SELECT * vs. with SELECT id, status.

Now, this adds support for an optional -- sql: comment assertion right after a -- route comment assertion.

E.g., if we have a case such as

-- case
-- route select: 0,1
-- sql: SELECT id FROM subusers WHERE status = 'VIP'
-- route select: 0,1
-- sql: SELECT * FROM suborders WHERE id IN (SELECT u.c1 FROM unnest($1::pg_catalog._int8) u(c1)) ORDER BY id
SELECT * FROM suborders WHERE id IN (
    SELECT id FROM subusers WHERE status = 'VIP'
) ORDER BY id;

this is now able to check that both shards run the subquery first, and then that the outer statement is ran with the ids in unnest(..) (as opposed to VALUES, not being re-written at all, etc)

This was fairly easy to add as the route assertions use pg_stat_monitor, and there was pre-existing 'machinery' to get the exact query ran (previously used get the statement type)

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

Metal bench (arm64) passed. All 517 measures within bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 19.19 (-0.7% ± 1.3%) 18,182 (-1.0% ± 0.5%) 31,546 (+0.0% ± 0.05%) 31,006 (-0.6% ± 2.2%) 50,988 (+0.1% ± 0.4%)
lb 19.62 (-0.4% ± 0.9%) 18,886 (+0.1% ± 0.8%) 32,459 (+0.0% ± 0.06%) 31,205 (-0.8% ± 1.8%) 52,214 (+0.1% ± 0.2%)
sharding-w2 31.67 (-0.7% ± 1.4%) 42,920 (-0.2% ± 0.6%) 94,870 (+0.0% ± 0.01%) 39,167 (-1.5% ± 3.0%) 53,650 (+0.0% ± 0.1%) 1.547 (+0.1% ± 0.4%)
sharding-w8 246,740 (-0.3% ± 1.5%) 29 (+0.6% ± 0.9%) 44,098 (+0.6% ± 1.9%) 50,445 (-0.0% ± 0.06%) 36,014 (+0.6% ± 0.5%) 42,390 (-0.1% ± 0.07%) 0.1711 (-1.4% ± 2.2%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 7,836 (-2.4% ± 1.6%) 2,710 (-1.0% ± 0.5%)
lb 8,318 (+0.1% ± 1.8%) 2,785 (+0.1% ± 0.9%)
sharding-w2 17,375 (-0.4% ± 1.9%) 4,079 (+0.3% ± 1.2%)
sharding-w8 19,799 (+0.8% ± 3.2%) 4,060 (+1.1% ± 0.4%)

Microbench: all 504 measures within bounds.

Hot code per txn
path base head change
pooler 113.1 KB 113.5 KB +0.4 KB
sharding-w2 168.6 KB 168.5 KB -0.1 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 20.0 KB 20.0 KB +0.0 KB
tokio 18.2 KB 18.3 KB +0.1 KB
pgdog::backend::pool 17.4 KB 17.6 KB +0.1 KB
aws-lc (TLS crypto) 9.9 KB 9.7 KB -0.2 KB
rustls (TLS) 8.3 KB 8.4 KB +0.1 KB
pgdog::frontend (other) 7.8 KB 7.8 KB +0.1 KB
pgdog::backend::server 7.8 KB 7.8 KB -0.1 KB
other 6.0 KB 5.9 KB -0.1 KB
everything else 17.6 KB 18.0 KB +0.4 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 5.5 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.3 KB +0.0 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.3 KB +0.1 KB
tokio::runtime::task::raw::poll 3.2 KB +0.0 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.2 KB +0.0 KB

sharding-w2:

crate base head change
pgdog::frontend::router 28.9 KB 29.0 KB +0.1 KB
pgdog::frontend::client::query_engine 21.4 KB 21.1 KB -0.4 KB
tokio 19.1 KB 19.1 KB -0.1 KB
pgdog::backend::pool 18.7 KB 18.4 KB -0.2 KB
aws-lc (TLS crypto) 12.7 KB 13.0 KB +0.3 KB
other 10.0 KB 10.1 KB +0.1 KB
pgdog::frontend (other) 8.9 KB 8.9 KB -0.1 KB
rustls (TLS) 8.1 KB 8.1 KB +0.0 KB
everything else 40.8 KB 40.8 KB +0.1 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.4 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.1 KB -0.2 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.0 KB -0.1 KB
tokio::runtime::task::raw::poll 3.3 KB -0.2 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 3.3 KB +0.0 KB
lb flamegraph vs 2131844

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs 2131844

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs 2131844

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs 2131844

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs 2131844

sharding-w8

Open interactive for hover, zoom and search.

sharding-w8 removed

Open interactive.

Logs

lb, microbench, pooler, sharding-w2, sharding-w8, verdict.json

Compared 3d93c4d with 2131844 on c8g.metal-24xl (on-demand).

@github-actions

Copy link
Copy Markdown
Contributor

Metal bench (x86) passed. All 517 measures within bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 26.04 (-0.0% ± 0.2%) 18,910 (+0.1% ± 0.05%) 32,938 (+0.0% ± 0.06%) 33,717 (-0.0% ± 0.4%) 36,588 (+0.2% ± 0.4%)
lb 26.43 (-0.0% ± 0.3%) 19,482 (+0.1% ± 0.3%) 33,917 (-0.0% ± 0.06%) 33,745 (-0.2% ± 0.6%) 37,188 (-0.2% ± 0.5%)
sharding-w2 41.82 (+0.0% ± 1.1%) 46,703 (+0.1% ± 1.3%) 98,556 (-0.0% ± 0.02%) 38,562 (-0.1% ± 2.0%) 40,130 (-0.0% ± 0.2%) 1.525 (-0.0% ± 0.6%)
sharding-w8 207,805 (-0.0% ± 0.5%) 32.79 (+0.2% ± 0.5%) 45,773 (+0.3% ± 0.9%) 52,868 (+0.0% ± 0.01%) 31,182 (+0.1% ± 0.5%) 32,528 (-0.0% ± 0.1%) 0.1719 (-0.4% ± 0.3%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 3,742 (-0.1% ± 0.5%) 1,168 (-0.8% ± 1.2%) 37,822 (+0.2% ± 0.4%)
lb 3,937 (+0.6% ± 0.8%) 1,226 (+0.8% ± 0.5%) 38,441 (-0.2% ± 0.3%)
sharding-w2 6,150 (-0.2% ± 1.2%) 1,556 (-0.7% ± 1.1%) 114,942 (+0.2% ± 2.9%)
sharding-w8 3,606 (-0.2% ± 2.2%) 916 (-0.6% ± 2.0%) 176,060 (+0.5% ± 1.0%)

Microbench: all 504 measures within bounds.

Hot code per txn
path base head change
pooler 114.3 KB 114.4 KB +0.1 KB
sharding-w2 169.8 KB 169.6 KB -0.1 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 22.3 KB 22.1 KB -0.2 KB
tokio 18.4 KB 18.6 KB +0.2 KB
pgdog::backend::pool 18.1 KB 18.2 KB +0.1 KB
pgdog::frontend (other) 9.0 KB 9.0 KB +0.0 KB
aws-lc (TLS crypto) 8.6 KB 8.8 KB +0.2 KB
rustls (TLS) 7.8 KB 7.9 KB +0.2 KB
pgdog::backend::server 7.8 KB 7.9 KB +0.1 KB
other 5.8 KB 5.7 KB -0.1 KB
everything else 16.6 KB 16.2 KB -0.4 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.9 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.4 KB -0.2 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.8 KB +0.0 KB
tokio::runtime::task::raw::poll 3.7 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.6 KB -0.1 KB

sharding-w2:

crate base head change
pgdog::frontend::router 28.6 KB 28.6 KB -0.1 KB
pgdog::frontend::client::query_engine 23.4 KB 23.2 KB -0.2 KB
pgdog::backend::pool 19.2 KB 19.0 KB -0.2 KB
tokio 18.6 KB 18.4 KB -0.2 KB
other 10.8 KB 11.2 KB +0.4 KB
pgdog::frontend (other) 10.8 KB 10.8 KB -0.1 KB
aws-lc (TLS crypto) 10.0 KB 10.1 KB +0.1 KB
pgdog::backend::server 8.6 KB 8.6 KB +0.1 KB
everything else 39.8 KB 39.8 KB +0.0 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 8.2 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.4 KB +0.0 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.6 KB +0.1 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 4.3 KB +0.0 KB
tokio::runtime::task::raw::poll 3.8 KB -0.3 KB
lb flamegraph vs 2131844

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs 2131844

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs 2131844

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs 2131844

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs 2131844

sharding-w8

Open interactive for hover, zoom and search.

sharding-w8 removed

Open interactive.

Logs

lb, microbench, pooler, sharding-w2, sharding-w8, verdict.json

Compared 3d93c4d with 2131844 on m7i.metal-48xl (spot).

@jkaczman
jkaczman added this pull request to stack #2041 November 15, 2026 00:14

This branch has not been deployed

No deployments
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.

1 participant