[SERVER-7595] indexOnly is never true when isMultiKey is true Created: 08/Nov/12  Updated: 10/Aug/14  Resolved: 08/Nov/12

Status: Closed
Project: Core Server
Component/s: Diagnostics, Performance
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Harold Cooper Assignee: Aaron Staple
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3173 Planner should use path-level multike... Closed
Related
Operating System: ALL
Participants:

 Description   

I've noticed that queries on a multiKey index are never indexOnly. Is that true? Seems odd.

For example if you set up a table as follows:

db.test.drop();
db.test.ensureIndex({single: 1, multi: 1});
db.test.insert({single: 'a', multi: [1,2,3]});
db.test.insert({single: 'b', multi: [2,3,4]});
db.test.insert({single: 'a', multi: [3,4,5]});
db.test.insert({single: 'b', multi: [4,5,6]});

Then querying on 'single' with a readset of just 'single' still gives indexOnly: false, even though the required data should certainly be available in the index:

> db.test.find({single: 'a'}, {single: 1, _id: 0}).explain()
{
	"cursor" : "BtreeCursor single_1_multi_1",
	"isMultiKey" : true,
	"n" : 2,
	"nscannedObjects" : 6,
	"nscanned" : 6,
	"nscannedObjectsAllPlans" : 6,
	"nscannedAllPlans" : 6,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"single" : [
			[
				"a",
				"a"
			]
		],
		"multi" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		]
	}
}

I don't know if this is an actual performance issue or just a problem with explain().

(Note that this was originally a post in the Google Group, where Max Schireson said I should file a bug: https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/QsZFS4nddHo)



 Comments   
Comment by Harold Cooper [ 08/Nov/12 ]

Ah, interesting, thanks for the explanation.

Comment by Aaron Staple [ 08/Nov/12 ]

Hi Harold,

Unfortunately the metadata stored about the index just has a single multikey flag, not a per field flag. It does not distinguish between cases where you've been inserting documents like this:

{single: 'a', multi: [1,2,3]}

or like this:

{single: ['a','b','c'], multi: 1}

As a result, covered index projections are never used for an index that is multikey on any field.

We already have a ticket open for addressing this, SERVER-3173. Feel free to vote / comment there if you'd like.

Your example is one of the cases where you might want to have an index on both

{ single:1 }

and

{ single:1, multi:1 }

. If you have both of these indexes, you may need to explicitly hint the

{ single:1 }

index to get indexOnly:true behavior. Making that happen automatically would be part of SERVER-2109.

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