-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.6.3, 4.0.3
-
Component/s: None
-
None
-
ALL
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
I have documents with the following structure:
{{{_id:"asdf", consumed: true, timestamp: ISODate("2018-12-10T11:57:57.960+0000") }}}
For querying I have two different (non partial) indices:
- "timestamp_-1" (timestamp ascending)
- "consumed_1_timesamp_-1 (compound index with consumed ascending and timestamp ascending)
When I create a query like
find({consumed: false, timestamp: { "$lte" : ISODate("2018-12-10T11:57:57.960+0000")}}
the first index is used, which leads to bad performance.
In what case would be for this query the first index better than the second index? Since consumed is a Boolean, using the second index will always look at equal or lower elements - in my case 17.000 instead of 17.000.000 elements.
Attached is a explain('allPlansExecution') query. I added here a limit(400) query, since the evaluation would take several minutes when the first index is used.
I know that i can hint to the second index, but in this case it should be very trivial for mongodb-server to detect that the second index is better than the first index.