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

单独使用$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的组合时也发现了类似的问题。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值