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: add scan constant columns to ordering if they are in the output #87562

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

DrewKimball
Copy link
Collaborator

Previously when building the provided ordering for a constrained scan, any columns proven to be constant by the constraint were ignored. This allows the optimizer to prove that the scan can provide orderings that omit those columns. However, in the case when one of these columns is an output column and the functional dependencies do not show it as constant, an internal error will result. This happens because the provided ordering omits the constant column, but the functional dependencies cannot later be used to show that the column was optional when checking whether the required ordering is satisfied.

This commit modifies the logic to only avoid considering constrained-constant index columns to be added to the provided ordering when they are not output columns.

Fixes #83793

Release note (bug fix): fixed a bug introduced in 21.2 that could cause an internal error in rare cases when a query required a constrained index scan to return results in order.

Previously when building the provided ordering for a constrained scan, any
columns proven to be constant by the constraint were ignored. This allows
the optimizer to prove that the scan can provide orderings that omit those
columns. However, in the case when one of these columns is an output column
and the functional dependencies do not show it as constant, an internal error
will result. This happens because the provided ordering omits the constant
column, but the functional dependencies cannot later be used to show that the
column was optional when checking whether the required ordering is satisfied.

This commit modifies the logic to only avoid considering constrained-constant
index columns to be added to the provided ordering when they are not output
columns.

Fixes cockroachdb#83793

Release note (bug fix): fixed a bug introduced in 21.2 that could cause
an internal error in rare cases when a query required a constrained index
scan to return results in order.
@DrewKimball DrewKimball requested a review from a team as a code owner September 8, 2022 02:44
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

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

Thanks! :lgtm:

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)

@DrewKimball
Copy link
Collaborator Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 9, 2022

Build succeeded:

@blathers-crl
Copy link

blathers-crl bot commented Sep 9, 2022

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 007de46 to blathers/backport-release-22.1-87562: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 22.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

DrewKimball added a commit to DrewKimball/cockroach that referenced this pull request Sep 12, 2022
This commit fixes a bug that was recently introduced in cockroachdb#87562 that can
cause an internal panic when remapping an ordering from the input to the
output of a `Project` operator. cockroachdb#87562 modified the logic to ensure that
the remapping only refers to columns from the required ordering; however,
it failed to add the optional columns to the allowed set of columns. This
could cause a panic if the provided ordering contains columns from the
optional set. This is fixed by adding the optional columns when remapping.

Fixes cockroachdb#87806

Release note: None (only on master)
craig bot pushed a commit that referenced this pull request Sep 13, 2022
87888: opt: include optional columns when remapping Project provided ordering r=DrewKimball a=DrewKimball

This commit fixes a bug that was recently introduced in #87562 that can cause an internal panic when remapping an ordering from the input to the output of a `Project` operator. #87562 modified the logic to ensure that the remapping only refers to columns from the required ordering; however, it failed to add the optional columns to the allowed set of columns. This could cause a panic if the provided ordering contains columns from the optional set. This is fixed by adding the optional columns when remapping.

Fixes #87806

Release note: None (only on master)

Co-authored-by: DrewKimball <[email protected]>
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.

roachtestsqlsmith: release-22.1: internal error: no output column equivalent
3 participants