[SERVER-8948] Count() can be wrong in sharded collections Created: 12/Mar/13  Updated: 09/Jul/16  Resolved: 07/Mar/14

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

Type: Bug Priority: Major - P3
Reporter: Antoine Guiral Assignee: Unassigned
Resolution: Duplicate Votes: 1
Labels: commands, count
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File orphans_not_skipped_on_count.js    
Issue Links:
Duplicate
duplicates SERVER-5931 Secondary reads in sharded clusters n... Closed
Related
related to SERVER-3645 Sharded collection counts (on primary... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

The count command does not ignore orphans like find/queries. This is true whether the query is on the primary or secondaries (which is known to be a different issue).

For a query like this the count can come back larger if there are orphaned docs, but find will filter them out:

// more than one shard has the document with x:10, some of which are orphans from migrations
> coll.count({x:10})
2
> coll.find({x:10}).toArray()
[{_id:10, x:10}]
> coll.find({x:10}).explain() // some of the explain is removed for brevity
{
	"clusteredType" : "ParallelSort",
	"shards" : { ... },
	"n" : 1,
	"nChunkSkips" : 1,
	"numQueries" : 2,
	"numShards" : 2,
	"millis" : 2
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 05/Feb/14 ]

Here is a test which passes now because the counts are off. This tests current behavior in the server

Comment by Adinoyi Omuya [ 11/Apr/13 ]

It could also be SERVER-4123. Could you post the result of calling explain() on the find query?

Comment by Adinoyi Omuya [ 11/Apr/13 ]

What shard key are you using? _id?

Comment by Antoine Guiral [ 12/Mar/13 ]

I don't know but SERVER-3645 is about non filtered count, and this count is filtered.
Btw, Thanks for the formatting

Comment by Tad Marshall [ 12/Mar/13 ]

SERVER-3645?

Comment by Antoine Guiral [ 12/Mar/13 ]

Btw, the result shown with php (21031) is the same I get with the shell.

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