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/memo: silence error in factorOutVirtualCols for mutation columns #139388

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

michae2
Copy link
Collaborator

@michae2 michae2 commented Jan 18, 2025

Mutation columns (such as those being dropped by an ALTER TABLE DROP COLUMN statement) exist in table metadata, but might not necessarily have an associated computed column expression. This is because optbuilder.(*Builder).addComputedColsForTable usually skips over mutation columns.

In memo.(*statisticsBuilder).factorOutVirtualCols we gather all the expressions for virtual computed columns of the table. We were failing an assertion if we couldn't find the expression for a column. This is fine, however, because factorOutVirtualCols only powers an optimization in statistics builder and is not necessary for correctness.

This commit silences the assertion if the column is a mutation column, and futhermore, only checks it in test builds otherwise, because ideally we wouldn't want to miss the optimization for non-mutation columns.

Fixes: #129405
Fixes: #138147
Fixes: #138809

Release note (bug fix): Fix a rare bug in which a query might fail with error "could not find computed column expression for column in table" while dropping a virtual computed column from the table. This bug was introduced in v23.2.4.

@michae2 michae2 requested review from fqazi, yuzefovich and a team January 18, 2025 01:06
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@michae2 michae2 added backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.2.x Flags PRs that need to be backported to 24.2 backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.1.x Flags PRs that need to be backported to 25.1 labels Jan 18, 2025
Copy link
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.

Nice job figuring this out! :lgtm:

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


-- commits line 24 at r1:
nit: consider mentioning that the bug was introduced in 24.1 version.

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Nice work! :lgtm_strong:

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

Mutation columns (such as those being dropped by an ALTER TABLE DROP
COLUMN statement) exist in table metadata, but might not necessarily
have an associated computed column expression. This is because
`optbuilder.(*Builder).addComputedColsForTable` usually skips over
mutation columns.

In `memo.(*statisticsBuilder).factorOutVirtualCols` we gather all the
expressions for virtual computed columns of the table. We were failing
an assertion if we couldn't find the expression for a column. This is
fine, however, because `factorOutVirtualCols` only powers an
optimization in statistics builder and is not necessary for correctness.

This commit silences the assertion if the column is a mutation column,
and futhermore, only checks it in test builds otherwise, because ideally
we wouldn't want to miss the optimization for non-mutation columns.

Fixes: cockroachdb#129405
Fixes: cockroachdb#138147
Fixes: cockroachdb#138809

Release note (bug fix): Fix a rare bug in which a query might fail with
error "could not find computed column expression for column in table"
while dropping a virtual computed column from the table. This bug was
introduced in v23.2.4.
@michae2 michae2 added the backport-23.2.x Flags PRs that need to be backported to 23.2. label Jan 25, 2025
Copy link
Collaborator Author

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r=yuzefovich,fqazi

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


-- commits line 24 at r1:

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: consider mentioning that the bug was introduced in 24.1 version.

Ah, good call. Looks like it was 23.2.4.

craig bot pushed a commit that referenced this pull request Jan 25, 2025
139388: opt/memo: silence error in factorOutVirtualCols for mutation columns r=yuzefovich,fqazi a=michae2

Mutation columns (such as those being dropped by an ALTER TABLE DROP COLUMN statement) exist in table metadata, but might not necessarily have an associated computed column expression. This is because `optbuilder.(*Builder).addComputedColsForTable` usually skips over mutation columns.

In `memo.(*statisticsBuilder).factorOutVirtualCols` we gather all the expressions for virtual computed columns of the table. We were failing an assertion if we couldn't find the expression for a column. This is fine, however, because `factorOutVirtualCols` only powers an optimization in statistics builder and is not necessary for correctness.

This commit silences the assertion if the column is a mutation column, and futhermore, only checks it in test builds otherwise, because ideally we wouldn't want to miss the optimization for non-mutation columns.

Fixes: #129405
Fixes: #138147
Fixes: #138809

Release note (bug fix): Fix a rare bug in which a query might fail with error "could not find computed column expression for column in table" while dropping a virtual computed column from the table. This bug was introduced in v23.2.4.

Co-authored-by: Michael Erickson <[email protected]>
@craig
Copy link
Contributor

craig bot commented Jan 25, 2025

Build failed:

@michae2
Copy link
Collaborator Author

michae2 commented Jan 26, 2025

looks like an infra flake, trying again...

bors r=yuzefovich,fqazi

Copy link

blathers-crl bot commented Jan 26, 2025

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #129405: branch-release-23.2, branch-release-24.2, branch-release-24.3, branch-release-25.1.


Issue #138147: branch-release-23.2, branch-release-24.1, branch-release-24.2, branch-release-25.1.


Issue #138809: branch-release-23.2, branch-release-24.1, branch-release-24.2, branch-release-25.1.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Copy link

blathers-crl bot commented Jan 26, 2025

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 d9eebcf to blathers/backport-release-23.2-139388: 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 23.2.x failed. See errors above.


error creating merge commit from d9eebcf to blathers/backport-release-24.1-139388: 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 24.1.x failed. See errors above.


error creating merge commit from d9eebcf to blathers/backport-release-24.2-139388: 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 24.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.2.x Flags PRs that need to be backported to 23.2. backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.2.x Flags PRs that need to be backported to 24.2 backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.1.x Flags PRs that need to be backported to 25.1
Projects
None yet
4 participants