[SERVER-11747] Inconsistent behavior of "distinct" with index Created: 17/Nov/13  Updated: 10/Dec/14  Resolved: 18/Nov/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PYTHON-598 GridFS.list() sometimes includes None Closed
Operating System: ALL
Participants:

 Description   

This is surprising:

> db.collection.insert({a:1})
> db.collection.insert({})
> db.collection.distinct('a')
[ 1 ]
> db.collection.createIndex({a:1})
> db.collection.distinct('a')
[ null, 1 ]

A document without the 'a' field has no effect on the 'distinct' output when there's no index, but it contributes a 'null' to the output when there is an index.



 Comments   
Comment by A. Jesse Jiryu Davis [ 17/Nov/13 ]

I'm seeing it on 2.4.8:

$ cat test.js
printjson(db.serverBuildInfo());
db.collection.drop();
db.collection.insert({a:1});
db.collection.insert({});
printjson(db.collection.distinct('a'));
db.collection.createIndex({a:1});
printjson(db.collection.distinct('a'));
 
 
$ mongo test.js
MongoDB shell version: 2.4.8
connecting to: test
{
	"version" : "2.4.8",
	"gitVersion" : "a350fc38922fbda2cec8d5dd842237b904eafc14",
	"sysInfo" : "Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49",
	"loaderFlags" : "-fPIC -pthread -rdynamic -m64",
	"compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -O3 -m64",
	"allocator" : "system",
	"versionArray" : [
		2,
		4,
		8,
		0
	],
	"javascriptEngine" : "V8",
	"bits" : 64,
	"debug" : false,
	"maxBsonObjectSize" : 16777216,
	"ok" : 1
}
[ 1 ]
[ null, 1 ]

However, on the 11/15 nightly it's fixed, so I guess we can close this:

$ mongo test.js
MongoDB shell version: 2.5.4-pre-
connecting to: test
{
	"version" : "2.5.4-pre-",
	"gitVersion" : "58b3bbcc1c366185cfbf9b8551a4c7150f6553d9",
	"OpenSSLVersion" : "",
	"sysInfo" : "Darwin mci-osx108-8.build.10gen.cc 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49",
	"loaderFlags" : "-fPIC -pthread -Wl,-bind_at_load -mmacosx-version-min=10.6",
	"compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -pipe -O3 -Wno-unused-function -Wno-deprecated-declarations -mmacosx-version-min=10.6",
	"allocator" : "system",
	"versionArray" : [
		2,
		5,
		4,
		-100
	],
	"javascriptEngine" : "V8",
	"bits" : 64,
	"debug" : false,
	"maxBsonObjectSize" : 16777216,
	"ok" : 1
}
[ 1 ]
[ 1 ]

Comment by Daniel Pasette (Inactive) [ 17/Nov/13 ]

Which version are you using? I'm not seeing this behavior on 2.4 or 2.5 given the test script..

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