Content here is by:
Michael Still
mikal@stillhq.com

All my Open Source projects
Extracted view of CVS
Home
Site map

1 comments today, 1 of them spam. 375558 comments overall, 374636 of them spam. See recent comments. RSS feed of all comments.

ImageMagick book
MythTV book







Wed, 07 May 2008



Estimating the progress of queries on MySQL

    I've been doing a lot of batch updates on one of my databases at home recently. show processlist says something like this:

    mysql> show processlist;
    +-------+------+---------------+--------------+---------+-------+----------+------------------------------------------+
    | Id    | User | Host          | db           | Command | Time  | State    | Info                                     |
    +-------+------+---------------+--------------+---------+-------+----------+------------------------------------------|
    | 18354 | root | maui:37403    | smtp_servers | Query   | 57234 | Updating | update ips_218 set reverse_lookup = null |
    | 22286 | root | maui:37348    | smtp_servers | Query   | 38103 | Updating | update ips_80 set reverse_lookup = null, |
    | 22851 | root | maui:54982    | smtp_servers | Query   | 34091 | Updating | update ips_19 set reverse_lookup = null, | 
    | 23351 | root | molokai:58232 | smtp_servers | Sleep   |    57 |          | NULL                                     |
    | 23496 | root | maui:40923    | smtp_servers | Query   | 29973 | Updating | update ips_62 set reverse_lookup = null, |
    | 23906 | root | maui:38068    | smtp_servers | Query   | 26794 | Updating | update ips_83 set reverse_lookup = null, |
    | 25675 | root | maui:56438    | smtp_servers | Query   | 12505 | Updating | update ips_82 set reverse_lookup = null, |
    | 25846 | root | maui:41334    | smtp_servers | Query   | 10948 | Updating | update ips_90 set reverse_lookup = null, |
    | 26437 | root | maui:41139    | smtp_servers | Query   |  6211 | Updating | update ips_66 set reverse_lookup = null, |
    | 26773 | root | maui:32885    | smtp_servers | Query   |  3526 | Updating | update ips_76 set reverse_lookup = null, |
    | 27073 | root | maui:42607    | smtp_servers | Query   |  1148 | Updating | update ips_11 set reverse_lookup = null, |
    | 27202 | root | molokai:50688 | smtp_servers | Query   |     0 | NULL     | show processlist                         |
    | 27203 | root | molokai:50689 | smtp_servers | Sleep   |     2 |          | NULL                                     |
    +-------+------+---------------+--------------+---------+-------+----------+------------------------------------------+
    14 rows in set (0.20 sec)
    


    Now, wouldn't it be nice if MySQL provided some extra information about the progress of those queries? Like for example the number of rows which have been updated so far, or an estimate of how long the query has left to run? I'm ok with such queries not being very accurate, but I assume the storage engine has to have some idea of how many rows are in the table and how many it has touched already.

    Perhaps something like this already exists and I haven't noticed? I'm using innodb if that matters.

    Update: it seems like innodb can answer this question for me:

    mysql> show engine innodb status \G;
    ...
    ---TRANSACTION 0 40056, ACTIVE 39794 sec, process no 22984, OS thread id 3020733328 waiting in InnoDB queue
    mysql tables in use 1, locked 1
    6672 lock struct(s), heap size 748864, undo log entries 909825
    MySQL thread id 22851, query id 351217 maui 192.168.1.93 root Updating
    update ips_19 set reverse_lookup = null, reverse = null, reverse_extracted
    ...
    


    That doesn't give you an estimate of percentage complete though. I assume there is a 1:1 correlation between undo row entries and rows altered by the query?

    Update: my imperical observation is that the undo rows are not 100% correlated to the number of rows your query changed. Its correlated to the number of rows that were changed kinda near your query. For example, if you're doing an update, then the number is good enough to trust. However, if you're doing a select, then the number seems to be the number of rows someone else changed while your select was running (i.e. how many old versions needed to be kept around because of your select transaction).

    Also, Jeremy Cole to the rescue!

    Tags for this post: mysql(S)

posted at: 11:19 | path: /mysql | permanent link to this entry
There are 2 comments on this post, and 7 comments which didn't survive moderation. 0 were blocked by trained gerbils. Click here to see them.


Blathering for Wednesday, 07 May 2008

    09:16: $10 theft cost a $250,000 spill cleanup
    09:16: " The 3,500-gallon spill of a toxic chemical into San Pablo Bay over the weekend cost an estimated $250,000 to clean up - and it was all for a lousy $10 worth of brass. The thieves who caused the spill of the chemical toluene at Reaction Products in Richmond were after the valves on holding tanks - the latest example of a crime wave involving barely precious metals that yield a few dollars at the recycling yard but can cost taxpayers big bucks."
    09:57: Professor sues own students
    09:58: "Priya Venkatesan taught English at Dartmouth College. She maintains that some of her students were so unreceptive of "French narrative theory" that it amounted to a hostile working environment. She is also readying lawsuits against her superiors, who she says papered over the harassment, as well as a confessional expose, which she promises will "name names.""
    09:58: ... I guess that's one way of retaining control in the classroom


    Tags for this post: blather(S)

posted at: 09:58 | path: /blather | permanent link to this entry
There are no comments on this post which have survived moderation. 1 posts have been culled and 0 blocked. Be the first to make a non-spam comment here, please!