Skip to content

MDEV-33959 mysqldump: dump sequences before tables across databases - #5683

Open
vaintroub wants to merge 1 commit into
10.11from
10.11-MDEV-33959
Open

vaintroub wants to merge 1 commit into
10.11from
10.11-MDEV-33959

Conversation

@vaintroub

Copy link
Copy Markdown
Member

Summary

mariadb-dump --all-databases (or --databases with several databases)
dumps databases in SHOW DATABASES order. If a table in one database
defaults a column to nextval() of a sequence living in a different
database, and that database sorts later, the resulting dump fails to
reload with Table 'db.seq' doesn't exist — the table gets created
before the sequence it depends on.

MDEV-21785 already dumps
sequences before tables within a single database, but that alone
doesn't help when the dependency crosses a database boundary.

Fix

Adds a sequences-first pre-pass (dump_all_sequences_in_db) that runs
over every database being dumped before any of them reaches the
existing per-database table-dump pass — mirroring the "dump all
tables, then all views" two-pass shape already used in this file for
views.

To keep output byte-for-byte unchanged for the common case of a
database with no sequences, the pre-pass only creates a database if it
turns out to actually own a sequence, and threads that fact through to
the table-dump pass so it skips re-creating the database and
re-dumping the sequences it already handled.

The pre-pass leaves --xml and the mysql system database to the
unchanged single-pass path: get_sequence_structure() isn't XML-aware,
and mysql never owns user sequences in practice but has a
LOG_OUTPUT save/restore that only closes in the table pass.

Testing

  • New regression test in mysql-test/main/mysqldump.test covering both
    --all-databases and --databases db test (explicit list, dependent
    database listed before the one owning the sequence), asserting the
    table's DEFAULT nextval(...) survives a dump/reload round-trip.
  • sql_sequence.mysqldump (the MDEV-21785 regression test) still passes.
  • sysschema.mysqldump, main.mysqlcheck pass.
  • Full main.mysqldump file passes (verified past one pre-existing,
    unrelated environment-specific failure in this local WSL/NTFS setup —
    a World-writable config file check that also fails identically on
    the unmodified base branch).
  • Reviewed with pr-review-toolkit:code-reviewer and
    :silent-failure-hunter; addressed unchecked allocations, an --xml
    output regression, and thin test coverage of the --databases
    (non---all-databases) path that they flagged.

Note for forward-merge

On 11.8+ (main), client/mysqldump.c was renamed to
client/mysqldump.cc by MDEV-32216, so this patch will need manual
conflict resolution on that rename during the forward-merge.

🤖 Generated with Claude Code

mariadb-dump --all-databases (or --databases with several databases)
dumps databases in SHOW DATABASES order. If a table in one database
defaults a column to nextval() of a sequence living in a different
database, and that database sorts later, the resulting dump fails to
reload with "Table 'db.seq' doesn't exist" -- the table gets created
before the sequence it depends on.

MDEV-21785 already dumps sequences before tables within a single
database, but that alone doesn't help when the dependency crosses a
database boundary.

Fix by adding a sequences-first pre-pass (dump_all_sequences_in_db)
that runs over every database being dumped before any of them reaches
the existing per-database table-dump pass, mirroring the "dump all
tables, then all views" two-pass shape already used in this file for
views. To keep output byte-for-byte unchanged for the common case of a
database with no sequences, the pre-pass only creates a database if it
turns out to actually own a sequence, and threads that fact through to
the table-dump pass so it skips re-creating the database and
re-dumping the sequences it already handled.

The pre-pass leaves --xml and the "mysql" system database to the
unchanged single-pass path: get_sequence_structure() isn't XML-aware,
and "mysql" never owns user sequences in practice but has a LOG_OUTPUT
save/restore that only closes in the table pass.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants