I have table with 300 000 records (MyISAM). I get record from this table with this function:
public function loadRows() {
if (!$this->result)
die("Nothing found!");
$this->rows = array();
while ($r = mysql_fetch_array($this->result, MYSQL_ASSOC))
$this->rows[] = $r;
//mysql_free_result($this->result);
return $this->rows;
}
The estimate time for showing 100 records from this table is 6 seconds, very slowly and the MEMORY used from this query is 512 MB. Where I’m wrong?
The query is:
SELECT i.* FROM inv i
LEFT JOIN (inv_m im) ON (i.m_id = im.id)
LEFT JOIN (inv_f iff) ON (iff.num = i.num)
LEFT JOIN (temp_a ta) ON (ta.num = i.num)
WHERE i.vid = 1
AND iff.num IS NULL
AND ta.num IS NULL
LIMIT 100
For i.vid I show all records.
Declared INDEXES:
i.m_id INDEX
im.id PRIMARY KEY
iff.num INDEX
i.num INDEX
ta.num INDeX
THE EXPLAIN RESULT
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE i ref vid vid 4 const 85343 Using where
1 SIMPLE im eq_ref PRIMARY PRIMARY 4 checksys_r1.i.m_id 1
1 SIMPLE iff ref num num 182 checksys_r1.i.num 1 Using where
1 SIMPLE ta ref num num 194 checksys_r1.i.num 1 Using where
Start with running:
look for things like a full row scan, file i/o, etc. Post the results here. Sometimes a table might need repairing as well.
Also, is there any reason you’re using MyISAM over InnoDB?