-
Dmitry Lenev authored
"Implement INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as a system views over dictionary tables." WL#6049 Meta-data locking for FOREIGN KEY tables. The primary goal of this task is to ensure that foreign keys checks, which are performed by storage engine (e.g. InnoDB), do not access tables which are concurrently modified by DDL statements. Such an isolation of FK checks/actions from DDL statements can be achieved by ensuring that FKs are taken into account when we acquire metadata "operation-type aware" locks for DML and DDL statements. This is done by: 1) Extending prelocking algorithm/process to take into account foreign keys and acquire metadata locks which are appropriate for the operations involving them (checks in parent or child tables take SR lock, cascading updates or deletes take SW lock, LOCK TABLES takes SRO or SNRW locks correspondingly). 2) Changing DDL statements which add or drop foreign keys to the system to X lock on FK parent table before child table definition changes. 3) Changing DDL statements which otherwise affect FK-related metadata (like RENAME TABLE on child or parent table) to acquire X lock on tables participating in the FK. 4) Changing ALTER TABLE to acquire SU metadata lock on parent tables for newly added FKs so it can properly check them. The secondary goal of this task is to ensure that DDL on parent tables correctly updates foreign key metadata. Specifically we now correctly update the following metadata: I) Name of unique constraint in parent table for the FK. Old code misused DD.FOREIGN_KEYS.UNIQUE_CONSTRAINT_ID to store id of supporting index for the FK in the child table. This WL replaces this column with VARCHAR(64) field which stores name of unique key in the parent table used for the FK -- UNIQUE_CONSTRAINT_NAME. DDL statements code was adjusted to keep this value correct on changes to parent table definition. II) Referenced schema and table names (DD.FOREIGN_KEYS.REFERENCED_TABLE_SCHEMA and DD.FOREIGN_KEYS.REFERENCED_TABLE_NAME) during ALTER TABLE RENAME/ RENAME TABLES on parent tables. This WL introduces some new temporary limitations: - We temporary disallow renaming of parent columns in FKs. - ALTER TABLE ... ALGORITHM=COPY acquires SRO locks on the parent tables for newly added FKs. This is temporary workaround for InnoDB SE making information about such FKs to other connections before DDL commit. - We disallow ALTER TABLE ... RENAME under LOCK TABLES on tables which have or will have foreign keys. This limitation should be weakened soon. WL#11059 Implement INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as a system views over dictionary tables. This patch implements I_S.REFERENTIAL_CONSTRAINTS as a system view over data dictionary tables, and remove 5.7 code that uses a temporary table to represent I_S view. Following changes are made in the patch: * Define a system view over data dictionary tables representing I_S.REFERENTIAL_CONSTRAINTS. * Remove 5.7 code from sql_show.cc for I_S.REFERENTIAL_CONSTRAINTS. * The result file for main.information_schema_inno shows the unique_constraint_name as PRIMARY. This is expected change added in wl6049. We get 'PRIMARY' as constraint name if a key is promoted as primary key. If a unique key is not a primary key, then the constraint name does show the unique key name. * Fixed upgrade code to return just the constraint name and avoid prefixing the constraint schema name with it. We also check that the constraint name is not more than 64 characters, before continuing further. * Added ORDER BY clauses in some of I_S query to force order of tuple returned. Because, now the optimizer returns the rows and not read from temporary table as in 5.7 I_S design. * Remove part of test case in main.information_schema. Because, - The problem reported back then is only applicable for 5.7 code. - The output of EXPLAIN ... <select on I_S system view> goes through optimizer and then plan return might vary. * Fixed InnoDB upgrade code, which ignored setting RESTRICT flag for update and delete rule. * Recorded result files with I_S column names being capitals now, this is expected, see wl6599 for more info.
Dmitry Lenev authored"Implement INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as a system views over dictionary tables." WL#6049 Meta-data locking for FOREIGN KEY tables. The primary goal of this task is to ensure that foreign keys checks, which are performed by storage engine (e.g. InnoDB), do not access tables which are concurrently modified by DDL statements. Such an isolation of FK checks/actions from DDL statements can be achieved by ensuring that FKs are taken into account when we acquire metadata "operation-type aware" locks for DML and DDL statements. This is done by: 1) Extending prelocking algorithm/process to take into account foreign keys and acquire metadata locks which are appropriate for the operations involving them (checks in parent or child tables take SR lock, cascading updates or deletes take SW lock, LOCK TABLES takes SRO or SNRW locks correspondingly). 2) Changing DDL statements which add or drop foreign keys to the system to X lock on FK parent table before child table definition changes. 3) Changing DDL statements which otherwise affect FK-related metadata (like RENAME TABLE on child or parent table) to acquire X lock on tables participating in the FK. 4) Changing ALTER TABLE to acquire SU metadata lock on parent tables for newly added FKs so it can properly check them. The secondary goal of this task is to ensure that DDL on parent tables correctly updates foreign key metadata. Specifically we now correctly update the following metadata: I) Name of unique constraint in parent table for the FK. Old code misused DD.FOREIGN_KEYS.UNIQUE_CONSTRAINT_ID to store id of supporting index for the FK in the child table. This WL replaces this column with VARCHAR(64) field which stores name of unique key in the parent table used for the FK -- UNIQUE_CONSTRAINT_NAME. DDL statements code was adjusted to keep this value correct on changes to parent table definition. II) Referenced schema and table names (DD.FOREIGN_KEYS.REFERENCED_TABLE_SCHEMA and DD.FOREIGN_KEYS.REFERENCED_TABLE_NAME) during ALTER TABLE RENAME/ RENAME TABLES on parent tables. This WL introduces some new temporary limitations: - We temporary disallow renaming of parent columns in FKs. - ALTER TABLE ... ALGORITHM=COPY acquires SRO locks on the parent tables for newly added FKs. This is temporary workaround for InnoDB SE making information about such FKs to other connections before DDL commit. - We disallow ALTER TABLE ... RENAME under LOCK TABLES on tables which have or will have foreign keys. This limitation should be weakened soon. WL#11059 Implement INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as a system views over dictionary tables. This patch implements I_S.REFERENTIAL_CONSTRAINTS as a system view over data dictionary tables, and remove 5.7 code that uses a temporary table to represent I_S view. Following changes are made in the patch: * Define a system view over data dictionary tables representing I_S.REFERENTIAL_CONSTRAINTS. * Remove 5.7 code from sql_show.cc for I_S.REFERENTIAL_CONSTRAINTS. * The result file for main.information_schema_inno shows the unique_constraint_name as PRIMARY. This is expected change added in wl6049. We get 'PRIMARY' as constraint name if a key is promoted as primary key. If a unique key is not a primary key, then the constraint name does show the unique key name. * Fixed upgrade code to return just the constraint name and avoid prefixing the constraint schema name with it. We also check that the constraint name is not more than 64 characters, before continuing further. * Added ORDER BY clauses in some of I_S query to force order of tuple returned. Because, now the optimizer returns the rows and not read from temporary table as in 5.7 I_S design. * Remove part of test case in main.information_schema. Because, - The problem reported back then is only applicable for 5.7 code. - The output of EXPLAIN ... <select on I_S system view> goes through optimizer and then plan return might vary. * Fixed InnoDB upgrade code, which ignored setting RESTRICT flag for update and delete rule. * Recorded result files with I_S column names being capitals now, this is expected, see wl6599 for more info.
Loading