Hoping someone can help me, this is taking forever and I need to speed it up:
SELECT Col2, Col3 FROM Table1 Where Col1 = Whats in Table1 Col1
UPDATE Table2 SET Col2, Col3 Where Col1 = Whats in Table2 Col1
the table I am updating and updating from have no indexes and are around 2.5 millions rows each.
The query is processing around 60 entries per second and will take way too long to finish. The code is below:
<?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>
";
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);
?>