Performance in PDO / PHP / MySQL: transaction versus direct execution

前端 未结 3 402
臣服心动
臣服心动 2020-12-20 23:39

I am looping through a number of values (1 to 100 for example) and executing a prepared statement inside the loop.

Is there and advantage to using a transaction - co

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 00:00

    I faced the same question when I had to implement a CSV file (possibly quite long) data import (I know you can use the LOAD DATA INFILE syntax for that but I had to apply some processing on my fields before insertion).

    So I made an experiment with transactions and a file with about 15k rows. The result is that if I insert all records inside one unique transaction, it takes only a few seconds and it's cpu bound. If I don't use any transaction at all, it takes several minutes and it's IO bounded. By committing every N rows, I got intermediate results.

提交回复
热议问题