Skip to content

MDEV-34784 unhandled FK dependency with DML vs DDL#5041

Merged
sjaakola merged 1 commit into
10.11from
10.11-MDEV-34784
May 22, 2026
Merged

MDEV-34784 unhandled FK dependency with DML vs DDL#5041
sjaakola merged 1 commit into
10.11from
10.11-MDEV-34784

Conversation

@sjaakola

@sjaakola sjaakola commented May 5, 2026

Copy link
Copy Markdown
Contributor

Certain DDL statements (e.g. ALTER TABLE) require innodb table lock on tables having foreign key constraint reference to the table under DDL execution. This dependency is not added in write set key information. However, tables being referenced to will be added in the key information, so the table locking domain of DDL is only partially recorded.

One harmful consequence of this missing dependency information happens when a DML modifies a FK child table's row, which has NULL in the FK referencing column. In such situation, the FK reference cannot be followed during DDL execution, and there will be no FK parent table keys recorded in the write set. Parallel applying (or multi-master access) of such DML and DDL on the FK parent table will cause applying conflicts.

This scenario is presented in a new mtr test added in this commit. The commit has a fix for the DDL FK dependency handling by adding all FK child table names in the write set key information. The commit has also fixes for innodb lock0lock.cc error logging to report lock connflicts of table and record locks correctly.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses MDEV-34784 by ensuring that both parent and child foreign key dependencies are correctly identified and recorded in the write set, preventing issues with parallel applying in Galera clusters. Additionally, it updates InnoDB's lock reporting logic to correctly distinguish between record and table locks during debug output. Review feedback suggests refactoring duplicated logic in wsrep_mysqld.cc and lock0lock.cc to improve maintainability, correcting inconsistent indentation, and removing redundant debug messages.

Comment thread sql/wsrep_mysqld.cc
Comment thread sql/wsrep_mysqld.cc Outdated
Comment thread storage/innobase/lock/lock0lock.cc Outdated

@janlindstrom janlindstrom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented code and you could address AI review also. If I correctly remember using lock_rec_print is not safe to call as it expects page to be latched and that might not be always true.

Comment thread sql/wsrep_mysqld.cc Outdated
Comment thread sql/wsrep_mysqld.cc Outdated
Comment thread storage/innobase/lock/lock0lock.cc
@sjaakola sjaakola force-pushed the 10.11-MDEV-34784 branch from 1202f23 to 11aa4de Compare May 6, 2026 17:34
@sjaakola sjaakola force-pushed the 10.11-MDEV-34784 branch from 11aa4de to d251f9a Compare May 20, 2026 07:21

@janlindstrom janlindstrom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@sjaakola sjaakola force-pushed the 10.11-MDEV-34784 branch 2 times, most recently from 00a2596 to fddcf61 Compare May 21, 2026 08:24
Certain DDL statements (e.g. ALTER TABLE) require innodb table lock
on tables having foreign key constraint reference to the table
under DDL execution. This dependency is not added in write set
key information. However, tables being referenced to will be added
in the key information, so the table locking domain of DDL is only
partially recorded.

One harmful consequence of this missing dependency information happens
when a DML modifies a FK child table's row, which has NULL in the FK
referencing column. In such situation, the FK reference cannot be followed
during DDL execution, and there will be no FK parent table keys recorded
in the write set. Parallel applying (or multi-master access) of such DML
and DDL on the FK parent table will cause applying conflicts.

This  scenario is presented in a new mtr test added in this commit.
The commit has a fix for the DDL FK dependency handling by adding all FK
child table names in the write set key information.
The commit has also fixes for innodb lock0lock.cc error logging to report
lock connflicts of table and record locks correctly.
@sjaakola sjaakola force-pushed the 10.11-MDEV-34784 branch from fddcf61 to 9ed3a7f Compare May 22, 2026 04:42
@sjaakola sjaakola merged commit 9ed3a7f into 10.11 May 22, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants