[DOCS-478] The same query show up in both able and unable to use index in Indexing Strategies Created: 03/Sep/12  Updated: 30/Oct/23  Resolved: 28/Sep/12

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: v1.0
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: trgoofi Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: JPEG File index.jpg    
Participants:
Days since reply: 11 years, 20 weeks, 5 days ago

 Description   

db.collection.find( { b:

{ $gt:5 }

} ).sort(

{ a:1, b:1 }

) show up in both be able to use the index and not be able to sort the results using the index.(example of Sort Using Indexes).



 Comments   
Comment by auto [ 28/Sep/12 ]

Author:

{u'date': u'2012-09-27T19:21:20-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: DOCS-478: correction
Branch: master
https://github.com/mongodb/docs/commit/db8b36d1ec9b3ddfac6c3f0665216116462caa71

Comment by Gianfranco Palumbo [ 17/Sep/12 ]

This query actually uses the index.

> db.test.find()
{ "_id" : ObjectId("5056fd76470a0d3629ece36c"), "a" : 4, "b" : 5 }
{ "_id" : ObjectId("5056fd80470a0d3629ece36d"), "a" : 5, "b" : 3 }
{ "_id" : ObjectId("5056fd92470a0d3629ece36e"), "a" : 5, "b" : 3, "d" : 5 }
{ "_id" : ObjectId("5056fd98470a0d3629ece36f"), "a" : 5, "b" : 3, "c" : 3 }
{ "_id" : ObjectId("5056fd9d470a0d3629ece370"), "a" : 5, "b" : 3, "c" : 3, "d" : 2 }
{ "_id" : ObjectId("5056fda0470a0d3629ece371"), "a" : 5, "b" : 3, "c" : 3, "d" : 5 }
{ "_id" : ObjectId("5056fdac470a0d3629ece372"), "a" : 5, "b" : 6 }
 
> db.test.ensureIndex({ a: 1, b: 1, c: 1, d: 1 })
 
> db.test.find( { b:{ $gt:5 } } ).sort( { a:1, b:1 } ).explain()
{
	"cursor" : "BtreeCursor a_1_b_1_c_1_d_1",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 1,
	"nscanned" : 3,
	"nscannedObjectsAllPlans" : 5,
	"nscannedAllPlans" : 7,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	....
}

So should go in the first part

Comment by auto [ 11/Sep/12 ]

Author:

{u'date': u'2012-09-11T12:02:04-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: DOCS-478 correction
Branch: master
https://github.com/mongodb/docs/commit/09f6b725f433bd89f6c2f664d189fb270c30bca3

Generated at Thu Feb 08 07:38:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.