Block(reservation) of an auto increment line in mysql

Asked

Viewed 78 times

1

I developed a data importer CSV to my base mysql. The Resource is working correctly, but I believe there must be a better way to implement the following logic.

In the archive CSV depending or may not occur that 2 Inserts(master-detail) and the only way I have at the time of controlling them is through your PK self-improvement.

What I do - I perform an Insert, if there is such detail information, I retrieve the last insert (select max(id) table, or with the function LAST_INSERT_ID() and saved in my tbl of detail the information recovered.

Since my service is online, and other people can perform the same import procedure, it may be that the Insert on the same team and my operation is no longer reliable.

One way I thought, and I’m researching it is, like the mysql already know what the next index, I somehow reserve and block this index and do my procedure, in case something occurs it proceeds with the next line.

Someone has worked with this problem?

  • You can create a lock on the table during INSERT, so parallel routines would have to wait for the previous one to be completed.

  • Thank you gmsantos.

  • I also found a nice alternative and that Alvéz also help me. I’ll leave here SHOW TABLE STATUS FROM database LIKE 'table'

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.