, , , . MySQL , sprocs . . : http://www.xaprb.com/blog/2007/01/11/how-to-implement-a-queue-in-sql/
, . , MySQL REPLACE INSERT ON DUPLICATE KEY UPDATE INSERT. ...
: , " ", , . - . Heres "" :
insert into q(id, modulo, fruit)
select
(coalesce(max(id), -1) + 1),
(coalesce(max(id), -1) + 1) mod 5,
'apples'
from q
on duplicate key update
id = values(id),
fruit = values(fruit)
: id , . , NULL, COALESCE() -1. , . , , AUTO_INCREMENT : , .
Etc. . ().:)
, ( 20 ), UserID. , ...
source
share