希望有人可以帮助我,这需要永远,我需要加快速度:
SELECT Col2, Col3 FROM Table1 Where Col1 = Whats in Table1 Col1
UPDATE Table2 SET Col2, Col3 Where Col1 = Whats in Table2 Col1
我正在更新和更新的表没有索引,每个行大约有250万行。
查询每秒处理大约60个条目,并且将花费太长时间才能完成。代码如下:
<?php
//establish connection to my Database
$link = mysql_connect('localhost', 'info', 'connect') or die('Could not connect: ' . mysql_error());
mysql_select_db('test') or die('Could not select database');
set_time_limit(18000);
//maintain logged in status
mysql_query("INSERT INTO `logtest` (`loggedin`, `timesince`) VALUES ('1', NOW());");
$shere=0;
$sql = "SELECT UniqueID FROM temp WHERE LongDec IS NULL ORDER BY UniqueID DESC";
$fcr = mysql_query($sql) or die(mysql_error());
while($frr=mysql_fetch_array($fcr)){
$shere=$frr[0];
}
mysql_free_result($fcr);
$sql = "SELECT DISTINCT UniqueID, LocationNum FROM temp WHERE UniqueID >=" . $shere . ";";
$fcr = mysql_query($sql);
while($fcrow = mysql_fetch_array($fcr)){
$sql = "SELECT LatDec, LongDec FROM lotest WHERE UniqueID=" . $fcrow[0] . " AND LocationNum=" . $fcrow[1] . ";";
$frr = mysql_query($sql);
$fr = mysql_fetch_array($frr);
$sql = "UPDATE temp SET LatDec=" . $fr[0] . ", LongDec=" . $fr[1] . " WHERE UniqueID = " . $fcrow[0] . " AND LocationNum=" . $fcrow[1] . ";";
mysql_query($sql);
//echo $fcrow[0] . ": " . $fr[0] . "<br>\n";
mysql_free_result($frr);
}
mysql_free_result($fcr);
//Move data to pool
mysql_query("TRUNCATE pool;");
mysql_query("INSERT INTO pool SELECT * FROM temp;");
mysql_close($link);
?>