MongoDB in Action Second Edition笔记之基于Index查询优化
2016-09-29 10:45
483 查看
查看查询过程的方法
查看所有的使用index的查询方案
强制使用某种index的方法
index cache
hint() forces the query optimizer to use a particular index:
这个模式记录了当你请求
index cache失效的三种情景:
1. 100 writes are made to the collection.
2. Indexes are added or removed from the collection.
3. A query using a cached query plan does a lot more work than expected. Here,what qualifies as “a lot more work” is a value for nscanned exceeding the cached nscanned value by at least a factor of 10.
查看所有的使用index的查询方案
强制使用某种index的方法
index cache
查看查询过程的方法:
> db.inventory.find({"quantity": 500, "type":"toys"}).limit(1).explain("executionStats")
查看所有的使用index的查询方案:
mongoDBv3.0 interprets true as allPlansExecution and false as queryPlannerdb.values.find({stock_symbol: "GOOG", close: {$gt: 200}}).explain(true)
强制使用某种index的方法
It’s understandable why the optimizer rejects the collection scan, but it might be less clear why the index on {close: 1} doesn’t satisfy. You can use hint() to find out.hint() forces the query optimizer to use a particular index:
query = {stock_symbol: "GOOG", close: {$gt: 200}} db.values.find(query).hint({close: 1}).explain()
index cache
当查询执行成功后,该查询模式会被记录下来,如下:{ pattern: { stock_symbol: 'equality', close: 'bound', index: { stock_symbol: 1 }, nscanned: 894 } }
这个模式记录了当你请求
stock_symbol的精确匹配(equality)和
close的区间匹配(bound)时,使用index{stock_symbol:1}
index cache失效的三种情景:
1. 100 writes are made to the collection.
2. Indexes are added or removed from the collection.
3. A query using a cached query plan does a lot more work than expected. Here,what qualifies as “a lot more work” is a value for nscanned exceeding the cached nscanned value by at least a factor of 10.
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- 如何在 Fedora 上安装 MongoDB 服务器
- PHP添加yaf xhprof mongodb 同理
- mongodb安装
- 如何在 Ubuntu 上安装 MongoDB
- 信息安全聚合 Sec-News 的重构之路
- Ruby on Rails框架程序连接MongoDB的教程
- perl操作MongoDB报错undefined symbol: HeUTF8解决方法
- C#中使用1.7版本驱动操作MongoDB简单例子
- 使用zabbix监控mongodb的方法
- Node.js的MongoDB驱动Mongoose基本使用教程
- MongoDB系列教程(四):设置用户访问权限
- MongoDB安装图文教程
- ASP.NET MVC4使用MongoDB制作相册管理
- node.js连接mongoDB数据库 快速搭建自己的web服务
- php mongodb操作类 带几个简单的例子
- php实现的mongodb操作类实例
- 解决mongodb在ubuntu下启动失败,提示couldn‘t remove fs lock errno:9 Bad file descriptor的错误
- 在PostgreSQL的基础上创建一个MongoDB的副本的教程