-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
MDEV-28933: Per-table unique FOREIGN KEY constraint names #3960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out that we can simply use decimal ASCII numbers for the generated constraint names; an ibfk_
prefix would not add any value. I will revise this accordingly.
229e39a
to
75eb1e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we address upgrade scenario? Does rename table from lower version works? Please point me to any test case.
Before MySQL 4.0.18, user-specified constraint names were ignored. Starting with MySQL 4.0.18, the specified constraint name was prepended with the schema name and '/'. Now we are transforming into a format where the constraint name is prepended with the dict_table_t::name and the impossible UTF-8 sequence 0xff. Generated constraint names will be ASCII decimal numbers. On upgrade, old FOREIGN KEY constraint names will be displayed without any schema name prefix. They will be updated to the new format on DDL operations. dict_foreign_t::sql_id(): Return the SQL constraint name without any schemaname/tablename\377 or schemaname/ prefix. row_rename_table_for_mysql(), dict_table_rename_in_cache(): Simplify the logic: Just rename constraints to the new format. dict_table_get_foreign_id(): Replaces dict_table_get_highest_foreign_id(). row_delete_constraint(): Try to drop all 3 constraint name variants.
(cherry picked from commit 402595f)
Upgrades can’t easily be covered by |
Description
dict_foreign_t::sql_id()
: Return the SQL constraint name. Before MySQL 4.0.18, user-specified constraint names were ignored. Starting with MySQL 4.0.18, the specified constraint name was prepended with the schema name and/
. Now we are transforming into a format where the constraint name is prepended with thedict_table_t::name
and the impossible UTF-8 sequence 0xff. Generated constraint names will be of the form1
,2
, …, internally stored asschemaname/tablename\3771
,schemaname/tablename\3772
, ….Release Notes
InnoDB
FOREIGN KEY
constraint names need not be unique within a schema any more, but only unique within a table. Auto-generated constraint names will be of the form1
,2
, ….The
INFORMATION_SCHEMA
viewsINNODB_SYS_FOREIGNS
andINNODB_SYS_FOREIGN_COLS
will only display the user-specified constraint name, no longer anydatabasename/
prefix.How can this PR be tested?
Upgrade testing
Before starting the first test step in GDB, specify with
file
an oldermariadbd
executable that does not contain these changes. For the subsequent test steps, specify the updatedmariadbd
executable. The test will pass but display a warning during the execution ofALTER TABLE t1 ENGINE=InnoDB, ALGORITHM=COPY
:It turns out that this warning is expected by the test, but
call mtr.add_suppression()
apparently has no effect when running./mtr --manual-gdb
.For some additional diagnostics, you can apply the following patch:
This will correctly display the constraint names
pc120
throughpc1
even though they were internally stored astest/pc120
throughtest/pc1
.Downgrade testing
If you run the test
innodb.innodb-fk
as it is adjusted in this PR, and run the unmodifiedmariadbd
on the 3rd test step (the server is being started 3 times for running the test), then it will obviously fail because a generated constraint has a different name:This happens even if you run the modified test against the old server all the time. We can work around this by commenting out the problematic statement:
If we run the old
mariadbd
against that for all test steps, there will be not only result differences for the generated constraint names, but also the following:If we run this modified test with
./mtr --manual-gdb innodb.innodb-fk
and run the updated server only for the first or second step or both, the test will work in the same way.This confirms that
DROP TABLE
can drop not only the old-format constraints in the updated server, but also the new-format constraints in the old server. AlsoDROP DATABASE schemaname
is expected to work, because theSYS_FOREIGN.ID
andSYS_FOREIGN_COLS.ID
will continue to start withschemaname/
. But,ALTER TABLE…DROP FOREIGN KEY
definitely is not going to work after a downgrade, because it is not expected to be possible for the user to input the invalid UTF-8 sequence 0xff.Basing the PR against the correct MariaDB version
main
branch.PR quality check