开发者

MySql InnoDb auto-increment pre-fetching values

How do I get future keys from a Mysql InnoDb?

Oracle and Postgres both have the concept of sequences and a nextval-function. Mysql seems to be a bit different.

Is there some easy sql statement to pull may开发者_Python百科be 1000 future keys for a certain auto-increment field, and be sure no other transaction can pull these values at the same time or any time in the future?


For InnoDb table you can do this:

  • Start a transaction.
  • Insert 1000 records.
  • Commit the transaction.

Oracle and Postgres both have the concept of sequences and a nextval-function. Mysql seems to be a bit different.

In MySQL you could do this to find next value -

SELECT MAX(id) + 1 FROM table_name;

But there is no guarantee that AUTO_INCREMENT works in the same way.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜