Database Reference
In-Depth Information
index you're using). Here's an example that uses the triple-compound index you cre-
ated in the previous section:
db.values.find({open: 1}, {open: 1, close: 1, date: 1, _id: 0})
If you run explain() on this query, you'll see a field labeled indexOnly that's set to
true . This indicates that the index, and no actual collection data, was used to serve
the query.
Query optimization is always application-specific, but the hope is that the ideas and
techniques provided here will help you tune your queries for the better. Empirical
approaches are always useful. Make a habit of profiling and explaining your queries.
In the process, you'll continue learning about the hidden corners of the query opti-
mizer, and you'll ensure efficient queries for your application.
7.4
Summary
This chapter is hefty, no doubt, as indexing is an admittedly rich subject. If not all the
ideas are clear, that's okay. You should at least come away with a few techniques for
examining indexes and avoiding slow queries, and you should know enough to keep
learning. With the complexity involved in indexing and query optimization, plain old
experimentation may be your best teacher from here on out.
Search WWH ::




Custom Search