I've got a set of transactions for storing stuff in a database which runs
slower and slower and slower as the tables get larger.
The traffic graph in MySQL Administrator goes up and up as the Number of SQL
Queries graph goes down and down.
There is nothing obviously wrong with any of the queries in the
transaction - they've all got sensible indexes, and none of them returns any
significant amount of data, which is why the bytes_sent figure (the Traffic)
graph is puzzling.
(I haven't yet checked running MySQL and the client on separate boxes and
getting a network trace of the traffic between them - I'll do that if I have
to, in order to find out whether bytes_sent is lying and that much data is
not being returned to the client, as indicated by examination of the queries
being performed, or whether I've wrongly analysed the queries, and lots of
data is being sent, and bytes_sent is telling the truth.)
Now, another odd thing is what turns up in the slow transaction log, being
lots of instances of:
# Time: 070123 9:25:25
# User@Host: xx[xx] @ localhost [127.0.0.1]
# Query_time: 2 Lock_time: 0 Rows_sent: 107772 Rows_examined: 107772
SET last_insert_id=107772;
SELECT LAST_INSERT_ID() FROM xx;
Eh?? Surely LAST_INSERT_ID() can't take any time?? What's going on here?? -
I have to be able to insert millions of rows into this table, and can't have
it taking seconds to do LAST_INSERT_ID() each time! I have trouble imagining
why LAST_INSERT_ID() does anything other than take a number from memory from
a data structure in the server belonging to the connection.
The main log seems to confirm what the slow log is saying - most of the
timestamps are after fetches of LAST_INSERT_ID():
65 Query SELECT LAST_INSERT_ID() FROM xx
070123 9:27:26 3 Query SHOW STATUS
3 Query SHOW INNODB STATUS
070123 9:27:27 3 Query SHOW STATUS
3 Query SHOW INNODB STATUS
070123 9:27:28 3 Query SHOW STATUS
3 Query SHOW INNODB STATUS
--
Tim Ward
Brett Ward Limited -
www.brettward.co.uk