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

release-20.2: sql: prevent DROP SCHEMA CASCADE from droping types with references #61259

Merged
merged 2 commits into from
Mar 2, 2021

Conversation

ajwerner
Copy link
Contributor

@ajwerner ajwerner commented Mar 1, 2021

Backport 2/2 commits from #59281.

/cc @cockroachdb/release


Before this patch, a DROP SCHEMA CASCADE could cause database corruption
by dropping types which were referenced by other tables. This would lead to
bad errors like:

ERROR: object already exists: desc 687: type ID 685 in descriptor not found: descriptor not found
SQLSTATE: 42710

And doctor errors like:

   Table 687: ParentID  50, ParentSchemaID 29, Name 't': type ID 685 in descriptor not found: descriptor not found

Fixes #59021.

Release note (bug fix): Fixed a bug where DROP SCHEMA ... CASCADE could
result in types which are referenced being dropped.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Before this patch, a DROP SCHEMA CASCADE could cause database corruption
by dropping types which were referenced by other tables. This would lead to
bad errors like:

```
ERROR: object already exists: desc 687: type ID 685 in descriptor not found: descriptor not found
SQLSTATE: 42710
```

And doctor errors like:
```
   Table 687: ParentID  50, ParentSchemaID 29, Name 't': type ID 685 in descriptor not found: descriptor not found
```

Fixes cockroachdb#59021.

Release note (bug fix): Fixed a bug where `DROP SCHEMA ... CASCADE` could
result in types which are referenced being dropped.
Before this commit we'd errantly skip dropping type references under a false
assumption that all the types were also being dropped. This could lead to
dangling backreferences to types from tables in other schemas.

Release note (bug fix): Fixed a bug whereby dropping a schema with a table
that used a user-defined type which was not being dropped (because it is
in a different schema) would result in a descriptor corruption due to a
dangling back-reference to a dropped table on the type descriptor.
Copy link
Contributor

@thoszhang thoszhang left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r1, 2 of 2 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @postamar)

@ajwerner ajwerner merged commit 1b65b2c into cockroachdb:release-20.2 Mar 2, 2021
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.

None yet

3 participants