[CALCITE-7702] JoinAggregateTransposeRule produces a non-equivalent plan when the aggregate with empty input and empty group set - #5171
Open
zzwqqq wants to merge 2 commits into
Open
Conversation
…lan when the aggregate with empty input and empty group set
mihaibudiu
reviewed
Aug 9, 2026
| ~ limitations under the License. | ||
| --> | ||
| <Root> | ||
| <TestCase name="testNoPullAggregateWithEmptyInputAndEmptyGroupSet"> |
Contributor
There was a problem hiding this comment.
can you add a quidem test which exhibits the bug? Reading plans is hard.
Contributor
Author
There was a problem hiding this comment.
Thanks for reviewing. I added a Quidem test to join-agg-transpose.iq. It checks the query result directly. Without the fix, the query returns no rows instead of (0, 10).
|
mihaibudiu
reviewed
Aug 10, 2026
| // Pull-up adds group keys and may lose that row. Require the input to be | ||
| // known non-empty. | ||
| && (!left.getGroupSet().isEmpty() | ||
| || Boolean.FALSE.equals(mq.isEmpty(left.getInput()))) |
Contributor
There was a problem hiding this comment.
I hope that this is conservative in the right direction: it never answers "yes" when it could be empty.
mihaibudiu
approved these changes
Aug 10, 2026
Contributor
|
I will wait a bit to see if @julianhyde is satisfied. |
Contributor
|
@mihaibudiu, I've not reviewed the PR but my issues with the spec are resolved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Jira Link
CALCITE-7702
Changes Proposed
JoinAggregateTransposeRulecan produce a non-equivalent plan when an Aggregate has an empty input and an empty group set. The original Aggregate returns one row, but after pull-up the JOIN columns become group keys and the new Aggregate returns no rows.For an Aggregate with an empty group set, the rule now applies only when metadata proves that its input is non-empty.
A regression test covers this case.