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

release-19.2: opt: fix internal error due to nested correlated aggregate functions #52141

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Jul 30, 2020

Backport 1/1 commits from #52092.

/cc @cockroachdb/release


Prior to this commit, the query SELECT max((SELECT count(v))) FROM kv;
caused an internal error. This query is invalid, but instead of causing an
internal error, the optimizer should have rejected it for containing nested
aggregates (that's what Postgres does). However, the optimizer could not
recognize that the aggregates were nested in this case.

This commit fixes the error by ensuring that the optimizer can detect
that the aggregate functions are nested. It does so by updating the outer
scope earlier to indicate the start of an aggregate function so that any
nested aggregates referencing the outer scope from a subquery in the aggregate
function arguments will return an appropriate error.

Fixes #41820
Fixes #51877

Release note (bug fix): Fixed an internal error that could occur when
an aggregate function argument contained a correlated subquery with another
aggregate function referencing the outer scope. This now returns an appropriate
user-friendly error, "aggregate function calls cannot be nested".

Prior to this commit, the query `SELECT max((SELECT count(v))) FROM kv;`
caused an internal error. This query is invalid, but instead of causing an
internal error, the optimizer should have rejected it for containing nested
aggregates (that's what Postgres does). However, the optimizer could not
recognize that the aggregates were nested in this case.

This commit fixes the error by ensuring that the optimizer can detect
that the aggregate functions are nested. It does so by updating the outer
scope earlier to indicate the start of an aggregate function so that any
nested aggregates referencing the outer scope from a subquery in the aggregate
function arguments will return an appropriate error.

Fixes cockroachdb#41820
Fixes cockroachdb#51877

Release note (bug fix): Fixed an internal error that could occur when
an aggregate function argument contained a correlated subquery with another
aggregate function referencing the outer scope. This now returns an appropriate
user-friendly error, "aggregate function calls cannot be nested".
@rytaft rytaft requested a review from RaduBerinde July 30, 2020 16:18
@rytaft rytaft requested a review from a team as a code owner July 30, 2020 16:18
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

@rytaft rytaft merged commit 6c5a7da into cockroachdb:release-19.2 Jul 30, 2020
@rytaft rytaft deleted the backport19.2-52092 branch July 30, 2020 17:53
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.

3 participants