何时在mongodb中建立索引有意义?
mLab慢查询分析器中的示例:
Log lines read
8 hours of logs starting at 2019-02-14 12:25 (2019-02-14 11:25 UTC)
find command
{"myArray":{"$all":["<vals>"]},"myBoolean":{"$ne":"<val>"}}
sort
{"myDate":-1}
total time (all occurrences)
5 seconds, 127 milliseconds
average time
394 milliseconds
query count
13
average documents / index keys examined
50,000 / 50,000
in-memory sort
yes
recommended index
index: {"myDate": -1, "myArray": 1, "myBoolean": 1}
一个性能不佳的查询,遍历所有文档,甚至在内存中排序。但是,查询在8小时内仅发生了13次,总共花费了5秒。
构建索引确实有意义时的参数和值是什么,例如在要建立索引之前,查询要分析的8个小时日志中有多少时间可以占用?