Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colbuilder: fix aggregation with no aggregate funcs #87662

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Sep 9, 2022

Previously, if there are no aggregate functions to compute, we would plan a special "num fixed tuples" operator that would always return a single tuple when in scalar and no tuples when in non-scalar context, but this is incorrect - we should be returning the same number of tuples as there are groups for non-empty input. The previous setup was correct only when the input is empty. This is now fixed by teaching the ordered aggregator to handle this special case instead. The impact of the bug seems minor since the optimizer should only be creating such plans when some of its rules are disabled.

Fixes: #87619.

Epic: CRDB-20535

Release note: None (this shouldn't be a user-visible bug)

@yuzefovich yuzefovich requested review from msirek, DrewKimball and a team September 9, 2022 00:37
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm: could you add a logic test?

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @msirek)

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Added a test, but it relies on the disabling of some rules, so it'll fail the CI until #87658 is merged. I'm not sure whether it is possible to come up with a regression test without disabling the rules. Do you have an idea if that is possible?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @msirek)

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

I don't think there's currently a way to disable specific rules in logic tests / from the command line. There probably should be, though. And I think this case would always be normalized away without any rules disabled.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @msirek)

Copy link
Contributor

@msirek msirek left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @yuzefovich)

Previously, if there are no aggregate functions to compute, we would
plan a special "num fixed tuples" operator that would always return
a single tuple when in scalar and no tuples when in non-scalar context,
but this is incorrect - we should be returning the same number of tuples
as there are groups for non-empty input. The previous setup was correct
only when the input is empty. This is now fixed by teaching the ordered
aggregator to handle this special case instead. The impact of the bug
seems minor since the optimizer should only be creating such plans when
some of its rules are disabled.

Release note: None (this shouldn't be a user-visible bug)
@yuzefovich
Copy link
Member Author

Adjusted the test so that it succeeds without #87658.

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 9, 2022

Build succeeded:

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.

roachtest: incorrect aggregation planning in the vectorized engine
4 participants