Skip to content

Range searches do not use available index #20

@edwardcoolson

Description

@edwardcoolson

Range searches perform slow even if the index is created for those searches. I tried range query using the example code from Indices & Performance doc chapter:

var db = new ForerunnerDB(),
    names = ['Jim', 'Bob', 'Bill', 'Max', 'Jane', 'Kim', 'Sally', 'Sam'],
    collection = db.collection('test'),
    tempName,
    tempAge,
    i;

for (i = 0; i < 100000; i++) {
    tempName = names[Math.ceil(Math.random() * names.length) - 1];
    tempAge = Math.ceil(Math.random() * 100);

    collection.insert({
        name: tempName,
        age: tempAge
    });
}

collection.ensureIndex({
  age: 1
});

var explained = collection.explain({
  age: {
    '$gte': 30,
    '$lte': 40
  }
});

'Explained' object has tableScan: 100000 as if no index is used.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions