Hi Jeremy, Adam,
Below is the explain output of the query being issued
>doc = {"batch1": {"$lt":100000}, "batch2": {"$gt":99980}}
>db.myCollection.find(doc).explain()
{
"cursor" : "BtreeCursor batch2_1",
"nscanned" : 20,
"nscannedObjects" : 20,
"n" : 19,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"batch2" : [
[
99980,
1.7976931348623157e+308
]
]
}
}
>doc1 = {"batch1": {"$lt":10000}, "batch2": {"$gt":9980}}
>db.myCollection.find(doc).explain()
{
"cursor" : "BtreeCursor batch2_1",
"nscanned" : 25020,
"nscannedObjects" : 25020,
"n" : 19,
"millis" : 170,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"batch2" : [
[
74980,
1.7976931348623157e+308
]
]
}
}
The fields on which the query is being issued is named batch1 and batch2. The index created is not a composite index. There is index created on each field
{"batch1":1}
{"batch2":1}
Query is issued as below
Fields batch1 and batch2 can contain different values too. In this use case to keep it simple I am inserting same values in both the fields.
I observe that index bounds in on batch2 when docs is selected with value of x > 50k and index bounds is on batch1 with value of x < 50k (any reason for this behaviour?)
>> Can you describe how to reproduce this initial data set? <<
I spawn 10 threads each inserting 10000 documents. Where in Thread 1 inserts docs with values (for batch1 and bacth2) in the sequence 1, 11, 21, 31, ......99991, Thread 2 inserts docs in the sequence 2,12,22,32........99992 continuing Thread 10 inserts 10, 20, 30........100000. This was done to make sure I don't have the values in serial order on storage.
Also, when I select a value for x it is always on the higher side. That is say, I am selecting from the range 26k-50K x value ranges closer to 50K.
Thanks
Praveen