Skip to content

opt: project required ordering for EXPLAIN to input columns#88441

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:explain-order
Sep 25, 2022
Merged

opt: project required ordering for EXPLAIN to input columns#88441
craig[bot] merged 1 commit intocockroachdb:masterfrom
DrewKimball:explain-order

Conversation

@DrewKimball
Copy link
Copy Markdown
Collaborator

@DrewKimball DrewKimball commented Sep 22, 2022

Previously, EXPLAIN operators could require an ordering on non-output columns from their enclosed expression, which causes a panic. This could happen after column-pruning rules fired. This commit modifies the order-building logic to project the ordering required of the child of an EXPLAIN operator to only reference output columns.

Fixes #88037

Release note (bug fix): Fixed a longstanding bug that could cause a panic when running a query with EXPLAIN that attempts to order on a non-output column.

@DrewKimball DrewKimball requested a review from a team as a code owner September 22, 2022 08:34
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@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.

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


pkg/sql/logictest/testdata/logic_test/explain line 33 at r1 (raw file):

FROM generate_series(1, 5) AS g;

statement ok

Can you make this a query T instead so we can see that the query plan has the correct sorting applied?

Previously, `EXPLAIN` operators could require an ordering on non-output
columns from their enclosed expression, which causes a panic. This
could happen after column-pruning rules fired. This commit modifies the
order-building logic to project the ordering required of the child of
an `EXPLAIN` operator to only reference output columns.

Fixes cockroachdb#88037

Release note (bug fix): Fixed a longstanding bug that could cause
a panic when running a query with `EXPLAIN` that attempts to order
on a non-output column.
Copy link
Copy Markdown
Collaborator Author

@DrewKimball DrewKimball 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 (waiting on @mgartner)


pkg/sql/logictest/testdata/logic_test/explain line 33 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

Can you make this a query T instead so we can see that the query plan has the correct sorting applied?

Good idea. Done.

Copy link
Copy Markdown
Member

@yuzefovich yuzefovich 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 2 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mgartner)

@yuzefovich
Copy link
Copy Markdown
Member

Let's merge this to fix the sqlsmith failures.

bors r=mgartner,yuzefovich

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 25, 2022

Build succeeded:

@mgartner
Copy link
Copy Markdown
Contributor

@DrewKimball Should this be backported to the 22.2.0 branch? SQLancer might be running into the bug: sqlancer/sqlancer#587 (comment)

@DrewKimball
Copy link
Copy Markdown
Collaborator Author

I wanted to avoid backporting a fix for an old bug, but it's had some time to bake at this point, so I guess we could. How much of a problem are the failures?

@mgartner
Copy link
Copy Markdown
Contributor

Good point. They aren't a huge problem, we can ignore them in SQLancer until v22.2.1 is released.

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.

costfuzz: expected required columns to be a subset of output columns in projectBuildProvided

4 participants