开发者

time complexity to get auto incremented row id in mysql

开发者 https://www.devze.com 2023-03-30 21:16 出处:网络
I am a newbie at mysql and databases. I have a simple question. I have created a table that has an integer type id column that is auto incremented. After each insert I get the last row inserted id (in

I am a newbie at mysql and databases. I have a simple question. I have created a table that has an integer type id column that is auto incremented. After each insert I get the last row inserted id (in python using cursor.lastrowid, or connection.insert_id()). I wanted to know what is the time complexity in mysql to get this value? I am guessing its O(1) as the database should be storing this value somewhere and updating it after each insert?

开发者_开发知识库

Thanks.


cursor.lastrowid will return the value from the single insert see: http://www.python.org/dev/peps/pep-0249/

connection.insert_id() will have to make a seperate call to get the last_insert_id, and would slightly slower

0

精彩评论

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