Don't  include a from clause with the last_insert_id(), or you will get 
a full table scan.

The last_insert_id will only give you the insert id for the last record 
inserted.

mysql mailing list user wrote:

> Hi,
> I have a big problem with last_insert_id() query.
> I am adding records to a table with about half a million records in 
> it. The
> insert takes well under a second. I then call last_insert_id as I need to
> make a link to another table.
> The last_insert_id takes around 2 minutes!!! Yes *minutes*!
> Has anybody any idea what might be going wrong here. The auto increment
> field is definitely a primary key and any other searches on the table are
> quite quick.
> Cheers
> ---------------------------------------------------------------------
> Before posting, please check:
>   http://www.mysql.com/manual.php   (the manual)
>   http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to