mysql 데이터베이스를 통해 실행하고 특정 '테스트'를 수행해야하는 스크립트가 있습니다. 단순화 된 데이터베이스는 사람이 만든 여행을 나타내는 레코드를 포함합니다. 각 레코드는 독창적 인 여행입니다. 그러나 나는 원정 여행 만하고 싶다. 그래서 나는 데이터베이스를 검색하고 서로에게 두 번의 여행을 매치시켜야합니다. 특정 위치에서 여행 및 여행.큰 mysql 데이터베이스에 대한 쿼리
스크립트가 제대로 작동합니다. 문제는 데이터베이스에 600,000 개 이상의 사례가 포함되어 있다는 것입니다. 가능하다면 피해야한다는 것을 알고 있습니다. 그러나 나중에이 스크립트와 데이터베이스 레코드를 사용하기 위해서는 모든 것이 함께해야합니다.
MAMP를 사용하여 iMac에서 실행할 때 스크립트를 실행하는 데 몇 시간이 걸립니다. 물론 나는 많은 메모리를 사용할 수 있다고 확신했다.
제 질문은 어떻게하면 속도를 높일 수 있습니까?이 작업을 수행하는 가장 좋은 방법은 무엇입니까?
$table = $_GET['table'];
$output = '';
//Select all cases that has not been marked as invalid in previous test
$query = "SELECT persid, ritid, vertpc, aankpc, jaar, maand, dag FROM MON.$table WHERE reasonInvalid != '1' OR reasonInvalid IS NULL";
$result = mysql_query($query)or die($output .= mysql_error());
$totalCountValid = '';
$totalCountInvalid = '';
$totalCount = '';
//For each record:
while($row = mysql_fetch_array($result)){
$totalCount += 1;
//Do another query, get all the rows for this persons ID and that share postal codes. Postal codes revert between the two trips
$persid = $row['persid'];
$ritid = $row['ritid'];
$pcD = $row['vertpc'];
$pcA = $row['aankpc'];
$jaar = $row['jaar'];
$maand = $row['maand'];
$dag = $row['dag'];
$thecountquery = "SELECT * FROM MON.$table WHERE persid=$persid AND vertpc=$pcA AND aankpc=$pcD AND jaar = $jaar AND maand = $maand AND dag = $dag";
$thecount = mysql_num_rows(mysql_query($thecountquery));
if($thecount >= 1){
//No worries, this person ID has multiple trips attached
$totalCountValid += 1;
}else{
//Ow my, the case is invalid!
$totalCountInvalid += 1;
//Call the markInvalid from functions.php
$totalCountValid += 1;
markInvalid($table, '2', 'ritid', $ritid);
}
}
//Echo the result
$output .= 'Total cases: '.$totalCount.'<br>Valid: '.$totalCountValid.'<br>Invalid: '.$totalCountInvalid; echo $output;
스크립트의 결과가 명확하지 않습니다. 테이블 구조에 대한 설명도 도움이 될 것입니다. – Andreas
결과는 어떤 경우가 '잘못된'으로 표시된다는 것입니다. 나는 DB 구조를 제공 할 수 있지만 거대한 (100 열 이상) –
markInvalid() 함수의 코드를 표시 할 수 있습니까? – Jocelyn