[SERVER-9207] Unexpected query plan for a $or condition Created: 02/Apr/13  Updated: 07/Mar/14  Resolved: 08/Jan/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alvin Richards (Inactive) Assignee: David Storch
Resolution: Done Votes: 0
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server9207.js    
Operating System: ALL
Steps To Reproduce:

Reproduce:

db.files.drop();
 
db.files.insert({ _id:"foo.txt", attr: [ { type: "text" },   { size: 64 } ] } )
db.files.insert({ _id:"bar.txt", attr: [ { type: "text" },   { size: 128 }, { created: ISODate("2013-01-01T18:13:42.689Z") } ] } )
db.files.insert({ _id:"foobar",  attr: [ { type: "binary" }, { size: 256 }, { created: ISODate("2013-04-01T18:13:42.689Z") } ] } )
 
db.files.ensureIndex({attr: 1})
 
db.files.find( { $or: [ { attr: { $gte: { created: ISODate("2013-02-01T00:00:01.689Z") } } },  
                        { attr: { $gt: { size:128 }, $lte: { size: 16384 } } }
                       ] } ).explain()

Participants:

 Description   

Problem:
Seeing the index bounds for a single element of a $or reference items in another element of the $or.

Example:
See the second element of the query plan, where bounds are "size" and "created" (lines 46 and 49 below)

{
	"clauses" : [
		{
			"cursor" : "BtreeCursor attr_1",
			"isMultiKey" : true,
			"n" : 1,
			"nscannedObjects" : 1,
			"nscanned" : 1,
			"nscannedObjectsAllPlans" : 1,
			"nscannedAllPlans" : 1,
			"scanAndOrder" : false,
			"indexOnly" : false,
			"nYields" : 0,
			"nChunkSkips" : 0,
			"millis" : 0,
			"indexBounds" : {
				"attr" : [
					[
						{
							"created" : ISODate("2013-02-01T00:00:01.689Z")
						},
						{
							"$maxElement" : 1
						}
					]
				]
			}
		},
		{
			"cursor" : "BtreeCursor attr_1",
			"isMultiKey" : true,
			"n" : 2,
			"nscannedObjects" : 5,
			"nscanned" : 5,
			"nscannedObjectsAllPlans" : 5,
			"nscannedAllPlans" : 5,
			"scanAndOrder" : false,
			"indexOnly" : false,
			"nYields" : 0,
			"nChunkSkips" : 0,
			"millis" : 0,
			"indexBounds" : {
				"attr" : [
					[
						{
							"size" : 128
						},
						{
							"created" : ISODate("2013-02-01T00:00:01.689Z")
						}
					]
				]
			}
		}
	],
	"n" : 3,
	"nscannedObjects" : 6,
	"nscanned" : 6,
	"nscannedObjectsAllPlans" : 6,
	"nscannedAllPlans" : 6,
	"millis" : 0,
	"server" : "vero:27017"
}



 Comments   
Comment by David Storch [ 08/Jan/14 ]

This optimization is something that we do not intend to do in the new query system; resolving as Works as Designed.

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