主表中的where条件加了组合索引,但还是出现了:using temporary, using filesort
请教各位大神,如何优化
谢谢!
EXPLAIN SELECT DISTINCT
(store_id),
c.id,
title,
count,
CODE,
time,
type
FROM
product AS p
LEFT JOIN store AS s ON (p.store_id = s.id)
WHERE
s. STATUS = 'active'
AND (
s.image != ''
OR s.image IS NOT NULL
)
AND p.is_active = 'yes'
AND is_available = '1'
AND title <> ''
AND type = 'code'
AND (
time != '0000-00-00 00:00:00'
OR time > now()
)
AND store_id NOT IN (
1,
2,
)
ORDER BY
id DESC
LIMIT 1000
把你现在已经建立的复合索引贴出来看看,因为你用到了排序,应该要把你排序字段也加入到这个符合索引里面