La creazione di tabelle MySQL è incredibilmente lenta


10

Una semplice creazione di tabelle su uno dei miei database MySQL richiede un'eternità:

mysql> CREATE TABLE blah (id BIGINT UNSIGNED NOT NULL PRIMARY KEY);
Query OK, 0 rows affected (16.58 sec)

La macchina è abbastanza inattiva:

01:21:26 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle
01:21:27 PM       all      0.50      0.00      0.21      0.00      0.00     99.29

Qualche idea su come indagare su questo?

EDIT : seguendo i consigli di DTest , questo è il profilo di esecuzione:

mysql> SHOW PROFILE FOR QUERY 1;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000044 |
| checking permissions | 0.000024 |
| creating table       | 8.668129 |
| After create         | 0.000014 |
| query end            | 0.000005 |
| freeing items        | 0.000028 |
| logging slow query   | 0.000004 |
| logging slow query   | 0.000206 |
| cleaning up          | 0.000006 |
+----------------------+----------+

@Phil Una macchina fisica con circa 16 GB di memoria.
— Adam Matan,

@Phil È un server di produzione con molte operazioni MySQL, quindi il disco non dovrebbe essere inattivo.
— Adam Matan,

Risposte:


10

Vorrei attivare la profilazione per avere un'idea di ciò che richiede così tanto tempo. Un esempio usando l'interfaccia della riga di comando di mysql:

SET profiling = 1;
CREATE TABLE blah (id BIGINT UNSIGNED NOT NULL PRIMARY KEY);
SET profiling = 1;

Dovresti ricevere una risposta simile a questa:

mysql> SHOW PROFILES;
| Query_ID | Duration   | Query |
+----------+------------+-------------------------------------------------------------+
|        1 | 0.00913800 | CREATE TABLE blah (id BIGINT UNSIGNED NOT NULL PRIMARY KEY) |
+----------+------------+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SHOW PROFILE FOR QUERY 1;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000071 |
| checking permissions | 0.000007 |
| Opening tables       | 0.001698 |
| System lock          | 0.000043 |
| creating table       | 0.007260 |
| After create         | 0.000004 |
| query end            | 0.000004 |
| closing tables       | 0.000015 |
| freeing items        | 0.000031 |
| logging slow query   | 0.000002 |
| cleaning up          | 0.000003 |
+----------------------+----------+
11 rows in set (0.00 sec)

1
@AdamMatan non è sicuro di leggere la documentazione di profilazione, ma ci sono altri flag per mostrare il profilo della query CPU, BLOCK IOecc. Che potrebbero aiutarti nella fase di "creazione della tabella".
— Derek Downey,
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.