Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
Fully Compatible
-
v4.4, v4.2
-
Query 2020-06-29
-
(copied to CRM)
Description
Implementation in SERVER-9507 only works when specific format for _id in $group is used:
// works
|
db.newTest.explain(1).aggregate([
|
{$sort:{valueDate:1}},
|
{$group:{_id: "$valueDate", first: {$first: "$farmId"}}}
|
]).stages[0]["$cursor"]["executionStats"]
|
{
|
"executionSuccess" : true,
|
"nReturned" : 2,
|
"executionTimeMillis" : 0,
|
"totalKeysExamined" : 2,
|
"totalDocsExamined" : 2,
|
... }
|
// doesn't work
|
db.newTest.explain(1).aggregate([
|
{$sort:{valueDate:1}},
|
{$group:{_id: {v:"$valueDate"}, first: {$first: "$farmId"}}}
|
]).stages[0]["$cursor"]["executionStats"]
|
{
|
"executionSuccess" : true,
|
"nReturned" : 5,
|
"executionTimeMillis" : 0,
|
"totalKeysExamined" : 10,
|
"totalDocsExamined" : 5,
|
... }
|
|
Attachments
Issue Links
- is related to
-
SERVER-53626 Minimize index scanning when retrieving distinct values grouped by more than one field
-
- Backlog
-
-
SERVER-9507 Optimize $sort+$group+$first pipeline to avoid full index scan
-
- Closed
-