2

This is a problem in a distribute environment!!!

I have processes in many distribute computers, in every process I use pymysql to insert many rows into a table with autoincrease id, I wish I could get the ids of each row.

I have solution when I do it on a single node:I just get max id of the table and set the id of inserted rows myself,but this will failed in distribute environment because if two processes do insert at same time, they will get the same max id, and collision will happened.

I have an inefficient sulotion, I can just insert one row a time and use cursor.lastrowid to get the id of this row,but this is very slow.

I find a similary question How can I Insert many rows into a MySQL table and return the new IDs? but this seems will failed when in distribute environment

I guess this must use a distribute lock,any ideas?

Tarjintor
  • 585
  • 4
  • 15

0 Answers0