[SERVER-16655] Geo predicate is unable to use compound 2dsphere index if it is root of $or clause Created: 23/Dec/14  Updated: 11/Mar/15  Resolved: 17/Jan/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.6
Fix Version/s: 2.6.8, 3.0.0-rc6

Type: Bug Priority: Major - P3
Reporter: Linda Qin Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

Query:

{
	"a" : {
		"$gt" : 5
	},
	"b" : {
		"$lt" : 500
	},
	"$or" : [
		{
			"startLoc" : {
				"$geoWithin" : {
					"$geometry" : {
						"type" : "MultiPolygon",
						"coordinates" : [[[[-1,-1],[2,-2],[2,2],[-2,2],[-1,-1]]]]
					}
				}
			}
		},
		{
			"endLoc" : {
				"$geoWithin" : {
					"$geometry" : {
						"type" : "MultiPolygon",
						"coordinates" : [[[[-1,-1],[2,-2],[2,2],[-2,2],[-1,-1]]]]
					}
				}
			}
		}
	]
}

  1. Insert a document

    db.docs.insert({a: 100, b: 100, startLoc: {type: "Point", coordinates: [0,0]}, endLoc: {type: "Point", coordinates: [1,1]}})

  2. When the indexes are not compound indexes, the query can use the indexes:

    db.docs.ensureIndex({startLoc: "2dsphere"}) 
    db.docs.ensureIndex({endLoc: "2dsphere"})
    db.docs.getIndexKeys()
    db.docs.find({a: {$gt: 5},b: {$lt: 500}, startLoc:{"$geoWithin" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [[[[-1,-1],[2,-2],[2,2],[-2,2],[-1,-1]]]]}}} }).explain(true)

  3. When the indexes are compound 2dsphere indexes, the query cannot use the indexes:

    db.docs.dropIndexes()
    db.docs.ensureIndex({startLoc: "2dsphere", a: 1, b: 1})
    db.docs.ensureIndex({endLoc: "2dsphere", a: 1, b: 1})
    db.docs.getIndexKeys()
    db.docs.find({a: {$gt: 5},b: {$lt: 500}, startLoc:{"$geoWithin" : { "$geometry" : { "type" : "MultiPolygon", "coordinates" : [[[[-1,-1],[2,-2],[2,2],[-2,2],[-1,-1]]]]}}} }).explain(true)

Participants:

 Description   

Please refer to the steps to reproduce the issue. This issue doesn't affect compound 2dsphere index that is {2dsphereIndexVersion: 1}



 Comments   
Comment by Githook User [ 22/Jan/15 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-16655 do not strip index tags from geo predicates during planning for V2 2dsphere indices

(cherry picked from commit 22ee5a4e87131a2b3791845c96edf4cde5028ba2)
Branch: v2.6
https://github.com/mongodb/mongo/commit/28b9b81eba5b79f1f83404d2220668fcbacd1aec

Comment by Githook User [ 17/Jan/15 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-16655 do not strip index tags from geo predicates during planning for V2 2dsphere indices
Branch: master
https://github.com/mongodb/mongo/commit/22ee5a4e87131a2b3791845c96edf4cde5028ba2

Generated at Thu Feb 08 03:41:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.