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

tabledesc: forbid computed columns from having DEFAULT expressions #73090

Merged
merged 2 commits into from
Nov 24, 2021

Conversation

postamar
Copy link
Contributor

Previously, we didn't have a table descriptor validation check to ensure
that computed columns didn't also have DEFAULT expressions. It is
therefore possible that clusters and cluster backups exist in production
which contain tables with such columns. This commit therefore fixes this
bug by adding the missing validation check, and by removing default
expressions from computed columns when necessary after deserializing
a descriptor protobuf.

Fixes #72881.

Release note (sql change, bug fix): fixes a bug which allowed computed
columns to also have DEFAULT expressions.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@postamar postamar marked this pull request as ready for review November 23, 2021 22:27
@postamar postamar requested a review from a team November 23, 2021 22:27
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Thoughts on adding parallel testing for ON UPDATE? If so, do it as a separate commit which you don't backport to 21.1.backport has tools to pick commits.

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


pkg/sql/logictest/testdata/logic_test/computed, line 1054 at r1 (raw file):

statement error computed column "v" cannot also have a DEFAULT expression
ALTER TABLE t69327 ALTER COLUMN v SET DEFAULT 'foo'

what's the pgcode here? Are we only catching this with validation? Ideally not.

Copy link
Contributor Author

@postamar postamar left a comment

Choose a reason for hiding this comment

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

Sure, I can add a test for ON UPDATE in a separate commit. It wouldn't hurt.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/logictest/testdata/logic_test/computed, line 1054 at r1 (raw file):

Previously, ajwerner wrote…
statement error computed column "v" cannot also have a DEFAULT expression
ALTER TABLE t69327 ALTER COLUMN v SET DEFAULT 'foo'

what's the pgcode here? Are we only catching this with validation? Ideally not.

No, because it's one of these cases I don't like where the validation function serves a dual purpose of (1) actually validating the descriptor and (2) validating the statement's effects. For some reason I don't understand, a lot of the errors which can be thrown in this way simply don't have pgcodes. If we care about pgcodes let's please address that in a separate issue and PR I feel this is out of scope here.

Copy link
Contributor

@ajwerner ajwerner 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 6 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @postamar)


pkg/sql/logictest/testdata/logic_test/computed, line 1054 at r1 (raw file):

Previously, postamar (Marius Posta) wrote…

No, because it's one of these cases I don't like where the validation function serves a dual purpose of (1) actually validating the descriptor and (2) validating the statement's effects. For some reason I don't understand, a lot of the errors which can be thrown in this way simply don't have pgcodes. If we care about pgcodes let's please address that in a separate issue and PR I feel this is out of scope here.

At this point, I’m of the mindset that have two such checks is fine. The validation level check ought not to carry a pgcode and ought to be a defense in depth mechanism that additionally protects us in cases like restore and upgrades. The statement time checks give better errors to the user and carry the intention. It is duplication, but it’s duplication that I think has served us well thus far.

Fine with not doing it now. Were the randomized schema change workload in good shape, it’d reveal the missing pgcode.

Marius Posta added 2 commits November 24, 2021 10:22
Previously, we didn't have a table descriptor validation check to ensure
that computed columns didn't also have DEFAULT expressions. It is
therefore possible that clusters and cluster backups exist in production
which contain tables with such columns. This commit therefore fixes this
bug by adding the missing validation check, and by removing default
expressions from computed columns when necessary after deserializing
a descriptor protobuf.

Fixes cockroachdb#72881.

Release note (sql change, bug fix): fixes a bug which allowed computed
columns to also have DEFAULT expressions.
This commit adds a missing test in our validation test suite to cover
the forbidden case of a computed column which also has an ON UPDATE
expression set.

Release note: None
Copy link
Contributor

@ajwerner ajwerner 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 @ajwerner and @postamar)

@postamar
Copy link
Contributor Author

Thanks for the review!

bors r+

@craig craig bot merged commit 8fa3a38 into cockroachdb:master Nov 24, 2021
@craig
Copy link
Contributor

craig bot commented Nov 24, 2021

Build succeeded:

@blathers-crl
Copy link

blathers-crl bot commented Nov 24, 2021

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 5b4ce82 to blathers/backport-release-21.1-73090: 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 21.1.x failed. See errors above.


error creating merge commit from 5b4ce82 to blathers/backport-release-21.2-73090: 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 21.2.x failed. See errors above.


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

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,catalog: should not allow a column definition to have a computed column and default expression
3 participants