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: do not provide project ordering for columns removed when simplified #64444

Merged
merged 1 commit into from
Apr 30, 2021

Conversation

mgartner
Copy link
Collaborator

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

@mgartner mgartner requested review from rytaft and RaduBerinde April 30, 2021 00:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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 2 of 2 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)

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! 2 of 0 LGTMs obtained (waiting on @mgartner)

@rytaft
Copy link
Collaborator

rytaft commented Apr 30, 2021


pkg/sql/opt/ordering/project_test.go, line 81 at r1 (raw file):

			// simplification cannot be provided. This causes
			// projectBuildChildReqOrdering to panic.
			req: "+(5|6)",

Is it worth also adding a data-driven regression test with a SQL query affected by this problem? Or is there no good reproduction?

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 mgartner force-pushed the 64399-fix-project-ordering branch from 2c74904 to 6d36413 Compare April 30, 2021 01:04
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 2 stale) (waiting on @rytaft)


pkg/sql/opt/ordering/project_test.go, line 81 at r1 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

Is it worth also adding a data-driven regression test with a SQL query affected by this problem? Or is there no good reproduction?

I left it out because its pretty non-sensical and it didn't really belong anywhere. But I found logictest/testdata/logic_test/sqlsmith which seems like a loving home for it. 🏡

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.

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


pkg/sql/opt/ordering/project_test.go, line 81 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

I left it out because its pretty non-sensical and it didn't really belong anywhere. But I found logictest/testdata/logic_test/sqlsmith which seems like a loving home for it. 🏡

Hehe awesome

@mgartner
Copy link
Collaborator Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Apr 30, 2021

Build succeeded:

@craig craig bot merged commit fc86aa6 into cockroachdb:master Apr 30, 2021
@mgartner mgartner deleted the 64399-fix-project-ordering branch April 30, 2021 20:15
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