I want to UPDATE some hundreds of thousand of rows stored in Oracle database. For this I use PHP and transactions. But the whole process is extremely slow. This is what I do:
while (($row = oci_fetch_array($stid, OCI_ASSOC))) {
// define input for function
$id = $row['ID'];
$upstream_attn = $row['UPSTREAM_ATTN'];
$downstream_attn = $row['DOWNSTREAM_ATTN'];
$attainable_bitrate_adsl = $row['ATTAINABLE_BITRATE_ADSL'];
$stability = $row['STABILITY'];
$performance = $row['PERFORMANCE'];
$dsl_type = $row['DSL_TYPE'];
$snr_profile = $row['SNR_PROFILE'];
// execute function
$validationStatus = validatePerformanceData($upstream_attn,$downstream_attn,$attainable_bitrate_adsl,$stability,$performance,$dsl_type,$snr_profile); // return true or false
if ($validationStatus== 'OK'){
$stid_tmp = oci_parse($connection,"update " . ALUWS_DATA_HISTORICAL_TBL . " set VALIDATION_STATUS = 1 where ID = :id_bbn");
oci_bind_by_name($stid_tmp, ":id_bbn", $id);
$r_tmp = oci_execute($stid_tmp, OCI_NO_AUTO_COMMIT);
}
else{
$y = $y +1;
}
}
oci_commit($connection);
//disconnect from database
oci_close($connection);
The whole process takes for ages. I have added in the oci_execute function the mode: OCI_NO_AUTO_COMMIT in order to avoid auto commit but this didn't make a big difference.
Any other suggestions are mostly welcome.
ages?ALUWS_DATA_HISTORICAL_TBLis a constant at least within the loop, you'd want to do youroci_parseonce and just bind and execute multiple times within the loop. Where is the data in your array coming from? If you're pulling it from the database, it would be much more efficient to do a singleupdateand let the database work in sets.validatePerformanceData()do? Is it a simple function? Also, what does the SQL foroci_fetch_array($stid, OCI_ASSOC)look like? What version of Oracle are you running?