[SERVER-17069] Sparse .hint() Functionality is Different in MMAPv1 vs. WiredTiger Created: 27/Jan/15  Updated: 27/Jan/15  Resolved: 27/Jan/15

Status: Closed
Project: Core Server
Component/s: Index Maintenance, WiredTiger
Affects Version/s: 3.0.0-rc6
Fix Version/s: None

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

Attachments: File mlaunch_data_failed_sparse_hint.tar.gz    
Operating System: ALL
Steps To Reproduce:
  • Note: I did this with mlaunch v 1.1.7
  • First, download the attached tarball and go to the directory you saved it to.

    $ tar xvf mlaunch_data_failed_sparse_hint.tar.gz
    $ mlaunch start
    $ mongo
    mongos> db.foo.explain("executionStats").find( { a : 12, b : 25, c : 8 } ).hint( { e : 1 } )

  • Expected result:
    • The query is executed, but misses a document that lacks an "e" field (and therefore an index entry on { e : 1 }
  • Actual result:
    • An error is thrown:

      2015-01-27T10:35:27.605-0500 E QUERY    Error: explain failed: {
      	"ok" : 0,
      	"errmsg" : "Explain command on shard cross-mb-air.local:27018 failed, caused by: { ok: 0.0, errmsg: \"error processing query: ns=test.foo limit=0 skip=0\nTree: $and\n    a == 12.0\n    b == 25.0\n    c == 8.0\nSort: {}\nProj: {}\n planner returned error: bad hint\", code: 2, $gleStats: { lastOpTime: Timestamp 0|0, electionId: ObjectId('54c7aef96a0ab41446ee1188') } }",
      	"code" : 2
      }
          at Error (<anonymous>)
          at Function.throwOrReturn (src/mongo/shell/explainable.js:34:19)
          at constructor.finish (src/mongo/shell/explain_query.js:188:36)
          at constructor.shellPrint (src/mongo/shell/explain_query.js:228:31)
          at shellPrintHelper (src/mongo/shell/utils.js:396:18)
          at (shell2):1:19 at src/mongo/shell/explainable.js:34

Participants:

 Description   

WiredTiger throws an error when I hint() on a sparse index. This is a problem because it should conform to the behavior of MMAPv1, which is to use the index but skip any documents that lack an entry on that index.



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

After dicussing with cross@mongodb.com, looks like this is working as designed. The replica set in question has the following indices:

shard01:PRIMARY> db.foo.getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_",
		"ns" : "test.foo"
	},
	{
		"v" : 1,
		"key" : {
			"a" : 1
		},
		"name" : "a_1",
		"ns" : "test.foo"
	},
	{
		"v" : 1,
		"key" : {
			"b" : 1
		},
		"name" : "b_1",
		"ns" : "test.foo"
	},
	{
		"v" : 1,
		"key" : {
			"c" : 1
		},
		"name" : "c_1",
		"ns" : "test.foo"
	},
	{
		"v" : 1,
		"key" : {
			"d" : 1
		},
		"name" : "d_1",
		"ns" : "test.foo"
	},
	{
		"v" : 1,
		"key" : {
			"e" : 1,
			"sparse" : true
		},
		"name" : "e_1_sparse_true",
		"ns" : "test.foo"
	}
]

Note that there is no index with the key pattern {e: 1}. Instead, there is an index with key pattern {e: 1, sparse: 1}. Therefore, hinting on {e: 1} was indeed a bad hint! Looks like this was caused by a subtle typo:

t.ensureIndex({e: 1, sparse: true}); // typo!
t.ensureIndex({e: 1}, {sparse: true}); // correct

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