这正是我的情况,我已经解决了,请在similar 问题中查看我的答案。
让我也试着系统地回答一下。
create table my_seq(
min_value integer,
Max_value integer,
last_value integer,
increment_by tinyint,
type varchar)ENGINE = InnoDB;
然后创建数据值,例如,
insert into my_seq(min_value,max_value,last_value,increment_by,type)
values(1,99999999,1,1,'foo#','DS'),(1,999999999,1,1,'foo#','MS'),(1,999999999,1,1,'foo#','DOC');
确保您拥有auto-commit=false。
然后,在您的应用程序或数据库代码中这样做,
//very import to begin the transaction
begin;
select CONCAT(type_val,'-',last_value) from my_seq where type_val=? FOR UPDATE;
Read the result in App or database procedure/trigger
update my_seq set last_number=last_number+1 where type_val=?;
commit;
确保type_val 上有index。
我相信这应该可行。