[SERVER-23065] Geo predicate beneath $elemMatch object causes planner to ignore valid index with 2dsphereIndexVersion > 1 Created: 10/Mar/16 Updated: 05/May/16 Resolved: 21/Apr/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance, Querying |
| Affects Version/s: | 3.0.10, 3.2.4 |
| Fix Version/s: | 3.3.5 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Bernard Gorman | Assignee: | David Storch |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||
| Operating System: | ALL | ||||||||||||
| Sprint: | Query 13 (04/22/16) | ||||||||||||
| Participants: | |||||||||||||
| Description |
| Comments |
| Comment by Githook User [ 21/Apr/16 ] | |||||||||||||||
|
Author: {u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}Message: | |||||||||||||||
| Comment by David Storch [ 18/Apr/16 ] | |||||||||||||||
|
Simplified repro script:
| |||||||||||||||
| Comment by David Storch [ 23/Mar/16 ] | |||||||||||||||
|
We are still investigating the complexity of a fix, but I would like to provide some information regarding the diagnosis of this issue. The index selection phase of query planning involves a process of matching predicates to indices. QueryPlannerIXSelect contains a suite of functions which tag predicates with the indices that they can use. For example, the predicate "field a is less than 3" is tagged to indicate that it can use the second position of the compound index {b: 1, a: 1}. As part of this process, we must enforce the "geo-sparseness" property of 2dsphere indices with 2dsphereIndexVersion 2 or 3. The geo-sparseness property is documented here and was introduced in MongoDB 2.6 as part of 2dsphereIndexVersion 2. The sparseness property means that only documents which store geometry in the 2dsphere-indexed path generate index keys which are inserted into the index. For example, if you have index {a: 1, b: "2dsphere"}, only documents containing geometry inside field b get indexed. The consequence of this sparseness property is that, for index {a: 1, b: "2dsphere"}, a query on a but not b cannot use the index since this will miss any documents that have no b field. This is enforced via a function that removes assignments to 2dsphere indices that are logically incorrect: QueryPlannerIXSelect::stripInvalidAssignmentsTo2dsphereIndices(). For the problem query reported in this ticket, assignments to the 2dsphere index are stripped when they should not be. This happens because the code expects the predicate over b and the predicate over the 2dsphere field d.f to be at the same level in the abstract syntax tree. Since the d.f geo predicate is beneath an $elemMatch and not directly joined to b by an AND node, we mistakenly remove the assignment of b to the index. The end result is a COLLSCAN plan. |