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

opt: remove non-equivalent group columns in OrderingChoice.Simplify #64342

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

mgartner
Copy link
Collaborator

Previously, OrderingChoice.Simplify would add but never remove columns
from ordering column groups based on equivalency in an FD. In rare
cases, this could cause the optimizer to generate expressions which
violated an invariant that all columns in an ordering column group are
equivalent according to the expression's FD.

Violation of this invariant only panics in test builds, and in the test
cases found that trigger this panic, there is likely no correctness
issues with the expression. Therefore, there was probably no impact in
any release builds.

This commit updates OrderingChoice.Simplify so that non-equivalent
columns in an ordering column group are removed from the group,
satisfying the invariant.

Fixes #63794

Release note: None

@mgartner mgartner requested review from rytaft and RaduBerinde April 28, 2021 17:44
@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 @mgartner and @rytaft)


pkg/sql/opt/props/physical/ordering_choice.go, line 523 at r1 (raw file):

		}

		// Check whether new equivalent columns can be added by the FD set.

[nit] Check whether the equivalency group needs to change.

Previously, `OrderingChoice.Simplify` would add but never remove columns
from ordering column groups based on equivalency in an FD. In rare
cases, this could cause the optimizer to generate expressions which
violated an invariant that all columns in an ordering column group are
equivalent according to the expression's FD.

Violation of this invariant only panics in test builds, and in the test
cases found that trigger this panic, there is likely no correctness
issues with the expression. Therefore, there was probably no impact in
any release builds.

This commit updates `OrderingChoice.Simplify` so that non-equivalent
columns in an ordering column group are removed from the group,
satisfying the invariant.

Fixes cockroachdb#63794

Release note: None
Copy link
Collaborator Author

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

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


pkg/sql/opt/props/physical/ordering_choice.go, line 523 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] Check whether the equivalency group needs to change.

Done.

Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 4 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner)

@mgartner
Copy link
Collaborator Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Apr 28, 2021

Build succeeded:

@craig craig bot merged commit 9190550 into cockroachdb:master Apr 28, 2021
@mgartner mgartner deleted the 63794-ordering-fix branch April 28, 2021 22:15
mgartner added a commit to mgartner/cockroach that referenced this pull request Apr 30, 2021
Previously, `projectCanProvideOrdering` did not simplify an ordering
base on an FD set if the original ordering could be provided, while
`projectBuildChildReqOrdering` always attempted to simplify an ordering.
In cockroachdb#64342 the behavior of `OrderingChoice.Simplify` changed  to remove
columns in groups that are not known to be equivalent by the FD. As a
result, `projectCanProvideOrdering` could return true in cases where the
simplified ordering, with some columns removed, could not be provided,
causing `ordering.projectBuildChildReqOrdering` to panic.

This commit updates `ordering.projectCanProvideOrdering` so that the
ordering is always simplified, matching the behavior of
`ordering.projectBuildChildReqOrdering`.

Fixes cockroachdb#64399

Release note: None
mgartner added a commit to mgartner/cockroach that referenced this pull request Apr 30, 2021
Previously, `projectCanProvideOrdering` did not simplify an ordering
base on an FD set if the original ordering could be provided, while
`projectBuildChildReqOrdering` always attempted to simplify an ordering.
In cockroachdb#64342 the behavior of `OrderingChoice.Simplify` changed  to remove
columns in groups that are not known to be equivalent by the FD. As a
result, `projectCanProvideOrdering` could return true in cases where the
simplified ordering, with some columns removed, could not be provided,
causing `ordering.projectBuildChildReqOrdering` to panic.

This commit updates `ordering.projectCanProvideOrdering` so that the
ordering is always simplified, matching the behavior of
`ordering.projectBuildChildReqOrdering`.

Fixes cockroachdb#64399

Release note: None
craig bot pushed a commit that referenced this pull request Apr 30, 2021
64306: pgcode: remove a couple of deprecated errors r=yuzefovich a=yuzefovich

Release note: None

64441: ccl/sqlproxyccl: fix a broken test in bazel r=darinpp a=darinpp

This fixes #61915
by adding the required data files.

Release note: None

64444: opt: do not provide project ordering for columns removed when simplified r=mgartner a=mgartner

Previously, `projectCanProvideOrdering` did not simplify an ordering
base on an FD set if the original ordering could be provided, while
`projectBuildChildReqOrdering` always attempted to simplify an ordering.
In #64342 the behavior of `OrderingChoice.Simplify` changed  to remove
columns in groups that are not known to be equivalent by the FD. As a
result, `projectCanProvideOrdering` could return true in cases where the
simplified ordering, with some columns removed, could not be provided,
causing `ordering.projectBuildChildReqOrdering` to panic.

This commit updates `ordering.projectCanProvideOrdering` so that the
ordering is always simplified, matching the behavior of
`ordering.projectBuildChildReqOrdering`.

Fixes #64399

Release note: None

64483: bazel: prefer `exec_tools` to `tools` in `BUILD` files r=rail a=rickystewart

The [documentation](https://docs.bazel.build/versions/master/be/general.html#genrule_args)
specifies that `exec_tools` is preferred to `tools` wherever possible.
It doesn't matter in our case, so let's just standardize on `exec_tools`
everywhere.

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: Darin Peshev <[email protected]>
Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
mgartner added a commit to mgartner/cockroach that referenced this pull request May 13, 2021
Previously, `projectCanProvideOrdering` did not simplify an ordering
base on an FD set if the original ordering could be provided, while
`projectBuildChildReqOrdering` always attempted to simplify an ordering.
In cockroachdb#64342 the behavior of `OrderingChoice.Simplify` changed  to remove
columns in groups that are not known to be equivalent by the FD. As a
result, `projectCanProvideOrdering` could return true in cases where the
simplified ordering, with some columns removed, could not be provided,
causing `ordering.projectBuildChildReqOrdering` to panic.

This commit updates `ordering.projectCanProvideOrdering` so that the
ordering is always simplified, matching the behavior of
`ordering.projectBuildChildReqOrdering`.

Fixes cockroachdb#64399

Release note: None
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/tests: TestRandomSyntaxSQLSmith failed
4 participants