MySQL query killing my server

Posted by Webnet on Stack Overflow See other posts from Stack Overflow or by Webnet
Published on 2010-04-06T14:01:34Z Indexed on 2010/04/06 14:03 UTC
Read the original article Hit count: 303

Filed under:
|

Looking at this query there's got to be something bogging it down that I'm not noticing. I ran it for 7 minutes and it only updated 2 rows.

//set product count for makes
$tru->query->run(array(
    'name' => 'get-make-list',
    'sql' => 'SELECT id, name FROM vehicle_make',
    'connection' => 'core'
));
while($tempMake = $tru->query->getArray('get-make-list')) {
    $tru->query->run(array(
        'name' => 'update-product-count',
        'sql' => 'UPDATE vehicle_make SET product_count = (
            SELECT COUNT(product_id) FROM taxonomy_master WHERE v_id IN (
                SELECT id FROM vehicle_catalog WHERE make_id = '.$tempMake['id'].'
        )
) WHERE id = '.$tempMake['id'],
        'connection' => 'core'
    ));
}

I'm sure this query can be optimized to perform better, but I can't think of how to do it.

vehicle_make = 45 rows

taxonomy_master = 11,223 rows

vehicle_catalog = 5,108 rows

All tables have appropriate indexes

© Stack Overflow or respective owner

Related posts about mysql

Related posts about query