Why do MySQL InnoDB inserts / updates on large tables get very slow when there are a few indexes?

前端 未结 5 1046
忘掉有多难
忘掉有多难 2020-12-14 02:48

We have a series of tables that have grown organically to several million rows, in production doing an insert or update can take up to two seconds. However if I dump the tab

5条回答
  •  被撕碎了的回忆
    2020-12-14 03:16

    It sounds like it's either

    • Index unbalancing over time
    • Disk fragmentation
    • Internal innodb datafile(s) fragmentation

    You could try analyze table foo which doesn't take locks, just a few index dives and takes a few seconds.

    If this doesn't fix it, you can use

    mysql> SET PROFILING=1;
    mysql> INSERT INTO foo ($testdata);
    mysql> show profile for QUERY 1;
    

    and you should see where most of the time is spent.

    Apparently innodb performs better when inserts are done in PK order, is this your case?

提交回复
热议问题