Skip to content

[Query engine] Aggregate functions mixed with columns don't work #1172

Description

@levkk

PgDog version
v0.1.48

Description
Cross-shard aggregates are not returned correctly when aggregate functions are mixed with columns, e.g.:

SELECT org_id, id, extra, max(val) FROM t GROUP BY org_id, id;

Which returns multiple rows:

org_id | id | extra | max
      2 |  1 |       |  20
      3 |  1 |       |  30
      1 |  1 |       |  10

Logs
Attach trace logs, if the issue can be reproduced locally. To get trace logs, set RUST_LOG=trace, e.g.:

2026-07-09T20:18:11.984124Z DEBUG SELECT org_id, id, extra, max(val) FROM t GROUP BY org_id, id;
2026-07-09T20:18:11.984145Z DEBUG table is sharded, but no sharding key detected
2026-07-09T20:18:11.984151Z DEBUG query router decision: Query(
    Route {
        shard: ShardWithPriority {
            source: Table(
                Sharded,
            ),
            shard: All,
        },
        read: true,
        order_by: [],
        aggregate: Aggregate {
            targets: [
                AggregateTarget {
                    column: 3,
                    function: Max,
                    distinct: false,
                },
            ],
            group_by: [
                0,
                1,
            ],
        },
        limit: Limit {
            limit: None,
            offset: None,
        },
        advisory_locks: AdvisoryLocks {
            locks: {},
        },
        distinct: None,
        rewrite_plan: AggregateRewritePlan {
            helpers: [],
        },
        explain: None,
        rollback_savepoint: false,
        search_path_driven: false,
        schema_changed: false,
        omnisharded: false,
    },
)

Configuration

Sharded config with matching tables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions