Emulating a transaction-safe SEQUENCE in MySQL

Posted by Michael Pliskin on Stack Overflow See other posts from Stack Overflow or by Michael Pliskin
Published on 2009-04-30T07:42:40Z Indexed on 2010/05/06 7:18 UTC
Read the original article Hit count: 209

Filed under:
|

We're using MySQL with InnoDB storage engine and transactions a lot, and we've run into a problem: we need a nice way to emulate Oracle's SEQUENCEs in MySQL. The requirements are: - concurrency support - transaction safety - max performance (meaning minimizing locks and deadlocks)

We don't care if some of the values won't be used, i.e. gaps in sequence are ok. There is an easy way to archieve that by creating a separate InnoDB table with a counter, however this means it will take part in transaction and will introduce locks and waiting. I am thinking to try a MyISAM table with manual locks, any other ideas or best practices?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about transactions