Skip to content

fix(cross-shard): detect DISTINCT on aggregates behind a cast - #2071

Merged
murex971 merged 2 commits into
mainfrom
fix-unsupported-distinct
Nov 21, 2026
Merged

murex971 merged 2 commits into
mainfrom
fix-unsupported-distinct

Conversation

@murex971

Copy link
Copy Markdown
Contributor

Summary

A cross-shard count(DISTINCT x)::int returned the sum of each shard's
distinct count. The DISTINCT flag was only read when the aggregate was
the top-level expression, so a cast hid it and the query was merged as a
plain count.

The flag is now read from the same call node as the function name, after
unwrapping casts. These queries get the same 0A000 error as the uncast
form: "count(DISTINCT ...) is not yet supported".

The same applies to sum, avg and the variance functions.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@murex971
murex971 added this pull request to stack #2073 November 19, 2026 13:21
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 18.82 (-0.7% ± 1.0%) 17,600 (-0.4% ± 0.5%) 31,370 (+0.0% ± 0.03%) 30,450 (-1.1% ± 1.7%) 51,073 (-0.0% ± 0.2%)
lb 19.43 (-0.6% ± 1.0%) 18,358 (+0.0% ± 0.6%) 32,485 (-0.1% ± 0.1%) 31,065 (-1.1% ± 1.5%) 52,094 (+0.1% ± 0.8%)
sharding-w2 32.76 (+0.2% ± 2.4%) 44,213 (+0.3% ± 0.6%) 95,087 (+0.0% ± 0.08%) 40,872 (+0.1% ± 4.2%) 53,759 (+0.0% ± 0.3%) 1.55 (+0.0% ± 0.3%)
sharding-w8 245,463 (-0.5% ± 1.0%) 28.95 (+0.6% ± 0.9%) 44,808 (+0.8% ± 1.0%) 50,636 (-0.0% ± 0.00%) 35,077 (+0.4% ± 0.8%) 42,427 (-0.0% ± 0.04%) 0.1715 (-0.7% ± 1.4%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 7,305 (-1.1% ± 1.6%) 2,639 (-0.4% ± 0.8%)
lb 7,727 (-0.0% ± 1.4%) 2,691 (+0.2% ± 0.6%)
sharding-w2 18,636 (+0.9% ± 0.9%) 4,218 (+0.5% ± 0.8%)
sharding-w8 20,566 (+2.0% ± 5.1%) 4,174 (+1.2% ± 3.1%)

Microbench: all 507 measures within bounds.

Hot code per txn
path base head change
pooler 113.6 KB 113.1 KB -0.5 KB
sharding-w2 168.1 KB 167.5 KB -0.6 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 20.4 KB 20.5 KB +0.1 KB
tokio 18.4 KB 18.3 KB -0.1 KB
pgdog::backend::pool 17.3 KB 17.4 KB +0.1 KB
aws-lc (TLS crypto) 10.4 KB 10.2 KB -0.1 KB
rustls (TLS) 8.5 KB 8.3 KB -0.2 KB
pgdog::frontend (other) 7.8 KB 7.9 KB +0.1 KB
pgdog::backend::server 7.6 KB 7.7 KB +0.1 KB
other 5.7 KB 5.9 KB +0.2 KB
everything else 17.4 KB 16.8 KB -0.6 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 5.6 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.4 KB +0.2 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.4 KB +0.0 KB
tokio::runtime::task::raw::poll 3.1 KB -0.1 KB

sharding-w2:

crate base head change
pgdog::frontend::router 29.1 KB 29.0 KB -0.1 KB
pgdog::frontend::client::query_engine 21.8 KB 21.5 KB -0.2 KB
tokio 18.1 KB 18.5 KB +0.4 KB
pgdog::backend::pool 18.5 KB 18.0 KB -0.5 KB
aws-lc (TLS crypto) 13.1 KB 13.0 KB -0.1 KB
other 9.7 KB 9.9 KB +0.2 KB
pgdog::frontend (other) 8.9 KB 8.8 KB -0.2 KB
rustls (TLS) 8.0 KB 8.2 KB +0.2 KB
everything else 41.0 KB 40.6 KB -0.4 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.2 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.3 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.8 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.3 KB +0.1 KB
lb flamegraph vs dbeed6a

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs dbeed6a

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs dbeed6a

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs dbeed6a

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs dbeed6a

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 90343dc with dbeed6a on m8g.metal-24xl (spot).

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 25.93 (-0.1% ± 0.5%) 18,683 (-0.0% ± 0.1%) 32,795 (+0.0% ± 0.05%) 33,801 (-0.0% ± 0.5%) 36,511 (+0.1% ± 0.7%)
lb 26.44 (+0.1% ± 0.6%) 19,491 (+0.0% ± 0.2%) 34,004 (-0.0% ± 0.03%) 33,862 (-0.0% ± 0.7%) 37,205 (+0.1% ± 0.3%)
sharding-w2 42.13 (+0.7% ± 2.9%) 47,542 (+1.3% ± 4.5%) 98,837 (-0.0% ± 0.08%) 38,541 (+0.3% ± 2.1%) 40,128 (-0.0% ± 0.2%) 1.524 (-0.2% ± 0.7%)
sharding-w8 205,746 (-0.4% ± 1.0%) 33.04 (+0.3% ± 0.4%) 46,176 (+0.5% ± 0.7%) 53,172 (-0.0% ± 0.08%) 31,399 (+0.1% ± 0.5%) 32,500 (+0.0% ± 0.1%) 0.1731 (+0.3% ± 3.0%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 3,504 (-0.1% ± 0.8%) 1,174 (-0.5% ± 0.6%) 38,136 (-0.1% ± 1.0%)
lb 3,642 (-0.0% ± 1.1%) 1,202 (-0.1% ± 1.1%) 40,364 (+0.1% ± 0.7%)
sharding-w2 7,203 (+18.5% ± 60.4%) 1,550 (+1.4% ± 6.6%) 112,306 (-3.0% ± 10.2%)
sharding-w8 3,270 (-1.4% ± 1.3%) 878 (-0.9% ± 1.8%) 180,092 (+0.9% ± 0.9%)

Microbench: all 507 measures within bounds.

Microbench latency: 3 benches changed more than 3%
benchmark latency baseline change instructions change
extended_cached::having_distinct_limit 3,611 ns 3,400 ns +6.19% ± 0.73% -0.39% ± 0.00%
extended_cached::having 3,082 ns 2,983 ns +3.31% ± 0.42% -0.47% ± 0.00%
extended_cached::group_by 2,841 ns 2,758 ns +3.00% ± 0.24% -0.52% ± 0.00%
Hot code per txn
path base head change
pooler 115.2 KB 113.8 KB -1.4 KB
sharding-w2 169.9 KB 169.4 KB -0.5 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 22.5 KB 22.1 KB -0.4 KB
tokio 18.5 KB 18.4 KB -0.1 KB
pgdog::backend::pool 17.8 KB 17.6 KB -0.1 KB
pgdog::frontend (other) 9.7 KB 9.8 KB +0.1 KB
aws-lc (TLS crypto) 8.8 KB 8.6 KB -0.2 KB
pgdog::backend::server 8.0 KB 8.0 KB +0.0 KB
rustls (TLS) 7.7 KB 7.8 KB +0.1 KB
other 6.0 KB 5.7 KB -0.3 KB
everything else 16.2 KB 15.9 KB -0.4 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 7.4 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.4 KB -0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.8 KB +0.0 KB
tokio::runtime::task::raw::poll 3.8 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.7 KB -0.1 KB

sharding-w2:

crate base head change
pgdog::frontend::router 28.1 KB 28.1 KB +0.0 KB
pgdog::frontend::client::query_engine 23.9 KB 23.7 KB -0.2 KB
pgdog::backend::pool 19.2 KB 18.9 KB -0.4 KB
tokio 18.3 KB 18.6 KB +0.2 KB
other 10.4 KB 11.1 KB +0.8 KB
pgdog::frontend (other) 10.9 KB 10.9 KB +0.1 KB
aws-lc (TLS crypto) 10.5 KB 10.1 KB -0.4 KB
pgdog::backend::server 8.6 KB 8.5 KB -0.1 KB
everything else 40.0 KB 39.5 KB -0.5 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 8.4 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.2 KB -0.3 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.7 KB -0.1 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 4.6 KB -0.1 KB
tokio::runtime::task::raw::poll 3.8 KB -0.2 KB
lb flamegraph vs dbeed6a

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs dbeed6a

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs dbeed6a

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs dbeed6a

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs dbeed6a

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 90343dc with dbeed6a on m7i.metal-48xl (spot).

@murex971
murex971 merged commit 9224a66 into main Nov 21, 2026
45 of 47 checks passed
@murex971
murex971 deleted the fix-unsupported-distinct branch November 21, 2026 08:22
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.

2 participants