-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
props: normalize empty OrderingChoice instances in all cases
Fixes #79644 Previously, a query with an ORDER BY clause a DISTINCT ON clause and a GROUP BY clause involving columns in different join tables may error out if there is an index on one of the GROUP BY's Optional OrderingChoice columns and that column is not in the ordering required by the ORDER BY clause. `FromOrderingWithOptCols` is called during construction of the group by expression, and builds a `GroupingPrivate` with `Ordering` of `Any` (no columns), but still includes the `Optional` grouping columns. This violates the rule stated in the comments for `Optional`: ``` ...if Columns is empty, then Optional must be as well. ``` Because of this unnormalized `OrderingChoice`, this makes it appear that the projected grouping column can provide the required ordering even though this column does not actually intersect with the ordering columns. A later call to `OrderingChoice.Intersection` is made in `groupByBuildChildReqOrdering` to find the intersection between required and provided orderings, which panics when it cannot build the intersection. `Optional` columns may only be added to an ordering when there is at least one ordering column, and this assumption is also made in the code that builds `OrderingChoice`s. To address this, this patch fixes all locations where an empty `OrderingChoice` which matches `Any` ordering is built by normalizing it so that the `Optional` column set is empty. Release note (bug fix): This patch fixes queries which involve an ORDER BY clause, a DISTINCT ON clause and a GROUP BY clause, which may sometimes error out depending on the columns referenced in those clauses.
- Loading branch information
Mark Sirek
committed
Apr 24, 2022
1 parent
621a046
commit 9e61561
Showing
3 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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