Skip to content

[CALCITE-7978] RelMdColumnUniqueness can incorrectly infer that an Aggregate preserves the uniqueness of input column combinations - #5465

Open
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix-aggregate-min-max-uniqueness
Open

zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix-aggregate-min-max-uniqueness

Conversation

@zzwqqq

@zzwqqq zzwqqq commented Nov 29, 2026

Copy link
Copy Markdown
Member

Jira Link

CALCITE-7978

Changes Proposed

RelMdColumnUniqueness and RelMdUniqueKeys can incorrectly infer that aggregate results form a key when their input columns form a key. Separate calls can select values from different rows in a group, so two groups can produce the same combination.

I propose using canPassThroughKey in both handlers. For a simple GROUP BY with unfiltered pass-through aggregates, either condition lets each group return the full input key from one row.

  1. At most one input key column is outside the group set.
  2. The grouping columns are known to be unique in the input.

If neither condition holds, getUniqueKeys skips that key. areColumnsUnique still checks the selected grouping columns with one non-grouping argument at a time.

…gregate preserves the uniqueness of input column combinations
.assertThatAreColumnsUnique(bitSetOf(0, 2), is(false))
.assertThatAreColumnsUnique(bitSetOf(0, 3), is(true))
.assertThatAreColumnsUnique(bitSetOf(0, 4), is(true))
.assertThatAreColumnsUnique(bitSetOf(0, 3), is(false))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that @PaulJackson123 has added these tests, maybe he can provide a review?

@mihaibudiu

Copy link
Copy Markdown
Contributor

This is a pretty serious bug, so hopefully we can fix it quickly.

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