Why is this loop over mysql resultset slow? (1.4ms per cycle)

Posted by pawpro on Stack Overflow See other posts from Stack Overflow or by pawpro
Published on 2010-05-26T09:34:07Z Indexed on 2010/05/26 9:41 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

The $res contains around 488k rows the whole loop takes 61s! that's over 1.25ms per cycle! What is taking all that time?

while($row = $res->fetch_assoc())
{
    $clist[$row['upload_id']][$row['dialcode_id']][$row['carrier_id']]['std'] = $row['cost_std'];
    $clist[$row['upload_id']][$row['dialcode_id']][$row['carrier_id']]['ecn'] = $row['cost_ecn'];
    $clist[$row['upload_id']][$row['dialcode_id']][$row['carrier_id']]['wnd'] = $row['cost_wnd'];
    $dialcode_destination[$row['upload_id']][$row['carrier_id']][$row['dialcode_id']]['other_destination'] = $row['destination_id'];
    $dialcode_destination[$row['upload_id']][$row['carrier_id']][$row['dialcode_id']]['carrier_destination'] = $row['carrier_destination_id'];
}

Now resultset of 10 rows, smaller arrays and performance 30 times higher (0.041ms) not the fastest still but better.

while($row = $res->fetch_assoc())
{
    $customer[$row['id']]['name'] = $row['name'];
    $customer[$row['id']]['code'] = $row['customer'];
}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql