Suppose I have a million records in db with 10 fields / ("columns") in db. It seems to me that the more columns I search, the faster the query is executed - for example:
db.items.find( {
$and: [
{ field1: x },
{ field2: y },
{ field3: z}
]
} )
faster than:
db.items.find( {
$and: [
{ field1: x },
{ field2: y }
]
} )
While I would like to say, “Great, that makes complete sense to me” - that’s not so. I just know that this is happening in my particular case and I wonder if it really is. If so, ideally, I would like to know why.
In addition, when creating indexes with multiple fields, it helps them in any order. For example, let's say I add a composite index :
db.collection.ensureIndex( { field1: 1, field2: 1, field3: 1 } )
- ? , ? , 90% 1, 1% 3. - ?