On MySQL 8.0.33, I'm experiencing a form of contention (reproduced on multiple instances) that is not explained by the documentation.
As example:
- I boot an instance
- on a console client, I invoke a
SELECT COUNT(*)
on a relatively large table (a few GBs of total records+indexes) - on a separate client, I invoke a
ANALYZE TABLE
on a separate, smaller table
the result is that the second statement (ANALYZE TABLE
) hangs for a while, blocked in a System Lock
state; this is a sample output:
+----+--------+------+-------+---------+------+-------------+---------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+--------+------+-------+---------+------+-------------+---------------------------------+
| 18 | _user_ | _ip_ | _db_ | Query | 72 | executing | SELECT COUNT(*) FROM _table_1_ |
| 32 | _user_ | _ip_ | _db_ | Query | 45 | System lock | ANALYZE TABLE _table_2_ |
+----+--------+------+-------+---------+------+-------------+---------------------------------+
Based on the documentation (here and here), MySQL seems to be locking (at least) both tables while paging in the records of the first (SELECT
) tables.
What is exactly causing MySQL to lock multiple tables, while performing a SELECT on one?