Conversation
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]>
vaintroub
force-pushed
the
10.11-MDEV-33959
branch
from
September 16, 2026 08:21
06a98ed to
e97be86
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mariadb-dump --all-databases(or--databaseswith several databases)dumps databases in
SHOW DATABASESorder. If a table in one databasedefaults a column to
nextval()of a sequence living in a differentdatabase, and that database sorts later, the resulting dump fails to
reload with
Table 'db.seq' doesn't exist— the table gets createdbefore 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 runsover 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
--xmland themysqlsystem database to theunchanged single-pass path:
get_sequence_structure()isn't XML-aware,and
mysqlnever owns user sequences in practice but has aLOG_OUTPUTsave/restore that only closes in the table pass.Testing
mysql-test/main/mysqldump.testcovering both--all-databasesand--databases db test(explicit list, dependentdatabase 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.mysqlcheckpass.main.mysqldumpfile passes (verified past one pre-existing,unrelated environment-specific failure in this local WSL/NTFS setup —
a
World-writable config filecheck that also fails identically onthe unmodified base branch).
pr-review-toolkit:code-reviewerand:silent-failure-hunter; addressed unchecked allocations, an--xmloutput 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.cwas renamed toclient/mysqldump.ccby MDEV-32216, so this patch will need manualconflict resolution on that rename during the forward-merge.
🤖 Generated with Claude Code