-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
opt: fix some aggregate scoping issues #46227
Conversation
gentle ping |
Prior to this commit, some aggregate functions were either incorrectly rejected or incorrectly accepted when they were scoped at a higher level than their position in the query. For example, aggregate functions are not normally allowed in WHERE, but if the aggregate is actually scoped at a higher level, then the aggregate should be allowed. Prior to this commit, these aggregate functions were rejected and caused an error. This commit fixes the issue by validating the context of the aggregate's scope rather than the aggregate's position in the query. In order to avoid adding another field to the scope struct, this commit re-uses the existing `context` field which was previously only used for error messages. To make comparisons more efficient, the field is now an enum rather than a string. Fixes cockroachdb#44724 Fixes cockroachdb#45838 Fixes cockroachdb#30652 Release justification: This bug fix is a low risk, high benefit change to existing functionality, since it fixes internal errors and increases compatibility with Postgres. Release note (bug fix): Fixed an internal error that could occur when an aggregate inside the right-hand side of a LATERAL join was scoped at the level of the left-hand side. Release note (bug fix): Fixed an error that incorrectly occurred when an aggregate was used inside the WHERE or ON clause of a subquery but was scoped at an outer level of the query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry, this fell through the cracks. Very clean change!
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @andy-kimball and @RaduBerinde)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build succeeded |
Prior to this commit, some aggregate functions were either incorrectly
rejected or incorrectly accepted when they were scoped at a higher
level than their position in the query. For example, aggregate functions
are not normally allowed in
WHERE
, but if the aggregate is actually scopedat a higher level, then the aggregate should be allowed. Prior to this
commit, these aggregate functions were rejected and caused an error.
This commit fixes the issue by validating the context of the aggregate's
scope rather than the aggregate's position in the query. In order to
avoid adding another field to the scope struct, this commit re-uses
the existing
context
field which was previously only used for errormessages. To make comparisons more efficient, the field is now an enum
rather than a string.
Fixes #44724
Fixes #45838
Fixes #30652
Release justification: This bug fix is a low risk, high benefit change
to existing functionality, since it fixes internal errors and increases
compatibility with Postgres.
Release note (bug fix): Fixed an internal error that could occur when
an aggregate inside the right-hand side of a LATERAL join was scoped at
the level of the left-hand side.
Release note (bug fix): Fixed an error that incorrectly occurred when
an aggregate was used inside the WHERE or ON clause of a subquery but
was scoped at an outer level of the query.