Mysql update large table too much long time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    Mysql update large table too much long time

    I have two tables in database
    table1 consisting of student data 4,00,000 records
    table2 consisting of student examination center with roll nos range-800 records
    I have to search roll no in range and then allocate center to it
    i tried all methods but failed
    first I tried to update by join it took infinite time to execute and resulted in browser hang
    then I tried to go to student data through center allocation data and then executed update. loop has to execute 800 times but after 1:30 hours it gives time execution exceeds error.
    Please help me to find a quickest method to do it
    METHOD1-HANGS BROWSER
    Code:
    UPDATE STUDENTDATA INNER JOIN CENTER ON STUDENTDATA.SCH=CENTER.SCH SET EXAMCENTER = EXMCENTER
    WHERE ROLLNO>=ROLLNO_FROM1 AND ROLLNO<=ROLLNO_TO1;
    METHOD 2-ERROR AFTER 1:30 HOURS OF EXECUTION
    Code:
    ?php 
    //$myfile = fopen("cenfil17.txt", "w") or die("Unable to open file!");
    include 'include/conn.php';
    $sql = "update studentdata set examcenter=''" ;
    $result = $conn->query($sql);
    //SET  innodb_lock_wait_timeout = 5000; 
    //ini_set('innodb_lock_wait_timeout', '5000');
    
    		$pSCHOOL="1";$vSCHOOL="4";
    		$sql = "select * from CENTER  order by SCHOOLNO2" ;
            $result = $conn->query($sql);
    		ini_set('memory_limit', '-1');
    		while($row = $result->fetch_assoc()) {
    		$sql1 = "UPDATE studentdata  SET examcenter = '".$row["exmcenter"]."' WHERE SCH='".$row["SCH"]."' AND ( CAST(rollno AS UNSIGNED) BETWEEN " . $row["SERIAL_FROM"]." AND ". $row["SERIAL_TO"]." OR CAST(rollno AS UNSIGNED) BETWEEN " . $row["SERIAL_FROM1"]." AND ". $row["SERIAL_TO1"]. ")"  ;
    	    ECHO $sql1."<BR/>";
    		//EXIT;
            $result1 = $conn->query($sql1);	
    			 
    }
    	
    		
    //fclose($myfile);
    $conn->close();
    ?>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Please help me to find a quickest method to do it
    use indexes

    Comment

    • kkshansid
      New Member
      • Oct 2008
      • 232

      #3
      i tried index then
      run method -1 that is bulk update method
      but browser still browser hangs

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        then you need to let MySQL explain you the query.

        Comment

        Working...