Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

此句sql,如何添加索引

主表中的where条件加了组合索引,但还是出现了:using temporary, using filesort
请教各位大神,如何优化
谢谢!

image

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

把你现在已经建立的复合索引贴出来看看,因为你用到了排序,应该要把你排序字段也加入到这个符合索引里面


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...