Details
-
Technical task
-
Status: In Review (View Workflow)
-
Critical
-
Resolution: Unresolved
-
None
Description
Add TABLE_SHARE::foreign_keys and TABLE_SHARE::referenced_keys as pointers to List<FOREIGN_KEY_INFO>.
Remove handler foreign key interface: get_foreign_key_list(), get_parent_foreign_key_list(), referenced_by_foreign_key().
Remove cached TABLE_SHARE objects of referenced tables when foreign table is dropped, renamed or altered (add foreign key, rename column of foreign key).
Remove cached TABLE_SHARE objects of foreign tables when referenced table is renamed or altered (rename column of referenced key).
Debug build: check consistency between opened foreign and referenced tables on table flush.
Store foreign keys into FRM files
1. Introduce Foreign_key_io class which creates/parses binary stream containing foreign key structures. Referenced tables store there only hints about foreign tables (their db and name), they restore full info from the corresponding tables.
Foreign_key_io is stored under new EXTRA2_FOREIGN_KEY_INFO field in extra2 section of FRM file.
2. Modify mysql_prepare_create_table() to generate names for foreign keys. Until InnoDB storage of foreign keys is removed, FK names must be unique across the database: the FK name must be based on table name.
3. Keep stored data in sync on DDL changes. Referenced tables update their foreign hints after following operations on foreign tables:
RENAME TABLE
DROP TABLE
CREATE TABLE
ADD FOREIGN KEY
DROP FOREIGN KEY
Foreign tables update their foreign info after following operations on referenced tables:
RENAME TABLE
RENAME COLUMN
4. To achieve 3. there must be ability to rewrite extra2 section of FRM file without full reparse. FRM binary is built from primary structures like HA_CREATE_INFO and cannot be built from TABLE_SHARE.
Use shadow write and rename like fast_alter_partition_table() does.
Converge Foreign_key and supplemental generated Key together
mysql_prepare_create_table() does data validation and such utilities as automatic name generation. But it does that only for indexes and ignores Foreign_key objects. Now as Foreign_key data needs to be stored in FRM files as well this processing must be done for them like for any other Key objects.
Replace Key::FOREIGN_KEY type with Key::foreign flag of type Key::MULTIPLE and Key::generated set to true. Construct one object with Key::foreign == true instead of two objects of type Key::FOREIGN_KEY and Key::MULTIPLE.
Attachments
Issue Links
- blocks
-
MDEV-21052 InnoDB foreign key refactoring for TABLE_SHARE::foreign_keys
- Stalled
-
MDEV-21652 FK migration from old version
- Stalled
- causes
-
MDEV-33741 Server crashes on double rename of table if there are references on it
- Open
-
MDEV-33780 Server crashes on renaming of table if table is locked
- Closed
- is blocked by
-
MDEV-21049 Segfault in create federatedx table with empty hostname
- Closed
- is duplicated by
-
MDEV-21051 Store and read foreign key info into/from FRM files
- Closed
-
MDEV-21311 Converge Foreign_key and supplemental generated Key together
- Closed
-
MDEV-35303 Store foreign keys, even not supported
- Closed
- relates to
-
MDEV-16983 Application-time periods: foreign key
- In Review
-
MDEV-20874 Wrong handling of 'table was dropped' error in purge thread
- Stalled