MDEV-38822 Lock wait timeout during CREATE TABLE AS SELECT FROM mysql.innodb_table_stats#4924
Merged
MDEV-38822 Lock wait timeout during CREATE TABLE AS SELECT FROM mysql.innodb_table_stats#4924
Conversation
|
|
dr-m
approved these changes
Apr 13, 2026
….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().
b7711f5 to
be0bb9d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Analysis:
Starts the CREATE TABLE ... SELECT and acquires an Intent Shared lock on mysql.innodb_table_stats to read the rows. (Transaction: T1)
The table t1 is populated. As part of the post-copy phase (introduced by MDEV-35163), InnoDB triggers the statistics update.
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().