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: Unnecessary sort operator added by SELECT with WHERE clause #33023
Comments
Note that removing the |
Fixed by #33023:
|
I am backing out the "fix". Columns in an OrderingChoice column group must be equivalent. There are subtle issues that show up if we relax that, and queries where we have equalities between columns (other than joins) shouldn't be very common. In the Select case, the columns are not equivalent under the select and we must make an (arbitrary) choice between them. As an example of a subtle issue: say that we have something like
We have a |
An idea is to use interesting orderings when making a choice for which subset of columns to keep. |
This commit updates the logic for determining whether an OrderingChoice can imply another OrderingChoice. The new logic allows columns in a group to be treated like optional columns after one of the columns is used. For example, "+1,+2,+3" implies "+(1|2),+3" now returns true. Prior to this commit, it returned false, which resulted in unnecessary sort operations in some cases. This commit also updates the corresponding logic for intersecting and finding the common prefix of two OrderingChoices. Furthermore, we now use interesting orderings to inform the required ordering passed down to the children of Select expressions. This makes it more likely that the child will be able to provide the required ordering. Informs cockroachdb#33023 Release note (performance improvement): increased the intelligence of the optimizer around orderings that can be provided by certain relational expressions when there are equalities between columns. This can allow the optimizer to remove unnecessary sort operations in some cases, thus improving performance.
This commit updates the logic for determining whether an OrderingChoice can imply another OrderingChoice. The new logic allows columns in a group to be treated like optional columns after one of the columns is used. For example, "+1,+2,+3" implies "+(1|2),+3" now returns true. Prior to this commit, it returned false, which resulted in unnecessary sort operations in some cases. This commit also updates the corresponding logic for intersecting and finding the common prefix of two OrderingChoices. Furthermore, we now use interesting orderings to inform the required ordering passed down to the children of Select expressions. This makes it more likely that the child will be able to provide the required ordering. Informs cockroachdb#33023 Release note (performance improvement): increased the intelligence of the optimizer around orderings that can be provided by certain relational expressions when there are equalities between columns. This can allow the optimizer to remove unnecessary sort operations in some cases, thus improving performance.
This commit updates the logic for determining whether an OrderingChoice can imply another OrderingChoice. The new logic allows columns in a group to be treated like optional columns after one of the columns is used. For example, "+1,+2,+3" implies "+(1|2),+3" now returns true. Prior to this commit, it returned false, which resulted in unnecessary sort operations in some cases. This commit also updates the corresponding logic for intersecting and finding the common prefix of two OrderingChoices. Furthermore, we now use interesting orderings to inform the required ordering passed down to the children of Select expressions. This makes it more likely that the child will be able to provide the required ordering. Informs cockroachdb#33023 Release note (performance improvement): increased the intelligence of the optimizer around orderings that can be provided by certain relational expressions when there are equalities between columns. This can allow the optimizer to remove unnecessary sort operations in some cases, thus improving performance.
This commit updates the logic for determining whether an OrderingChoice can imply another OrderingChoice. The new logic allows columns in a group to be treated like optional columns after one of the columns is used. For example, "+1,+2,+3" implies "+(1|2),+3" now returns true. Prior to this commit, it returned false, which resulted in unnecessary sort operations in some cases. This commit also updates the corresponding logic for intersecting and finding the common prefix of two OrderingChoices. Furthermore, we now use interesting orderings to inform the required ordering passed down to the children of Select expressions. This makes it more likely that the child will be able to provide the required ordering. Informs cockroachdb#33023 Release note (performance improvement): increased the intelligence of the optimizer around orderings that can be provided by certain relational expressions when there are equalities between columns. This can allow the optimizer to remove unnecessary sort operations in some cases, thus improving performance.
64593: opt: allow OrderingChoices to imply more orderings r=rytaft a=rytaft This commit updates the logic for determining whether an `OrderingChoice` can imply another `OrderingChoice`. The new logic allows columns in a group to be treated like optional columns after one of the columns is used. For example, "+1,+2,+3" implies "+(1|2),+3" now returns true. Prior to this commit, it returned false, which resulted in unnecessary sort operations in some cases. This commit also updates the corresponding logic for intersecting and finding the common prefix of two `OrderingChoice`s. Furthermore, we now use interesting orderings to inform the required ordering passed down to the children of `Select` expressions. This makes it more likely that the child will be able to provide the required ordering. Informs #33023 Release note (performance improvement): increased the intelligence of the optimizer around orderings that can be provided by certain relational expressions when there are equalities between columns. This can allow the optimizer to remove unnecessary sort operations in some cases, thus improving performance. Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
We have marked this issue as stale because it has been inactive for |
We have marked this issue as stale because it has been inactive for |
Repro:
Expected: No explicit sort should be necessary
Actual: An explicit sort is added.
Jira issue: CRDB-4704
The text was updated successfully, but these errors were encountered: