Pergunta

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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top