[SERVER-8621] Non covered geo query is reported as a covered query Created: 19/Feb/13  Updated: 29/Jan/15  Resolved: 29/Jan/15

Status: Closed
Project: Core Server
Component/s: Geo, Querying
Affects Version/s: 2.4.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Sridhar Nanjundeswaran Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-8592 Projecting a field that has a 2dspher... Closed
Operating System: ALL
Participants:

 Description   

The test below shows indexOnly=true and nscannedObjects=0.

 
var coll = db.getCollection("covered_geo_2")
coll.drop()
 
coll.insert({_id : 1, loc1 : [ 5 , 5 ], type1 : "type1", loc2 : [ 5 , 5 ], type2 : 1})
coll.insert({_id : 2, loc1 : [ 6 , 6 ], type1 : "type2", loc2 : [ 5 , 5 ], type2 : 2})
coll.insert({_id : 3, loc1 : [ 7 , 7 ], type1 : "type3", loc2 : [ 5 , 5 ], type2 : 3})
 
coll.ensureIndex({loc1 : "2dsphere", type1 : 1});
coll.ensureIndex({type2: 1, loc2 : "2dsphere"});
 
var plan = coll.find({type2 : {$lt:3}}, {type2:1, loc2:1, _id:0}).hint({type2: 1, loc2:"2dsphere"}).explain();
assert.eq(false, plan.indexOnly, "geo.2.3 - indexOnly should be false for a covered query")
assert.neq(0, plan.nscannedObjects, "geo.2.3 - nscannedObjects should be 0 for a covered query")



 Comments   
Comment by David Storch [ 29/Jan/15 ]

This reporting issue was fixed as part of the query engine rewrite for 2.6:

> db.version()
2.6.7
> var coll = db.getCollection("covered_geo_2")
> coll.drop()
true
>
> coll.insert({_id : 1, loc1 : [ 5 , 5 ], type1 : "type1", loc2 : [ 5 , 5 ], type2 : 1})
WriteResult({ "nInserted" : 1 })
> coll.insert({_id : 2, loc1 : [ 6 , 6 ], type1 : "type2", loc2 : [ 5 , 5 ], type2 : 2})
WriteResult({ "nInserted" : 1 })
> coll.insert({_id : 3, loc1 : [ 7 , 7 ], type1 : "type3", loc2 : [ 5 , 5 ], type2 : 3})
WriteResult({ "nInserted" : 1 })
>
> coll.ensureIndex({loc1 : "2dsphere", type1 : 1});
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> coll.ensureIndex({type2: 1, loc2 : "2dsphere"});
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 2,
	"numIndexesAfter" : 3,
	"ok" : 1
}
> coll.find({type2 : {$lt:3}}, {type2:1, loc2:1, _id:0}).hint({type2: 1, loc2:"2dsphere"}).explain();
{
	"cursor" : "BtreeCursor type2_1_loc2_2dsphere",
	"isMultiKey" : false,
	"n" : 2,
	"nscannedObjects" : 3,
	"nscanned" : 3,
	"nscannedObjectsAllPlans" : 3,
	"nscannedAllPlans" : 3,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"type2" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		],
		"loc2" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		]
	},
	"server" : "dstorch-desktop:27017",
	"filterSet" : false
}

Note that the reporting is different in 3.0.x versions due to changes to explain made under SERVER-10448. Closing as a duplicate.

Comment by Sridhar Nanjundeswaran [ 17/Sep/13 ]

These are related bugs but not duplicates. SERVER-8592 is a projection issue. This one is about incorrectly marking the query as a covered query. Projecting a geo field always result in a document fetch which should not be classified as a covered query.

Comment by Daniel Pasette (Inactive) [ 16/Sep/13 ]

This is a misleading bug report. It is really a duplicate of SERVER-8592. The explain() report is correct in that it uses a covered index and the nscannedObjects is correct, but the actual data returned is incorrect because it can't satisfy the query without looking at the object.

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