MongoDB takes different time for with and without hint

梦想的初衷 提交于 2020-01-25 07:06:48

问题


I know, I know, hint forces MongoDB to use a specific index.

I have two queries:

db.mycol.find({sourceId:ObjectId("596bac5a6f473e1a042bFFFF"),myFlag:false}).count()

db.mycol.find({sourceId:ObjectId("596bac5a6f473e1a042bFFFF"),myFlag:false}).hint("sourceId_-1_myFlag_-1").count()

Both of these commands take different time:

Without hint: 4-6 seconds
With hint : 0-1 second

However, both of the commands are using the same index:
{ "sourceId" : -1, "myFlag" : -1 }

When I execute db.mycol.aggregate( { $indexStats: { } } ), I can see the accesses.ops count increases for the same index.

Even explain shows me the same index will be used!

来源:https://stackoverflow.com/questions/46584233/mongodb-takes-different-time-for-with-and-without-hint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!