Skip to content

Error when encountering an unsupported aggregate function#1020

Draft
sgrif wants to merge 3 commits into
mainfrom
sg-error-on-unsupported-aggregates
Draft

Error when encountering an unsupported aggregate function#1020
sgrif wants to merge 3 commits into
mainfrom
sg-error-on-unsupported-aggregates

Conversation

@sgrif
Copy link
Copy Markdown
Contributor

@sgrif sgrif commented May 28, 2026

When handling aggregate functions in cross-shard queries, we can only return a correct result for functions that we have explicit support for. No matter what the aggregate function is doing, we need to know how to combine the results from the separate shards.

Prior to this change, we would just silently do the wrong thing, treating this as any other non-aggregate expression and just returning a union of the rows from each query. We now explicitly check if an aggregate function with that name exists and error if we don't recognize it.

This is future proofed against new functions in later postgres versions, as well as user defined aggregates (which we can likely never support). This will produce a false positive if a function exists and is defined as aggregate for some argument types but not others. But frankly anyone doing that is asking for trouble.

This logic is objectively in the wrong place. What we are doing here is validation, not parsing. However as I'm familiarizing myself with these code paths and preparing a larger rearchitecture, I'm slowly hammering things into a shape that's easier to move around. I do not intend on leaving this logic here long term.

When handling aggregate functions in cross-shard queries, we can only
return a correct result for functions that we have explicit support
for. No matter what the aggregate function is doing, we need to know how
to combine the results from the separate shards.

Prior to this change, we would just silently do the wrong thing,
treating this as any other non-aggregate expression and just returning a
union of the rows from each query. We now explicitly check if an
aggregate function with that name exists and error if we don't recognize
it.

This is future proofed against new functions in later postgres versions,
as well as user defined aggregates (which we can likely never support).
This will produce a false positive if a function exists and is defined
as aggregate for some argument types but not others. But frankly anyone
doing that is asking for trouble.

This logic is objectively in the wrong place. What we are doing here is
validation, not parsing. However as I'm familiarizing myself with these
code paths and preparing a larger rearchitecture, I'm slowly hammering
things into a shape that's easier to move around. I do not intend on
leaving this logic here long term.
@blacksmith-sh
Copy link
Copy Markdown
Contributor

blacksmith-sh Bot commented May 28, 2026

Found 3 test failures on Blacksmith runners:

Failures

Test View Logs
pg_tests/TestShardedTwoPc View Logs
pg_tests/TestShardedTwoPc View Logs
pg_tests/TestShardedTwoPc View Logs

Fix in Cursor

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread pgdog/src/frontend/router/parser/aggregate.rs
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