我有 300 000 条记录的表(MyISAM)。我使用此功能从该表中获取记录:
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;
}
显示该表中的 100 条记录的估计时间为 6 秒,非常慢,该查询使用的 MEMORY 为 512 MB。我哪里错了?
查询是:
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
对于 i.vid,我显示所有记录。
声明的索引:
i.m_id 索引
im.id 主键
iff.num 索引
i.num 索引
ta.num 索引
解释结果
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