Details
Description
mysqldump treads sequences the same as other tables, dumping all of them in alphabetical order. A sequence may provide the default value for a column on another table though. So if the table name alphabetically comes before the sequence name, the tables CREATE statement will be in the dump output before the CREATE for the sequence table, and so the table creation will fail as it refers to a sequence not created yet.
How to reproduce:
- create sequence and table:
CREATE SEQUENCE b;
|
CREATE TABLE a (id INT PRIMARY KEY DEFAULT (NEXT VALUE FOR b));
|
- dump database with mysqldump, then restore into an empty database
- restore will fail when trying to create table `a`:
ERROR 1146 (42S02) at line ...: Table 'test.b' doesn't exist
Attachments
Issue Links
- relates to
-
MDEV-33959 mysqldump of all databases cannot be loaded if a table uses a sequence from another schema
-
- Open
-
I can add to that. In such a case, SHOW CREATE TABLE a refers to b by fully qualified name, e.g.:
So, if the dump is restored into a different database, there will be other problems – either an error if the sequence in the initial schema no longer exists, or the table will end up referencing a wrong sequence.
Something needs to be done (at least about the initially reported problem), but I don't know what should be a fix for either of this – either we should have a variable which temporarily suppresses the reference check, like it happens with foreign keys, or the tricky logic with fake temporary tables, as it happens with views, or recognizing sequences (which might also be needed due to
MDEV-21786) and dumping them first, or something else.