开发者

Using mysql innodb as a queue?

开发者 https://www.devze.com 2023-01-08 13:03 出处:网络
I have two jobs pulling from a mysql table. They both want to get a row, do some work on it and update that row with the results, however I don\'t want them selecting the same row to update. Whats the

I have two jobs pulling from a mysql table. They both want to get a row, do some work on it and update that row with the results, however I don't want them selecting the same row to update. Whats the best way using mysql/innodb engine to lock a row in the select so that it will be unavailab开发者_运维百科le to other threads but allowing them to select other records? is that possible?

thanks!


You can add the "FOR UPDATE" modifier to the end of your select statement. i.e.

SELECT * FROM table WHERE pkey = N FOR UPDATE;

.. but I think you should be careful when using InnoDB as a queue and aiming for performance. Queues are stack oriented, and need different tools to what InnoDB (and MySQL) are trying to solve.

0

精彩评论

暂无评论...
验证码 换一张
取 消