Skip to content

Non-count aggregate (sum/avg/min/max) over an empty input returns zero rows instead of one null/identity row (count(*) is special-cased) #6680

Closed

Description

@ruispereira

Summary

A non-count aggregate (sum/avg/min/max) over an empty input returns zero rows instead of the single row (with a null/identity aggregate) that SQL and Cypher callers expect. count(*) is special-cased to return 0, but the other aggregates are not, so the two behave inconsistently over an empty set.

Where (HEAD 86a704526)

engine/src/main/java/com/arcadedb/query/sql/executor/SelectExecutionPlanner.java:780-783: GuaranteeEmptyCountStep is chained only when a count-star projection is present and info.groupBy == null:

final ProjectionItem countStarItem = findCountStarItem(info, context);
if (countStarItem != null && info.groupBy == null)
  result.chain(new GuaranteeEmptyCountStep(...));

AggregateProjectionCalculationStep.executeAggregation emits nothing when the upstream is empty, so sum/avg/min/max produce no row.

Repro

SELECT max(x) FROM Foo WHERE 1=0 (or an empty type) → expected one row {max: null}; actual zero rows. SELECT count(*) FROM Foo WHERE 1=0 correctly returns one row {count: 0}, showing the inconsistency.

Suggested fix

Extend the guarantee step to emit a single all-null aggregate row for any no-group aggregation over an empty input (not just count-star).

Scope / confidence

Behavior confirmed at HEAD. Low severity — long-standing OrientDB-inherited behavior and the count-star special case shows it is a deliberate-if-incomplete design; filed as a semantic gap/consistency fix rather than a fresh defect.

Activity

  1. added this to the 26.9.1 milestone on Aug 24, 2026
  2. added
    in progress
    on Aug 24, 2026
  3. self-assigned this
    on Aug 24, 2026
  4. added a commit that references this issue on Aug 24, 2026
  5. removed
    in progress
    on Aug 24, 2026
  6. lvca commented on Aug 24, 2026

    @lvca
    Member

    Fixed in #6693 (merged to main).

    sum(), avg(), min(), max() on an empty result now correctly return one row (with 0 or null), matching what count(*) already did. Before, you'd get zero rows instead.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions