Ho la seguente tabella di InnoDB:Mysql Inserire lento
+-----------+-----------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| doc_id | char(32) | NO | | NULL | |
| staff | char(18) | NO | | NULL | |
| timestamp | timestamp | NO | MUL | CURRENT_TIMESTAMP | |
+-----------+-----------+------+-----+-------------------+----------------+
Con questi tasti:
+--------------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| staff_online | 0 | PRIMARY | 1 | id | A | 277350 | NULL | NULL | | BTREE | |
| staff_online | 1 | timestamp | 1 | timestamp | A | 277350 | NULL | NULL | | BTREE | |
| staff_online | 1 | staff_timestamp | 1 | timestamp | A | 277350 | NULL | NULL | | BTREE | |
| staff_online | 1 | staff_timestamp | 2 | staff | A | 277350 | NULL | NULL | | BTREE | |
+--------------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
Ho appena notato che in mysql-slow.log
a volte ho una query di inserimento su questo tavolo che prende più di 1 secondo
INSERT INTO `staff_online` (`doc_id`, `staff`, `timestamp`) VALUES ('150b60a0ab8c5888bdbbb80bd8b7f8a2', 'asia', '2011-01-29 16:52:54')
sono davvero perplesso perché ci vuole tanto tempo. Come posso accelerarlo?
BTW: Ogni giorno ci sono ~ 80 INSERTI lenti e 40 AGGIORNAMENTI lenti come questo.
quante righe sono in tabella, e sono certo tutti gli inserti sono lenti? –
Ci sono 277259 righe e solo alcuni inserimenti sono lenti (rari). – kalkin
Sembra che tu abbia due indici, uno per 'timestamp' un altro per' timestamp, staff'. Quest'ultimo è sufficiente per cercare per 'timestamp', è possibile eliminare il precedente. – 9000