Skip to content

CoalescePartitionsExec::cardinality_effect returns Equal when fetch is set #26050

Closed

Description

@asolimando

Describe the bug

CoalescePartitionsExec::cardinality_effect always returns CardinalityEffect::Equal, which is documented as "the operator is guaranteed to produce exactly one row for each input row". When fetch is set, the operator can produce fewer rows than its input, so it should return CardinalityEffect::LowerEqual, as SortExec and SortPreservingMergeExec already do when they have a fetch.

Any code that relies on cardinality_effect gets the wrong answer for this operator. For example, PassthroughStatisticsProvider returns the input statistics unchanged for operators with CardinalityEffect::Equal, so a CoalescePartitionsExec with fetch = 10 over 1000 rows reports Exact(1000) instead of Exact(10).

To Reproduce

let plan = CoalescePartitionsExec::new(input).with_fetch(Some(10));
assert!(matches!(plan.cardinality_effect(), CardinalityEffect::LowerEqual)); // fails: Equal

Expected behavior

cardinality_effect returns CardinalityEffect::LowerEqual when fetch is set, and CardinalityEffect::Equal otherwise.

Additional context

Other readers of cardinality_effect are the physical optimizer rules sort_pushdown, topk_aggregation and limit_pushdown_past_window. I did not find a query that returns wrong results because of this, and no sqllogictest plan changes with the fix.

Activity

  1. added a commit that references this issue on Oct 9, 2026
    3310fd5
  2. added a commit that references this issue on Oct 11, 2026
    13f8faf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions