在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的组合时也发现了类似的问题。
后来在官方论坛中提问,得知有一个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中一起使用$or和sort()时,查询性能可能会很差
- 在MongoDB中一起使用$or和sort()时,查询性能差的一种解决方案
- 在MongoDB中一起使用$or和sort()时,查询性能差的一种解决方案
- mongoDB 性能优化:如何使用普通查询语句替代 aggregate 操作?
- mongoDB 性能优化:如何使用普通查询语句替代 aggregate 操作?
- 在MongoDB中一起使用$or和sort()
- MongoDB 组合多个条件查询($and、$in、$gte、$lte)
- 变长参数(void sortAndPrint(int... entrys))的使用
- SAP ABAP 性能优化技巧 — 使用 ABAP “Sort” 取代 “Order By”
- 在合适的场合使用 with (nolock) 提升查询性能
- linux下使用sort命令升序、降序、随机及组合方式排序方法
- About how to use Edit Control and SPin Control together! (关于怎么组合使用Edit Control 和 Spin Control 增加浮点数)
- 在使用Hibernate时,因为一个查询需要更多的表连接而要使用SQL来解决性能问题。然而返回的结果集中包含了没有映射的Entity类中的表字段,在这个SQL中还有使用如何将层次关系的父子结点显示为横行
- MongoDB java api for 插入和单collection基本查询使用示例
- 使用Oracle 10g中的等待界面诊断性能问题(查询会话等待,查询慢的现象)
- MongoDB学习笔记5 - 测试查询性能
- SQL点滴10—使用with语句来写一个稍微复杂sql语句,附加和子查询的性能对比
- 数据库查询性能优化(合理使用索引|避免或简化排序|避免对大型表进行全表顺序扫描|避免使用相关的子查询|避免使用通配符匹配 )
- 在ORACLE 中使用Instr和Decode函数处理组合查询
- 使用临时表提升SqlServer视图查询性能