Description
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).
cockroach/pkg/sql/drop_database.go
Lines 273 to 277 in deb468b
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.