开发者

indexing keys AND related columns or just keys to increase speed in mysql

开发者 https://www.devze.com 2023-03-29 11:39 出处:网络
So if I have an sql query like these: SELECT title, document FROM docs WHERE id = \"1\" and type = \"2\"

So if I have an sql query like these:

SELECT title, document FROM docs WHERE id = "1" and type = "2"

SELECT title FROM docs WHERE id = "1" 

SELECT title FROM docs WHERE member = "foo"

to maximize speed for the first one i. would I have to index only the keys (id and type together? seperate?) ii. would I also have to index title an开发者_如何学编程d document (together,separate)

same type of questions apply for the second one, and for the third query i. would I have to index only member? IM just trying to understand mysql retrieval and indexing.


You need 2 indexes

(id, type, title)
(member, title)
  • id, type makes id redundant
  • adding title makes the index covering


1) Index both id and type together, but not title and document

2) Index id only

3) index member only

in other word you have to index {id}, {id, type}, {member}

0

精彩评论

暂无评论...
验证码 换一张
取 消