mariadb/mysql-test/suite/innodb_fts/r
Aleksey Midenkov a518e1dd42 MDEV-20865 Store foreign key info in TABLE_SHARE
1. Access foreign keys via TABLE_SHARE::foreign_keys and
   TABLE_SHARE::referenced_keys;

   foreign_keys and referenced_keys are lists in TABLE_SHARE.

2. Remove handler FK interface:

   - get_foreign_key_list()
   - get_parent_foreign_key_list()
   - referenced_by_foreign_key()

3. Invalidate referenced shares on:

   - RENAME TABLE
   - DROP TABLE
   - RENAME COLUMN
   - ADD FOREIGN KEY

   When foreign table is created or altered by the above operations
   all referenced shares are closed. This blocks the operation while
   any referenced shares are used (when at least one its TABLE
   instance is locked).

4. Update referenced shares on:

   - CREATE TABLE

   On CREATE TABLE add items to referenced_keys of referenced
   shares. States of referenced shares are restored in case of errors.

5. Invalidate foreign shares on:

   - RENAME TABLE
   - RENAME COLUMN

   The above-mentioned blocking takes effect.

6. Check foreign/referenced shares consistency on:

   - CHECK TABLE

7. Temporary change until MDEV-21051:

   InnoDB fill foreign key info at handler open().

FOREIGN_KEY_INFO is refactored to FK_info holding Lex_cstring.

On first TABLE open FK_info is loaded from storage engine into
TABLE_SHARE. All referenced shares (if any exists) are closed. This
leads to blocking of first time foreign table open while referenced
tables are used.

MDEV-21311 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 it 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.

MDEV-21051 datadict refactorings

- Move read_extra2() to datadict.cc
- Refactored extra2_fields to Extra2_info
- build_frm_image() readability

MDEV-21051 build_table_shadow_filename() refactoring

mysql_prepare_alter_table() leaks fixes

MDEV-21051 amend system tables locking restriction

Table mysql.help_relation has foreign key to mysql.help_keyword. On
bootstrap when help_relation is opened, it preopens help_keyword for
READ and fails in lock_tables_check().

If system table is opened for write then fk references are opened for
write.

Related to: Bug#25422, WL#3984
Tests: main.lock

MDEV-21051 Store and read foreign key info into/from 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. Shadow FRM is new FRM file that replaces the old one.

CREATE TABLE workflow:

  1. Foreign_key is constructed in parser, placed into
     alter_info->key_list;

  2. mysql_prepare_create_table() translates them to FK_info, assigns
     foreign_id if needed;

  3. build_frm_image() writes two FK_info lists into FRM's extra2
     section, for referenced keys it stores only table names (hints);

  4. init_from_binary_frm_image() parses extra2 section and fills
     foreign_keys and referenced_keys of TABLE_SHARE.

     It restores referenced_keys by reading hint list of table names,
     opening corresponding shares and restoring FK_info from their
     foreign_keys. Hints resolution is done only when initializing
     non-temporary shares. Usually temporary share has different
     (temporary) name and it is impossible to resolve foreign keys by
     that name (as we identify them by both foreign and referenced
     table names). Another not unimportant reason is performance: this
     saves spare share acquisitions.

ALTER TABLE workflow:

  1. Foreign_key is constructed in parser, placed into
     alter_info->key_list;

  2. mysql_prepare_alter_table() prepares action lists and share list
     of foreigns/references;

  3. mysql_prepare_alter_table() locks list of foreigns/references by
     MDL_INTENTION_EXCLUSIVE, acquires shares;

  4. prepare_create_table() converts key_list into FK_list, assigns
     foreign_id;

  5. shadow FRM of altered table is created;

  6. data is copied;

  7. altered table is locked by MDL_EXCLUSIVE;

  8. fk_handle_alter() processes action lists, creates FK backups,
     modifies shares, writes shadow FRMs;

  9. altered table is closed;

  10. shadow FRMs are installed;

  11. altered table is renamed, FRM backup deleted;

  12. (TBD in MDEV-21053) shadow FRMs installation log closed, backups
      deleted;

On FK backup system:

In case of failed DDL operation all shares that was modified must be
restored into original state. This is done by FK_ddl_backup (CREATE,
DROP), FK_rename_backup (RENAME), FK_alter_backup (ALTER).

On STL usage:

STL is used for utility not performance-critical algorithms, core
structures hold native List. A wrapper was made to convert STL
exception into bool error status or NULL value.

MDEV-20865 fk_check_consistency() in CHECK TABLE

Self-refs fix

Test table_flags fix: "debug" deviation is now gone.

FIXMEs: +16 -1
2025-09-02 13:24:36 +03:00
..
basic.result MDEV-25004 Missing row in FTS_DOC_ID_INDEX during DELETE HISTORY 2022-12-27 00:02:02 +03:00
bug_32831765.result MDEV-27913 innodb_ft_cache_size max possible value (80000000) is too small for practical purposes 2022-02-24 22:41:23 +05:30
concurrent_insert.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
crash_recovery.result cleanup: key algorithm vs key flags 2024-11-05 14:00:47 -08:00
create,orig.rdiff Merge 10.6 into 10.11 2024-02-14 16:12:53 +02:00
create.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
foreign_key_check.result MDEV-20865 Store foreign key info in TABLE_SHARE 2025-09-02 13:24:36 +03:00
foreign_key_update.result MDEV-28933: Per-table unique FOREIGN KEY constraint names 2025-07-08 12:30:27 +03:00
ft_result_cache_limit.result Remove deprication from mariadbd --debug 2023-11-28 16:33:22 +02:00
fts_kill_query.result Merge 10.1 into 10.2 2018-08-02 08:19:57 +03:00
fts_sync_commit_resiliency.result MDEV-34057 Inconsistent FTS state in concurrent scenarios 2024-06-06 19:09:13 +05:30
fulltext.result Merge 11.4 into 11.7 2024-12-02 17:51:17 +02:00
fulltext2.result Merge 10.3 into 10.4 2022-12-13 11:37:33 +02:00
fulltext3.result Merge 10.1 into 10.2 2019-03-06 15:15:59 +02:00
fulltext_cache.result
fulltext_distinct.result
fulltext_left_join.result
fulltext_misc.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
fulltext_multi.result
fulltext_order_by.result MDEV-34679 ER_BAD_FIELD uses non-localizable substrings 2024-10-17 21:37:37 +02:00
fulltext_update.result
fulltext_var.result MDEV-16172: Enable skipped tests 2018-05-17 09:37:01 +03:00
index_table.result MDEV-36061 Incorrect error handling on DDL with FULLTEXT INDEX 2025-02-13 16:28:06 +01:00
innodb-fts-ddl,vers.rdiff Merge branch '11.1' into 11.2 2024-04-09 12:12:33 +02:00
innodb-fts-ddl,vers_trx.rdiff Merge branch '11.1' into 11.2 2024-04-09 12:12:33 +02:00
innodb-fts-ddl.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
innodb-fts-fic,vers.rdiff MDEV-30528 CREATE FULLTEXT INDEX assertion failure WITH SYSTEM VERSIONING 2024-02-12 16:52:55 +01:00
innodb-fts-fic,vers_trx.rdiff MDEV-30528 CREATE FULLTEXT INDEX assertion failure WITH SYSTEM VERSIONING 2024-02-12 16:52:55 +01:00
innodb-fts-fic.result MDEV-15253: Default optimizer setting changes for MariaDB 10.4 2018-12-09 09:22:00 +05:30
innodb_ft_aux_table.result MDEV-36420 Assertion failure in SET GLOBAL innodb_ft_aux_table 2025-03-28 09:05:20 +02:00
innodb_fts_large_records.result
innodb_fts_misc.result MDEV-35082 HANDLER with FULLTEXT keys is not always rejected 2024-10-08 18:20:13 +02:00
innodb_fts_misc_1.result Merge branch '12.0' into 12.1 2025-08-03 15:01:09 +02:00
innodb_fts_multiple_index.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
innodb_fts_plugin.result Merge 10.5 into 10.6 2022-08-30 13:01:16 +03:00
innodb_fts_proximity.result Merge branch '10.11' into 11.0 2023-12-19 15:53:18 +01:00
innodb_fts_result_cache_limit.result MDEV-13134 Introduce ALTER TABLE attributes ALGORITHM=NOCOPY and ALGORITHM=INSTANT 2018-05-07 14:58:11 +05:30
innodb_fts_stopword_charset.result Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
innodb_fts_transaction.result MDEV-21921 Make transaction_isolation and transaction_read_only into system variables 2023-04-12 11:04:29 +10:00
limit_union.result MDEV-13626 Merge InnoDB test cases from MySQL 5.7 2023-11-08 12:17:14 +02:00
misc.result MariaDB 11.4.4 release 2024-11-08 07:17:00 +01:00
misc_1.result MDEV-28933: Per-table unique FOREIGN KEY constraint names 2025-07-08 12:30:27 +03:00
misc_debug,vers.rdiff Merge 10.5 into 10.6 2024-02-13 20:42:59 +02:00
misc_debug,vers_trx.rdiff Merge 10.5 into 10.6 2024-02-13 20:42:59 +02:00
misc_debug.result MDEV-20865 Store foreign key info in TABLE_SHARE 2025-09-02 13:24:36 +03:00
misc_debug2.result Merge 10.5 into 10.6 2022-10-12 12:14:13 +03:00
multiple_index.result Merge branch '11.5' into 11.6 2024-08-21 15:13:47 +02:00
opt.result Merge branch '10.11' into 11.0 2023-12-19 15:53:18 +01:00
phrase.result MDEV-13626 Merge InnoDB test cases from MySQL 5.7 2023-11-08 12:17:14 +02:00
plugin_debug.result MDEV-14231 MATCH() AGAINST( IN BOOLEAN MODE), results mismatch 2024-08-13 15:22:09 +05:30
result_cache_limit.result MDEV-13626 Merge InnoDB test cases from MySQL 5.7 2023-11-08 12:17:14 +02:00
savepoint.result MDEV-24035 Failing assertion: UT_LIST_GET_LEN(lock.trx_locks) == 0 causing disruption and replication failure 2024-12-12 18:02:00 +02:00
stopword,vers.rdiff MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
stopword.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
subexpr.result MDEV-13626 Merge InnoDB test cases from MySQL 5.7 2023-11-08 12:17:14 +02:00
sync.result MDEV-30996 insert.. select in presence of full text index freezes all other commits at commit time 2023-04-24 11:06:56 +05:30
sync_block.result Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
sync_ddl.result MDEV-30528 CREATE FULLTEXT INDEX assertion failure WITH SYSTEM VERSIONING 2024-02-12 16:52:55 +01:00
versioning,prepare.result MDEV-25004 Missing row in FTS_DOC_ID_INDEX during DELETE HISTORY 2022-12-27 00:02:02 +03:00
versioning.result Merge 10.6 into 10.7 2023-01-04 14:52:25 +02:00