mongodb AND查询遇到多个index时候可能会做交集——和复合索引不同
关于MongoDB中索引文档的一个问题?
-
To illustrate index intersection, consider a collection orders that has the following indexes:
{ qty: 1 }
{ item: 1 }
MongoDB can use the intersection of the two indexes to support the following query:
db.orders.find( { item: "abc123", qty: { $gt: 15 } } )
上面是MongoDB的索引文档,说下面这个查询能交叉利用上面两个索引进行优化,可是根据我的理解,需要建立一个多重索引才行,如下:
{ qty: 1, item: 1 }
建立两个索引是建立两个独立的B+树,多重索引则是建立一颗B+树,如果两颗B+树是独立的,怎么才能交叉利用呢?
还有下面这个例子,也不知道如何才能混合利用起来?
Consider a collection orders with the following indexes:
{ qty: 1 }
{ status: 1, ord_date: -1 }
To fulfill the following query which specifies a condition on both the qty field and the status field, MongoDB can use the intersection of the two indexes:
db.orders.find( { qty: { $gt: 10 } , status: "A" } )
看问题似乎很神奇。。不过实际看过去也没啥变化。。
determine if MongoDB used index intersection, run explain(); the results of explain()will include either an AND_SORTED stage or an AND_HASH stage.
归并排序或hash 组合。 类似join的做法。
Stages are descriptive of the operation; e.g.
COLLSCANfor a collection scanIXSCANfor scanning index keysFETCHfor retrieving documentsSHARD_MERGEfor merging results from shards
Index Intersection
For an index intersection plan, the result will include either an AND_SORTED stage or an AND_HASH stage with an inputStages array that details the indexes; e.g.:
{
"stage" : "AND_SORTED",
"inputStages" : [
{
"stage" : "IXSCAN",
...
},
{
"stage" : "IXSCAN",
...
}
]
}
In previous versions of MongoDB, cursor.explain() returned the cursor field with the value of Complex Plan for index intersections.
转自:http://www.ihowandwhy.com/z/%E5%85%B3%E4%BA%8EMongoDB%E4%B8%AD%E7%B4%A2%E5%BC%95%E6%96%87%E6%A1%A3%E7%9A%84%E4%B8%80%E4%B8%AA%E9%97%AE%E9%A2%98%EF%BC%9F
mongodb AND查询遇到多个index时候可能会做交集——和复合索引不同的更多相关文章
- 深入理解MongoDB的复合索引
更新时间:2018年03月26日 10:17:37 作者:Fundebug 我要评论 对于MongoDB的多键查询,创建复合索引可以有效提高性能.这篇文章主要给大家介绍了关于MongoDB复 ...
- 二十、oracle通过复合索引优化查询及不走索引的8种情况
1. 理解ROWID ROWID是由Oracle自动加在表中每行最后的一列伪列,既然是伪列,就说明表中并不会物理存储ROWID的值:你可以像使用其它列一样使用它,只是不能对该列的值进行增.删.改操作: ...
- 关于mongodb的复合索引新功能
最新在做一个项目,由于查询字段较多,且查询较频繁,所以我做了一个复合索引,将所有需要查询的字段都做到索引里,做了一个名为s_1_m_1_c_1_v_1_year_1_month_1_week_1_da ...
- mongodb索引 复合索引
当我们的查询条件不只有一个时,就需要建立复合索引,比如插入一条{x:1,y:2,z:3}记录,按照我们之前建立的x为1的索引,可是使用x查询,现在想按照x与y的值查询,就需要创建如下的索引 创 ...
- MongoDB学习笔记(11)-- Index
索引通常能够极大的提高查询的效率,如果没有索引,MongoDB在读取数据时必须扫描集合中的每个文件并选取那些符合查询条件的记录. 这种扫描全集合的查询效率是非常低的,特别在处理大量的数据时,查询可以要 ...
- MongoDB 数据类型查询 — $type使用
MongoDB 使用过程中经常需要根据字段的类型来查询数据, 而MongoDB中查询字段类型是通过$type操作符来实现. $type使用法语: db.集合名.find({$type:类型值}); / ...
- MongoDB慢查询与索引
MongoDB慢查询 慢查询分析 开启内置的慢查询分析器 db.setProfilingLevel(n,m),n的取值可选0,1,2 0:表示不记录 1:表示记录慢速操作,如果值为1,m需要传慢查询的 ...
- TODO:MongoDB的查询更新删除总结
TODO:MongoDB的查询更新删除总结 常用查询,条件操作符查询,< .<=.>.>=.!= 对应 MongoDB的查询操作符是$lt.$lte.$gt.$gte.$ne ...
- SQL Server-聚焦强制索引查询条件和Columnstore Index(九)
前言 本节我们再来穿插讲讲索引知识,后续再讲数据类型中的日期类型,简短的内容,深入的理解,Always to review the basics. 强制索引查询条件 前面我们也讲了一点强制索引查询的知 ...
随机推荐
- 21Spring重用切点表达式
直接看代码: package com.cn.spring.aop.impl; //加减乘除的接口类 public interface ArithmeticCalculator { int add(in ...
- SQL-如何使用 MongoDB和PyMongo。
先决条件 在开始之前,请确保已经安装了 PyMongo 发行版. 在 Python shell 中,下面的代码应该在不引发异常的情况下运行: >>> import pymongo 假 ...
- 我们参与投资36Kr股权众筹项目“易途8”的决策过程
背景 中文接机.中文送机.中文包车. 当地玩乐 最大的竞争对手:皇包车,15年9月A轮 其它对手:唐人接等,订单量无法和 皇包车.易途8比. 看好理由 1.旅游行业和境外自由行,是 ...
- Windows Server 2012 防火墙如何添加端口例外的方法(转)
Windows Server 2012 防火墙如何添加端口例外的方法 Windows Server 2012 防火墙如何添加端口例外的方法 在Windows Server 2012系统中,如果用户想在 ...
- [K/3Cloud] 代码中设置某个字段必录
Control ctl = this.GetControl(fieldKey); FieldEditor editCtl = ctl as FieldEditor; if (editCtl != nu ...
- CF676E:The Last Fight Between Human and AI
人类和电脑在一个多项式上进行博弈,多项式的最高次项已知,一开始系数都不确定.电脑先开始操作,每次操作可以确定某次项的系数,这个系数可以是任意实数.给出一个博弈中间状态,最后如果这个多项式被x-K整除就 ...
- HDU——3342 Legal or Not
Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Mybatis教程(一)
1 Mybatis教程(一) 学习过的持久层框架:DBUtils , Hibernate Mybatis就是类似于hibernate的orm持久层框架. 为什么学Mybatis? 目前最主流 ...
- sql语句在Mysql中如何执行?
1.MySQL 主要分为 Server 层和引擎层,Server 层主要包括连接器.查询缓存.分析器.优化器.执行器,同时还有一个日志模块(binlog),这个日志模块所有执行引擎都可以共用,redo ...
- spring 拦截器整体配置
1.spring boot拦截器默认有 HandlerInterceptorAdapter AbstractHandlerMapping UserRoleAuthorizationIntercepto ...