[SERVER-58563] Optimize plan generation for accumulators to not use Traverse Created: 14/Jul/21  Updated: 06/Dec/22  Resolved: 27/Oct/21

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

Type: Task Priority: Major - P3
Reporter: Eric Cox (Inactive) Assignee: Backlog - Query Execution
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Participants:

 Description   

Accumulators ignore arrays or treat them as whole values. 

A $min doesn't traverse into an array to find the min  of 1,

> db.c.insert({a: 1, x: [1, 99]})
WriteResult({ "nInserted" : 1 })
> db.c.insert({a: 2, x: 10})
WriteResult({ "nInserted" : 1 })
> db.c.insert({a: 1, x: 10})
WriteResult({ "nInserted" : 1 })
> db.c.aggregate([{$group: {_id: "$a", m: {$min: "$x"}}}])
{ "_id" : 1, "m" : 10 }

A $min where a 'false' is compared to an array chooses the min as the array,

db.c.insert({a: 3, x: false})
db.c.insert({a: 3, x: [1,2]})
> db.c.aggregate([{$group: {_id: "$a", m: {$min: "$x"}}}])
{ "_id" : 1, "m" : 10 }
{ "_id" : 3, "m" : [ 1, 2 ] }
{ "_id" : 2, "m" : 10 }

This all means that we don't implicitly traverse arrays so could generate plans that chain together getFields() over the dotted paths instead of plans that use the sbe traverse stage.

 



 Comments   
Comment by Eric Cox (Inactive) [ 27/Oct/21 ]

Will be handled by optimizer.

Generated at Thu Feb 08 05:44:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.