Operational Defect Database

BugZero found this defect 2498 days ago.

MongoDB | 377332

[SERVER-28957] Index bounds are not detected correctly

Last update date:


Affected products:

MongoDB Server

Affected releases:


Fixed releases:

No fixed releases provided.



Documents with two fields: {sort:..,x:...} Index on {sort:1,x:1} The query on "x" sorted by the sort field doesn't detect proper index bounds for x: > db.test.find({x:{$gte:1,$lte:3}}).sort({sort:1}).explain("executionStats").executionStats.executionStages.inputStage.indexBounds { "sort" : [ "[MinKey, MaxKey]" ], "x" : [ "[MinKey, MaxKey]" ] } However, adding an all-inclusive condition on "sort" into the query fixes the problem: > db.test.find({sort:{$gte:MinKey},x:{$gte:1,$lte:3}}).sort({sort:1}).explain("executionStats").executionStats.executionStages.inputStage.indexBounds { "sort" : [ "[MinKey, MaxKey]" ], "x" : [ "[1.0, 3.0]" ] }

Top User Comments

david.storch commented on Mon, 8 May 2017 17:06:50 +0000: I am closing as a duplicate of SERVER-13197. The scenarios are slightly different (this one uses a sort, the other uses a hint) but the essence is the same: when there is no predicate on the leading field of the index, the query planner is not able to constrain the index bounds of the trailing fields. There is no fundamental reason that we couldn't construct bounds for the trailing fields. However, the planner has quite a bit of index selection and plan enumeration logic which depends on differential treatment of leading versus trailing fields of a compound index. Extending the planner to generate better index bounds in cases like this one will therefore involve significant development effort from the Query Team.

Additional Resources / Links


BugZero Risk Score

Coming soon



Have you been affected by this bug?


Do you know how much operational outages are costing you?

Understand the cost to your business and how BugZero can help you reduce those costs.


Login to read and write comments.

Have you ever...

had your data corrupted from a