문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top