Bug #62221 Possible race condition at row_ins_check_foreign_constraints()
Submitted: 22 Aug 2011 4:46 Modified: 14 May 2019 17:08
Reporter: Yasufumi Kinoshita Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S3 (Non-critical)
Version:5.1.58, 5.5.15 OS:Any
Assigned to: CPU Architecture:Any

[22 Aug 2011 4:46] Yasufumi Kinoshita
Description:
In the row_ins_check_foreign_constraints(),
---------------
                        if (foreign->referenced_table == NULL) {
                                dict_table_get(foreign->referenced_table_name,
                                               FALSE);
                        }

                        if (0 == trx->dict_operation_lock_mode) {
                                got_s_lock = TRUE;

                                row_mysql_freeze_data_dictionary(trx);
                        }
---------------
reading foreign->referenced_table needs row_mysql_freeze_data_dictionary(trx) at least, in exactly.

How to repeat:
It might be race condition of rare case.

Suggested fix:
row_upd_check_references_constraints() seems good,
row_mysql_freeze_data_dictionary() is called before while().

row_ins_check_foreign_constraints() should be aligned with the same way at row_upd_check_references_constraints()
[22 Aug 2011 12:59] Valeriy Kravchuk
Thank you for the problem report. Verified by code review of current mysql-5.5 tree.
[18 Jun 2013 14:02] MySQL Verification Team
Is this bug still valid after the fixes for:
Bug 13635833 - MULTIPLE CRASHES IN FOREIGN KEY CODE WITH CONCURRENT DDL/DML ?
[13 May 2019 13:22] Dmitry Lenev
Posted by developer:
 
Hello!

This bug report complains about misplaced call to
row_mysql_freeze_data_dictionary() in 
row_ins_check_foreign_constraints().

However, this call was completely removed from this function in 8.0 by:

commit 3bff56267ccf3dd14a48ed3ff8e8a3592392d2cc (origin/mysql-trunk-mock)
Author: Allen Lai <zheng.lai@oracle.com>
Date:   Thu Apr 13 10:59:58 2017 +0800

      wl#9525 InnoDB_New_DD: update InnoDB specific metadata into new DD for  DDL
      wl#9534 InnoDB_New_DD: Instantiate InnoDB in-memory metadata with  newDD objects
      wl#9530 InnoDB_New_DD: FTS index support for newDD
      wl#9531 InnoDB_New_DD: Enable table encryption and transparent  compression
      wl#9532 InnoDB_New_DD: InnoDB_New_DD: Move data dictionary tables to a  single tablespace
      wl#9559 InnoDB_New_DD: Support in-place ALTER PARTITION
      wl#9537 InnoDB_New_DD: Support InnoDB table import/export for new DD
      wl#9357 InnoDB: Upgrade steps for new data dictionary
      wl#9570 Extend SHOW statements to list hidden  columns and index information
      wl#9461 Upgrade for Innodb Internal Dictionary Migration

      This is the InnoDB side of work to support an unified metadata system between MySQL server and
      Storage Engines. It removes the InnoDB dependency on InnoDB system tables, that is, all InnoDB
      metadata are now read from server objects, instead of reading from InnoDB system tables.

      In these wls, we replaced dict_table_open_* (on_id/on_name) with their newDD counterpart.
      It replaced metadata instantiation (dict_load_table etc.) with newDD counterpart too.
      And also, we migrated all related features, like partition, encryption, compression and
      import/export etc. Upgrade from mysql-5.7 is supported as well.

which was added to 8.0.2 development release.

Also in 8.0 all foreign key operations are now protected from concurrent 
DDL by metadata locks, thanks to WL#6049 "Meta-data locking for FOREIGN
KEY tables", which was added to 8.0.3 development release.

Taking into account the above and after discussing this bug with InnoDB
team members (including original bug reporter) I am closing this bug
as fixed in 8.0.3.

Moving it to Documenting state to let Documentation team to figure out
if anything needs to be added to Release Notes.
[14 May 2019 17:08] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 8.0.17 release, and here's the changelog entry:

A misplaced function call that locks the InnoDB data dictionary during a
foreign key check was removed.
[20 May 2019 20:59] Daniel Price
Posted by developer:
 
Correction. This bug was fixed as of the 8.0.3 release.