Skip to Content
MongoDB权威指南(第3版)
book

MongoDB权威指南(第3版)

by Shannon Bradshaw, Eoin Brazil, Kristina Chodorow
November 2021
Intermediate to advanced
410 pages
12h 1m
Chinese
Posts & Telecom Press
Content preview from MongoDB权威指南(第3版)
索引
107
不幸的是,关于索引什么时候有用以及什么时候有害,并没有一个固定的规则,因为这实
际上取决于数据、索引、文档和平均结果集的大小。根据经验,如果查询返回集合中
30%
或更少的文档,则索引通常可以加快速度。然而,这个数字会在
2%
60%
变动
。表
5-1
对索引和全表扫描通常适用的情况进行了总结。
5-1:影响索引效率的属性
索引通常适用的情况 全表扫描通常适用的情况
比较大的集合 比较小的集合
比较大的文档 比较小的文档
选择性查询 非选择性查询
假如现在有一个收集统计信息的分析系统。应用程序要根据给定的账户去系统中查询所有
的文档,以根据从一小时之前到最开始时间的所有数据来生成一个图表:
> db.entries.find({"created_at" : {"$lt" : hourAgo}})
"created_at"
上创建索引以加快查询速度。
最初运行时,结果集很小而且可以立即返回。但是几个星期之后,数据开始多起来,而一
个月之后,这个查询运行起来就会花费很长时间了。
对于大多数应用程序来说,这很可能就是那个“错误”的查询:你真的需要在查询中返回
数据集中的大部分内容吗?大部分应用程序不需要,尤其是那些拥有庞大数据集的应用程
序。然而,也有一些合理的情况可能需要获取大部分或者全部的数据。例如,可能需要将
这些数据导出到报表系统或在一个批处理任务中使用。在这些情况下,应该尽可能快地返
回数据集中的这些内容。
5.4
 索引类型
在创建索引时可以指定一些选项来改变索引的行为方式。接下来介绍一些常见的变体,而 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9787115576538