我正在使用PHP比较一些数据来访问MySQL表。该脚本需要一个多小时才能运行。我们处理源数据中的大约100k行和每个目标表中的300k,即两个表。
每张表中总共不超过10列。
这是脚本:
$query = "SELECT bbva_check_deductions.empno, bbva_check_deductions.idr, bbva_check_deductions.current1, bbva_job.paygroup
FROM bbva_check_deductions
LEFT JOIN bbva_job
ON bbva_check_deductions.empno = bbva_job.file_nbr
ORDER BY current1 DESC, EmpNo DESC, IDR DESC";
$result_set = mysql_query($query,$connection);
while ($result = mysql_fetch_assoc($result_set)) {
$emplid = compare_filter($result['empno']);
$oldCode = compare_filter($result['idr']);
$origCode = $oldCode;
$payGroup = compare_filter($result['paygroup']);
$codes = array('DC6', 'HTH', 'DM4', '4UP', 'DC1', 'DC3', 'DC4', 'DEN', 'DCR', 'MDR', 'PRK', 'VIS', '41K');
//CALCULATE WEEK NO
if ($payGroup == "J2C") {$week = 24;}
elseif ($payGroup == "J2E") {$week = 26;}
else {$week = 22;}
//QUERY TRANSLATION TABLE FOR TRANSLATED VALUE
$translate_query = "SELECT * FROM translation WHERE sourceValue = '{$oldCode}'
AND sourceField LIKE '%ded_code%' LIMIT 1";
$translate_result_set = mysql_query($translate_query, $connection);
if (mysql_num_rows($translate_result_set) > 0) {
$translate_result = mysql_fetch_assoc($translate_result_set);
$oldCode = compare_filter($translate_result['translatedValue']);
}
//DETERMINE IF MEMO
if ($oldCode == "GTL" || $oldCode == "BLI" || $oldCode == "BLT" || $oldCode == "HIC" || $oldCode == "DM4") {
$queryField = "memo_code"; $queryTable = "pf_check_memo";
} else {
$queryField = "deduction_code"; $queryTable = "pf_check_deductions";
}
$compare_query = "SELECT {$queryField}, amount_field_for_payroll
FROM {$queryTable}
WHERE empl_id = {$emplid}
AND {$queryField} LIKE '%{$oldCode}%'
AND week_number = {$week}
LIMIT 1";
$compare_result_set = mysql_query($compare_query, $connection);
if (mysql_num_rows($compare_result_set) != 0) {
$compare_result = mysql_fetch_assoc($compare_result_set);
//PREP COMPARE FIELDS
$amount = compare_filter($result['current1']);
$compare_amount = compare_filter($compare_result['amount_field_for_payroll']);
$negCodes = array('DC6', 'HTH', 'DM4', '4UP', 'DC1', 'DC3', 'DC4', 'DEN', 'DCR', 'MDR', 'PRK', 'VIS', '41K');
if (in_array($oldCode,$negCodes)) {$compare_amount = $compare_amount * -1;}
//AMOUNT COMPARE
direct_compare_basic($amount,$compare_amount,"amount","bbva_check_deductions","Y",$origCode,$oldCode);
} else {$content .= $emplid . $separator . "" . $separator . "Emplid + Deduction Code + Pay Group" . $separator . 'bbva_check_deductions' .
$separator . field_prep($emplid . " - " . $oldCode . " - " . $payGroup) . $separator . "No Record Found in PF for week {$week}" . $separator . "Y" . $separator . "Y" .
$separator . $origCode . $separator . $oldCode . $break;}
然后它只写入.CSV文件。
我的功能不会调用任何其他查询,只是格式化内容。我正在运行InnoDB表,并为所有正在使用的列提供索引。我的电脑正在运行WAMP,它有16G的RAM和四核处理器。硬盘是7200转。
似乎对我来说太长了。有什么想法吗?