Skip to content

sql: disallow aggregate functions in ORDER BY in DELETE and UPDATE#107641

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
mgartner:107634-disallow-order-by-aggs
Jul 26, 2023
Merged

sql: disallow aggregate functions in ORDER BY in DELETE and UPDATE#107641
craig[bot] merged 1 commit intocockroachdb:masterfrom
mgartner:107634-disallow-order-by-aggs

Conversation

@mgartner
Copy link
Copy Markdown
Contributor

This commit disallows aggregate functions in the context of an
ORDER BY clause in a DELETE or UPDATE statement. An aggregate
function in an ORDER BY would require a GROUP BY clause to group
non-aggregate columns. A GROUP BY is not allowed in DELETE or
UPDATE statements as it's not obvious how grouping in these statements
would behave. So we simply disallow aggregates in ORDER BY instead.

Fixes #107634

Release note (bug fix): A bug has been fixed that caused internal errors
when using an aggregate function in an ORDER BY clause of a DELETE
or UPDATE statement. Aggregate functions are no longer allowed in
these contexts. The bug has been present since at least version 20.2.

This commit disallows aggregate functions in the context of an
`ORDER BY` clause in a `DELETE` or `UPDATE` statement. An aggregate
function in an `ORDER BY` would require a `GROUP BY` clause to group
non-aggregate columns. A `GROUP BY` is not allowed in `DELETE` or
`UPDATE` statements as it's not obvious how grouping in these statements
would behave. So we simply disallow aggregates in `ORDER BY` instead.

Fixes cockroachdb#107634

Release note (bug fix): A bug has been fixed that caused internal errors
when using an aggregate function in an `ORDER BY` clause of a `DELETE`
or `UPDATE` statement. Aggregate functions are no longer allowed in
these contexts. The bug has been present since at least version 20.2.
@mgartner mgartner requested a review from michae2 July 26, 2023 17:12
@mgartner mgartner requested a review from a team as a code owner July 26, 2023 17:12
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice!

Reviewed 8 of 8 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)

@mgartner
Copy link
Copy Markdown
Contributor Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jul 26, 2023

Build succeeded:

@craig craig bot merged commit 1d3c11e into cockroachdb:master Jul 26, 2023
@mgartner mgartner deleted the 107634-disallow-order-by-aggs branch July 26, 2023 22:17
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.

sql: Internal Error: column x not in input.

3 participants