8000 sql: DROP DATABASE CASCADE leaves tables which utilize sequences · Issue #50997 · cockroachdb/cockroach · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
sql: DROP DATABASE CASCADE leaves tables which utilize sequences #50997
Closed
@ajwerner

Description

@ajwerner

Describe the problem

It seems that tables which utilize sequences are not properly dropped. It is interesting to note that this is only a problem if the sequence is also in the database being dropped. If the sequence is part of a different database, it will not be dropped.

The root cause of that issue seems to be filterCascadedTables, which seems to be designed for table-view / view-view dependency relationships so that we don't try to unnecessarily drop views that would be dropped in other table/view's drop cascade. This doesn't seem to play well with sequences, which don't drop the tables that depend on them during cascade (aside we currently don't support cascade for sequences).

// filterCascadedTables takes a list of table descriptors and removes any
// descriptors from the list that are dependent on other descriptors in the
// list (e.g. if view v1 depends on table t1, then v1 will be filtered from
// the list).
func (p *planner) filterCascadedTables(ctx context.Context, tables []toDelete) ([]toDelete, error) {

To Reproduce

Set up CockroachDB cluster using v20.1.3 or earlier in the 20.1 release and do the following:

CREATE DATABASE good_stuff;
CREATE TABLE good_stuff.data_to_backup ();

SET experimental_serial_normalization = 'sql_sequence';
CREATE DATABASE to_corrupt;
USE to_corrupt;
CREATE TABLE uses_sequence ( k SERIAL PRIMARY KEY );

USE good_stuff;
DROP DATABASE to_corrupt CASCADE;
BACKUP DATABASE good_stuff to 'nodelocal://1/this_wont_work';

ERROR: table "uses_sequence" has unknown ParentID 57

At this point we'll have failed to drop the table uses_sequence and manually repairing it is painful.

Expected behavior
The drop will work.

Additional context

It's not yet clear whether this bug affects earlier versions.

Metadata

Metadata

Assignees

Labels

A-schema-descriptorsRelating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-erroneous-edge-caseDatabase produces or stores erroneous data without visible error/warning, in rare edge cases.S-3-wrong-metadataIssues causing erroneous metadata or monitoring stats to be returned.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0