Skip to content

fix(cross-shard): compute LIMIT/OFFSET with integer arithmetic and casts - #2030

Open
murex971 wants to merge 1 commit into
mainfrom
murex-limit-expressions
Open

murex971 wants to merge 1 commit into
mainfrom
murex-limit-expressions

Conversation

@murex971

Copy link
Copy Markdown
Contributor

Problem

Cross-shard GROUP BY with aggregates or HAVING rejected
LIMIT 1 + 1 and LIMIT $1::int with 0A000.

Fix

LimitClause computes integer arithmetic (+ - * / %, unary -/+) and
casts to int2/int4/int8 over literals and parameters. A cast
fails when the value doesn't fit the type. NULL anywhere means no limit,
as in Postgres.

Still rejected with 0A000: functions, subqueries, decimal literals,
non-integer casts, and simple-protocol PREPARE/EXECUTE with an
expression.

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.97173% with 68 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pgdog/src/frontend/router/parser/limit.rs 73.70% 56 Missing ⚠️
...tend/router/parser/rewrite/statement/projection.rs 25.00% 12 Missing ⚠️

📢 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.1 (+0.4% ± 0.9%) 18,829 (-0.2% ± 0.4%) 32,009 (+0.0% ± 0.1%) 30,003 (+0.7% ± 1.7%) 51,051 (-0.1% ± 0.4%)
lb 19.66 (-1.0% ± 0.9%) 19,406 (-0.5% ± 0.6%) 32,897 (+0.0% ± 0.05%) 30,625 (-1.4% ± 1.4%) 52,152 (+0.1% ± 0.2%)
sharding-w2 31.41 (+0.7% ± 1.9%) 42,977 (+0.5% ± 0.4%) 97,507 (+0.1% ± 0.01%) 38,487 (+1.1% ± 4.0%) 53,627 (-0.0% ± 0.10%) 1.548 (-0.1% ± 0.2%)
sharding-w8 250,357 (-0.7% ± 2.5%) 28.5 (+0.8% ± 2.4%) 43,945 (+0.6% ± 1.3%) 53,027 (+0.1% ± 0.02%) 34,753 (+1.1% ± 4.2%) 42,372 (+0.0% ± 0.1%) 0.1726 (-0.7% ± 1.6%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 8,233 (-0.6% ± 1.0%) 2,699 (-0.0% ± 0.5%)
lb 8,551 (-0.5% ± 1.2%) 2,751 (-0.2% ± 0.4%)
sharding-w2 16,708 (+1.3% ± 1.3%) 3,940 (+0.4% ± 0.3%)
sharding-w8 18,768 (+2.4% ± 1.4%) 3,880 (+1.4% ± 1.6%)

Microbench: all 504 measures within bounds.

Hot code per txn
path base head change
pooler 112.3 KB 112.7 KB +0.4 KB
sharding-w2 165.1 KB 164.8 KB -0.3 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 19.5 KB 19.6 KB +0.1 KB
tokio 18.4 KB 18.6 KB +0.2 KB
pgdog::backend::pool 17.6 KB 17.6 KB +0.0 KB
aws-lc (TLS crypto) 10.5 KB 10.4 KB -0.1 KB
rustls (TLS) 8.4 KB 8.3 KB -0.1 KB
pgdog::frontend (other) 7.8 KB 7.7 KB -0.1 KB
pgdog::backend::server 7.4 KB 7.2 KB -0.2 KB
other 6.4 KB 6.5 KB +0.1 KB
everything else 16.2 KB 16.7 KB +0.4 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 5.5 KB +0.0 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.2 KB +0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.1 KB -0.1 KB
tokio::runtime::task::raw::poll 3.2 KB -0.1 KB
pgdog::backend::server::Server::read::{{closure}} 2.9 KB +0.0 KB

sharding-w2:

crate base head change
pgdog::frontend::router 29.1 KB 28.3 KB -0.8 KB
pgdog::frontend::client::query_engine 20.4 KB 20.6 KB +0.2 KB
tokio 18.8 KB 18.6 KB -0.1 KB
pgdog::backend::pool 18.4 KB 18.1 KB -0.2 KB
aws-lc (TLS crypto) 12.9 KB 12.9 KB +0.0 KB
other 9.8 KB 10.2 KB +0.4 KB
pgdog::frontend (other) 8.6 KB 8.5 KB -0.1 KB
rustls (TLS) 8.1 KB 7.9 KB -0.2 KB
everything else 39.1 KB 39.7 KB +0.6 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.0 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.1 KB +0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.1 KB +0.1 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 3.4 KB +0.0 KB
tokio::runtime::task::raw::poll 3.2 KB -0.1 KB
lb flamegraph vs e084496

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs e084496

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs e084496

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs e084496

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs e084496

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 a745f29 with e084496 on m8g.metal-24xl (spot).

@github-actions

Copy link
Copy Markdown
Contributor

Metal bench (x86) failed. 1 of 517 measures outside bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 34.73 (+0.2% ± 0.2%) 22,934 (+0.4% ± 0.7%) 33,982 (-0.0% ± 0.02%) 57,852 (+0.3% ± 0.2%) 38,536 (-0.1% ± 0.1%)
lb 35.69 (-0.0% ± 0.3%) 24,057 (-0.4% ± 0.8%) 34,937 (+0.0% ± 0.02%) 58,669 (+0.1% ± 0.3%) 39,207 (+0.0% ± 0.09%)
sharding-w2 56.41 (+0.0% ± 1.1%) 53,320 (+0.6% ± 1.9%) 101,452 (+0.0% ± 0.08%) 72,483 (-0.4% ± 1.0%) 43,124 (-0.0% ± 0.6%) 1.394 (-0.0% ± 0.3%)
sharding-w8 148,417 (-0.6% ± 2.2%) 48.08 (+0.1% ± 1.5%) 58,294 (+0.5% ± 2.5%) 56,905 (+0.2% ± 0.06%) 63,755 (-0.2% ± 0.8%) 34,200 (+0.1% ± 0.2%) 0.1687 (+0.3% ± 4.1%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 73,001 (+0.8% ± 1.2%) 3,671 (+0.2% ± 0.2%)
lb 75,948 (-0.7% ± 1.1%) 3,798 (+0.0% ± 0.2%)
sharding-w2 157,176 (+1.0% ± 5.1%) 6,060 (+0.1% ± 1.1%)
sharding-w8 120,356 (-0.4% ± 0.3%) 4,824 (+0.6% ± 0.4%)
benchmark measure result baseline change bound
extended_cached::order_limit_offset instructions 17,464 17,239 +1.31% ± 0.00% +1%

Microbench: 503 of 504 measures within bounds.

Hot code per txn
path base head change
pooler 101.5 KB 103.9 KB +2.4 KB
sharding-w2 157.0 KB 159.6 KB +2.6 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 19.4 KB 20.2 KB +0.9 KB
pgdog::backend::pool 16.7 KB 17.1 KB +0.4 KB
tokio 17.0 KB 17.1 KB +0.1 KB
pgdog::frontend (other) 8.8 KB 8.9 KB +0.1 KB
aws-lc (TLS crypto) 7.4 KB 7.5 KB +0.1 KB
rustls (TLS) 6.8 KB 6.9 KB +0.1 KB
pgdog::backend::server 6.4 KB 6.4 KB +0.0 KB
other 5.6 KB 5.9 KB +0.3 KB
everything else 13.5 KB 13.9 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.1 KB +0.7 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.4 KB -0.3 KB
tokio::runtime::task::raw::poll 3.5 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.1 KB -0.1 KB

sharding-w2:

crate base head change
pgdog::frontend::router 27.1 KB 27.8 KB +0.7 KB
pgdog::frontend::client::query_engine 22.0 KB 22.6 KB +0.6 KB
pgdog::backend::pool 18.2 KB 18.1 KB -0.1 KB
tokio 17.4 KB 17.6 KB +0.2 KB
aws-lc (TLS crypto) 10.6 KB 10.4 KB -0.2 KB
pgdog::frontend (other) 9.8 KB 10.1 KB +0.3 KB
other 9.7 KB 9.6 KB -0.1 KB
rustls (TLS) 7.3 KB 7.4 KB +0.1 KB
everything else 35.1 KB 36.2 KB +1.1 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 7.6 KB +0.2 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.0 KB +0.2 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.9 KB +0.2 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 3.9 KB -0.2 KB
tokio::runtime::task::raw::poll 3.8 KB +0.0 KB
lb flamegraph vs e084496

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs e084496

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs e084496

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs e084496

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs e084496

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 a745f29 with e084496 on c7a.metal-48xl (spot).

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