[SERVER-82447] $project incorrectly pushed down on timeseries when $project uses $getField on a measurement field Created: 25/Oct/23  Updated: 30/Nov/23  Resolved: 15/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc0, 7.2.0-rc2, 7.0.5, 6.0.13, 5.0.24

Type: Bug Priority: Major - P3
Reporter: Gil Alon Assignee: Gil Alon
Resolution: Fixed Votes: 0
Labels: greenerbuild
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Assigned Teams:
Query Integration
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.2
Steps To Reproduce:

assert.commandWorked(db.createCollection(coll.getName(), {timeseries: {timeField: 'time', metaField: 'tag'}})); 
 
assert.commandWorked(coll.insert({ _id:1, time: new Date("2022-12-25T00:25:56.333Z"), tag:2, obj:3})); 
 
// run aggregation
coll.aggregate([ {$project: {"array": {$map: {input: ["$tag"], in: {$getField: "obj"}}}}}]) 
 
// aggregation returns [ { "_id" : 1, "array" : [ null ] } ] 
 
// but the aggregation should return[[ { "_id" : 1, "array" : [ 3 ] } ]] 

Sprint: QI 2023-11-13, QI 2023-11-27
Participants:
Linked BF Score: 0

 Description   

$project, $addFields and $set that reference the metaField are pushed before the $_internalUnpackBucket stage. However, we are not accounting for the case that these stages could have expressions with subexpressions that are dependent on measurement fields. Below is a minimal repro from a fuzzer BF.



 Comments   
Comment by Githook User [ 30/Nov/23 ]

Author:

{'name': 'Gil Alon', 'email': 'gil.alon@mongodb.com', 'username': 'galon1'}

Message: SERVER-82447 Restrict project and addFields pushdown before unpack if an expression depends on the whole document

(cherry picked from commit 16e742346bf0d4a58419920663695128c5add72a)

GitOrigin-RevId: 583601f9a0684c97a52ed8acf7b1b925126f4bc5
Branch: v5.0
https://github.com/mongodb/mongo/commit/116bd5ff632eca17d80d563fda8fc63e928d6ac4

Comment by Githook User [ 29/Nov/23 ]

Author:

{'name': 'Gil Alon', 'email': 'gil.alon@mongodb.com', 'username': 'galon1'}

Message: SERVER-82447 Restrict project and addFields pushdown before unpack if an expression depends on the whole document
Branch: v6.0
https://github.com/mongodb/mongo/commit/16e742346bf0d4a58419920663695128c5add72a

Comment by Githook User [ 28/Nov/23 ]

Author:

{'name': 'Gil Alon', 'email': 'gil.alon@mongodb.com', 'username': 'galon1'}

Message: SERVER-82447 Restrict project and addFields pushdown before unpack if an expression depends on the whole document
Branch: v7.0
https://github.com/mongodb/mongo/commit/9810bf55855b2c1ae725fba91dc0775f6015be6b

Comment by Githook User [ 17/Nov/23 ]

Author:

{'name': 'Gil Alon', 'email': 'gil.alon@mongodb.com', 'username': 'galon1'}

Message: SERVER-82447 Restrict project and addFields pushdown before unpack if an expression depends on the whole document

(cherry picked from commit 0d000e66178ce2e1c4a25da246d662e4939ac179)
Branch: v7.2
https://github.com/mongodb/mongo/commit/a9d61291ebc811bda860814a6bd839549c087193

Comment by Githook User [ 15/Nov/23 ]

Author:

{'name': 'Gil Alon', 'email': 'gil.alon@mongodb.com', 'username': 'galon1'}

Message: SERVER-82447 Restrict project and addFields pushdown before unpack if an expression depends on the whole document
Branch: master
https://github.com/mongodb/mongo/commit/0d000e66178ce2e1c4a25da246d662e4939ac179

Generated at Thu Feb 08 06:49:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.