在蒙戈DBMongoDB中查找()全扫描与指数
> show dbs
admin (empty)
data 23.9423828125GB
local (empty)
我有一个表与索引:
> db.XXX.count();
80089670
C#:
voteCol.EnsureIndex("({ YYY:1 })");
当我做一个查询与C#驱动程序:
MongoCollection<BsonDocument> voteCol = database.GetCollection<BsonDocument>("XXX");
var query = new QueryDocument("YYY", DataUtils.getItemInPollIdList());
MongoCursor<BsonDocument> cursor = voteCol.Find(query).SetSortOrder(SortBy.Descending("ZZZ")).SetLimit(10).SetSkip(20);
的执行时间为这部分代码是接近0
然后,当我试图让光标
cursor.Size();
我得到一个超时的大小。
无法读取从传输连接数据:连接 尝试失败,因为连接的方没有正确一段时间后应对 ,或已建立的连接失败,因为 连接的主机没有反应。
在蒙戈登录
周一年08月22十点08分50秒[conn9]查询data.XXX ntoreturn:1个reslen:36 nscanned:80089670 {YYY: “1482092”} nreturned:0 48935ms
它可能是什么?查询真的执行了吗?为什么我不能得到结果?
编辑1:增加新的索引
即使有新的索引周一年08月22 10点17分38秒[conn12]上建立新的索引{({YYY:-1}):1} 为data.XXX
4000000/80089670 4% 7866400/80089670 9% 11403000/80089670 14% 15000000/80089670 18% 19000000/80089670 23% 22988600/80089670 28% 26454700/80089670 33% 30000000/80089670 37% 33438600/80089670 41% 37000000/80089670 46% 40810600/80089670 50% 44132200/80089670 55% 48000000/80089670 59% 52000000/80089670 64% 55618300/80089670 69% 59000000/80089670 73% 62170100/80089670 77% 66000000/80089670 82% 70000000/80089670 87% 74000000/80089670 92% 77874500/80089670 97%
- 同样的问题: 蒙戈外壳:
> printjson(db.XXX.findOne({YYY:"1517077"}));
MongoLog
Mon Aug 22 10:33:40 [conn4] query data.XXX ntoreturn:1 reslen:36 nscanned:80089670 { YYY: "1517077" } nreturned:0 48751ms
它扫描了80百万个文件,需要很多时间) –
@Hohhi为什么?我添加了一个索引。你能解释完整的扫描吗? – JohnJohnGa
这是它在日志中写的:nscanned:80089670 –