您的位置:首页 > 数据库 > Mongodb

在MongoDB中组合使用$or、sort()或$or、$and时,查询性能可能会很差

2017-12-28 10:14 721 查看
单独使用$or、$and、sort()时,查询性能均可,但$or与$and或sort()组合查询,其时长会增加几倍!!!

后来在官方论坛中提问,得知有一个bug:https://jira.mongodb.org/browse/SERVER-1205

将来会修改,今天先记录一下。

论坛回复:

I believe the issue you are running into is expressed in this JIRA 

ticket: https://jira.mongodb.org/browse/SERVER-1205 

I believe the query optimizer is choosing to use the name index and 

walk it backwards. As it goes through the index it compares the user 

and owner attributes to your parameters and collects them in sorted 

order. As a result the nscanned objects is much larger than in the 

other two cases. 

I would vote up the issue to prioritize it. 

-Tyler 

 

原帖地址:http://groups.google.com/group/mongodb-user/browse_thread/thread/58428702d9485b8/40d6db4604a95a69?lnk=gst&q=gen+liu+%24or#40d6db4604a95a69

 

注:如果查询中使用了$or,并且查询元素有索引的话,那么也会使用该元素的索引的。换句话说,如果查询中只有$or时(无sort时),不会出现这里的问题。另外在使用$and和$or的组合时也发现了类似的问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mongodb
相关文章推荐