Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k 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 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...