At 23:37 -0300 3/21/04, Anderson wrote:
Hello,

I analize my mysql slow query log and see this:

"
# Time: 040320 15:35:31
# [EMAIL PROTECTED]: maxpcco_autoresp[maxpcco_autoresp] @ localhost []
# Query_time: 5  Lock_time: 0  Rows_sent: 764220  Rows_examined: 764220
SET last_insert_id=764597;
SELECT LAST_INSERT_ID() AS id FROM arp3_cam;
# [EMAIL PROTECTED]: maxpcco_autoresp[maxpcco_autoresp] @ localhost []
# Query_time: 5  Lock_time: 0  Rows_sent: 764222  Rows_examined: 764222
SET last_insert_id=764599;
SELECT LAST_INSERT_ID() AS id FROM arp3_cam;
# Time: 040320 15:35:33
# [EMAIL PROTECTED]: maxpcco_autoresp[maxpcco_autoresp] @ localhost []
# Query_time: 7  Lock_time: 0  Rows_sent: 764221  Rows_examined: 764221
SET last_insert_id=764598;
SELECT LAST_INSERT_ID() AS id FROM arp3_cam;
# Time: 040320 15:35:34
# [EMAIL PROTECTED]: maxpcco_autoresp[maxpcco_autoresp] @ localhost []
# Query_time: 6  Lock_time: 0  Rows_sent: 764224  Rows_examined: 764224
SET last_insert_id=764601;
SELECT LAST_INSERT_ID() AS id FROM arp3_cam;
# [EMAIL PROTECTED]: maxpcco_autoresp[maxpcco_autoresp] @ localhost []
# Query_time: 8  Lock_time: 0  Rows_sent: 764223  Rows_examined: 764223
SET last_insert_id=764600;
SELECT LAST_INSERT_ID() AS id FROM arp3_cam;
"

Why these query are much slow to me?

SET last_insert_id=(number);
SELECT LAST_INSERT_ID() AS id FROM arp3_cam;

Its necessary to examine all rows to get last id?
Its possible to change anything to speed up this query?

There is. Use this query instead:


SELECT LAST_INSERT_ID();

There is no need to select LAST_INSERT_ID() for *every row in the table*.

The slow query log also contains queries that don't use any index at
all to select rows from a table, which indicates a full scan.  That's
probably why you're seeing those queries in the log.


-- Paul DuBois, MySQL Documentation Team Madison, Wisconsin, USA MySQL AB, www.mysql.com

MySQL Users Conference: April 14-16, 2004
http://www.mysql.com/uc2004/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to