Skip to content

MDEV-38822 Lock wait timeout during CREATE TABLE AS SELECT FROM mysql.innodb_table_stats#4924

Merged
dr-m merged 1 commit into10.6from
MDEV-38822
Apr 13, 2026
Merged

MDEV-38822 Lock wait timeout during CREATE TABLE AS SELECT FROM mysql.innodb_table_stats#4924
dr-m merged 1 commit into10.6from
MDEV-38822

Conversation

@Thirunarayanan
Copy link
Copy Markdown
Member

Analysis:

  1. Starts the CREATE TABLE ... SELECT and acquires an Intent Shared lock on mysql.innodb_table_stats to read the rows. (Transaction: T1)

  2. The table t1 is populated. As part of the post-copy phase (introduced by MDEV-35163), InnoDB triggers the statistics update.

  3. InnoDB opens a new internal transaction to update the statistics. This transaction(T2) attempts to acquire an LOCK_X on the same table in mysql.innodb_table_stats. T2 (x-lock) must wait for T1 to commit or rollback because X-locks are incompatible with IS locks from other trasnaction.

Solution:

Currently, Intermediate tables don't trigger dict_stats_update_if_needed(), so they require explicit stats update via alter_stats_rebuild(). For CREATE...SELECT stats are updated automatically through the normal DML path via dict_stats_update_if_needed()

Skip calling dict_stats_update() in alter_stats_rebuild() for non-intermediate tables when using copy algorithm, since their statistics will be updated automatically via dict_stats_update_if_needed().

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

….innodb_table_stats

Analysis:
=========
1) Starts the CREATE TABLE ... SELECT and acquires an Intent Shared lock on
mysql.innodb_table_stats to read the rows. (Transaction: T1)

2) The table t1 is populated. As part of the post-copy phase
(introduced by MDEV-35163), InnoDB triggers the statistics update.

3) InnoDB opens a new internal transaction to update the statistics.
This transaction(T2) attempts to acquire an LOCK_X on the same
table in mysql.innodb_table_stats. T2 (x-lock) must wait for T1 to
commit or rollback because X-locks are incompatible with
IS locks from other trasnaction.

Solution:
========
Currently, Intermediate tables don't trigger dict_stats_update_if_needed(),
so they require explicit stats update via alter_stats_rebuild().
For CREATE...SELECT stats are updated automatically through the normal DML
path via dict_stats_update_if_needed()

Skip calling dict_stats_update() in alter_stats_rebuild() for
non-intermediate tables when using copy algorithm, since their statistics will
be updated automatically via dict_stats_update_if_needed().
@dr-m dr-m merged commit be0bb9d into 10.6 Apr 13, 2026
12 of 14 checks passed
@dr-m dr-m deleted the MDEV-38822 branch April 13, 2026 06:41
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