이 mysql을/젠드 내 간단한 쿼리입니다 :Zend에서 내 쿼리를 최적화하는 방법은 무엇입니까?
// Get Patients
$table = new Model_Patient_DbTable();
$select = $table->select();
$select->from('patient');
$select->setIntegrityCheck(false);
// insurance join
$select->joinLeft('insurance', 'patient.insuranceId=insurance.Id',
array('insName' => 'insName'));
// Get total no of records
$totalRecords = count($table->fetchAll($select));
// Filters
if($inactive) {
$select->where('patient.inactive = ?', $inactive);
}
// Other where clause conditions
// Fetch filtered patient records
$patientRecords = $table->fetchAll($select);
// Get total no of filtered patient records
$filteredRecords = count($table->fetchAll($select));
내가 WHERE 절에 일부 조건에 따라 점점 환자 기록과 보험을 얻을입니다 위 젠드 쿼리합니다. 나는 (1) 총 레코드 수, (2) 총계 필터링 된 레코드 수 및 (3) 웹 페이지에 표시 할 환자 기록.
문제는 위의 쿼리에서 10,000 레코드가있을 때 성능이 저하되는 레코드를 3 회 가져와야한다는 것입니다. 쿼리를 최적화하여 레코드를 한 번만 가져 오거나 모든 레코드를 가져 오는 대신 레코드의 총 수만 가져 오는 계산을위한 별도의 쿼리가 있어야합니다.
모든 답변을 부탁드립니다. 이 같은
먼저 PHP 카운트를해서는 안됩니다. MySQL의 count 메소드를 사용하여 기준에 맞는 레코드 수를 파악하십시오. – JohnP
@JohnP : 네가 쓰고 있습니다.하지만 젠드에서 어떻게하는지 설명 할 수 있습니까? 감사. – Awan