Why is executemany slow in Python MySQLdb?

前端 未结 4 1317
星月不相逢
星月不相逢 2020-12-14 11:08

I am developing a program in Python that accesses a MySQL database using MySQLdb. In certain situations, I have to run an INSERT or REPLACE command on many rows. I am curren

4条回答
  •  忘掉有多难
    2020-12-14 11:31

    Your first example is a single (large) statement that is generated and then sent to the database.

    The second example is a much simpler statement that inserts/replaces a single row but is executed multiple times. Each command is sent to the database separately so you have to pay the turnaround time from client to server and back for every row inserted. I would think that this extra latency introduced between the commands is the main reason for the decreased performance of the second example.

提交回复
热议问题