I'm aware what a "full collection scan" is. But i'm a little unsure if the term "collection scan" applies to queries that use B-tree cursor. Do queries that use a cursor other than the basic cursor perform a collection scan?
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- How to convert from Timestamp to Mongo ObjectID
- MongoDB Indexing: Multiple single-field vs single
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- MongoError: cannot infer query fields to set, path
- Pymongo $in Query Not Working
- django.core.exceptions.ImproperlyConfigured: '
- How to represent an array with mixed types
The short answer is the two terms are the same, or rather there is only "full collection scan".
If your query is using a B-tree cursor it is by definition not scanning the collection put is traversing the index in order to find the queried documents.
A collection scan occurs where no index can satisfy the query and we have to scan the full collection in order to find the required documents. See the link for all the information.
http://docs.mongodb.org/manual/reference/method/cursor.explain/
A collection scan is, well, literally scanning the whole collection. This happens when the user requests to find documents using some conditions that do cannot be answered using an index. For example lets say, we have a users collection with fields such as name, age, hair color, address, phone number and country
Further if we have an index on name and query the DB using,
Here since we have an index on the name field the query optimizer would use the index as a performance optimizing approach.
Suppose you query the DB for some other field. Lets say, address
Here the query optimizer would love to shorten its response time for the query, but since it has no prior information about the records in the collection, it has to go through each and every document in the collection to see if that document's address field matched the one in the query. If it does then we return that document. I am sure you know this is where the index comes in since it maintains pointers by "grouping" docs according to certain criteria.
For more info, you can look here.
For your question, a query that uses a B-tree cursor, does it to avoid performing a collection scan and hence queries using any kind of cursor other than the basic cursor "mostly" avoid a collection scan.
You can force it perform a collection scan even if theres exists an index on the field that is being queried. You can read about it here