InnoDB inserts very slow and slowing down

前端 未结 2 1005
逝去的感伤
逝去的感伤 2020-12-31 13:03

I have recently switched my project tables to InnoDB (thinking the relations would be a nice thing to have). I\'m using a PHP script to index about 500 products at a time. <

2条回答
  •  悲&欢浪女
    2020-12-31 13:43

    InnoDB provides more complex keys structure than MyIsam (FOREIGN KEYS) and regenerating keys is really slow in InnoDB. You should enclose all update/insert statements into one transactions (those are actually quite fast in InnoDB, once I had about 300 000 insert queries on InnoDb table with 2 indexes and it took around 30 minutes, once I enclosed every 10 000 inserts into BEGIN TRANSACTION and COMMIT it took less than 2 minutes).

    I recommend to use:

    BEGIN TRANSACTION;
    SELECT ... FROM products;
    UPDATE ...;
    INSERT INTO ...;
    INSERT INTO ...;
    INSERT INTO ...;
    COMMIT;
    

    This will cause InnoDB to refresh indexes just once not few hundred times.

    Let me know if it worked

提交回复
热议问题