[SERVER-67780] Incorrect $group rewrite for timeseries collection when the accumulator uses meta field Created: 05/Jul/22  Updated: 29/Oct/23  Resolved: 31/Aug/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.9, 6.0.0-rc13, 6.1.0-rc0
Fix Version/s: 6.2.0-rc0, 5.0.16, 6.0.6

Type: Bug Priority: Critical - P2
Reporter: Arun Banala Assignee: Svilen Mihaylov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Problem/Incident
causes SERVER-75243 Disable broken timeseries_lastpoint_t... Closed
Related
related to SERVER-73822 Time-series $group rewrite ignores ce... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.0, v5.0
Steps To Reproduce:

> db.createCollection("ts", {timeseries: {timeField: "time", metaField: "metadata"}})
{ "ok" : 1 }
> db.ts.insert({metadata: {groupKey: 1, num: 4}, time: new Date()})
WriteResult({ "nInserted" : 1 })
> db.ts.insert({metadata: {groupKey: 2, num: 5}, time: new Date()})
WriteResult({ "nInserted" : 1 })
> db.ts.insert({metadata: {groupKey: 2, num: 4}, time: new Date()})
WriteResult({ "nInserted" : 1 })
> db.ts.aggregate([{$group: {_id: "$metadata.groupKey", accum: {$max: "$metadata.num"}}}])
{ "_id" : 1, "accum" : null }
{ "_id" : 2, "accum" : null }
> db.ts.aggregate([{$_internalInhibitOptimization: {}} , {$group: {_id: "$metadata.groupKey", accum: {$max: "$metadata.num"}}}])
{ "_id" : 2, "accum" : 5 }
{ "_id" : 1, "accum" : 4 }

Sprint: QO 2022-08-08, QO 2022-08-22, QO 2022-09-05
Participants:
Linked BF Score: 157

 Description   

We currently have an optimisation to rewrite a $group with the group key on meta field, and the accumulator(s) using either $min or $max on measurements. This logic is incorrectly assuming that all non-timeField paths can be treated as measurements. We rewrite a path "$x" as either "$control.min.x" or "$control.max.x". This rewrite would be incorrect when the accumulator is using a metaField. In this case, the rewrite logic should be a path "$metaField.x" gets written into "$meta.x".



 Comments   
Comment by Githook User [ 17/Mar/23 ]

Author:

{'name': 'Svilen Mihaylov', 'email': 'svilen.mihaylov@mongodb.com', 'username': 'svilen-mihaylov'}

Message: SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field
Branch: v5.0
https://github.com/mongodb/mongo/commit/5f2b3207b0801fe59988f9d8b3b19ae8734ff9ba

Comment by Githook User [ 15/Mar/23 ]

Author:

{'name': 'Svilen Mihaylov', 'email': 'svilen.mihaylov@mongodb.com', 'username': 'svilen-mihaylov'}

Message: SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field
Branch: v6.0
https://github.com/mongodb/mongo/commit/d6803bde9895008663a158eb8d0d0d59623b876f

Comment by Githook User [ 30/Aug/22 ]

Author:

{'name': 'Svilen Mihaylov', 'email': 'svilen.mihaylov@mongodb.com', 'username': 'smihaylov-mongodb'}

Message: SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field
Branch: master
https://github.com/mongodb/mongo/commit/3f7efc7fbe74cbe5155b6a8229392b0261d59b28

Comment by Githook User [ 30/Aug/22 ]

Author:

{'name': 'auto-revert-processor', 'email': 'dev-prod-dag@mongodb.com'}

Message: Revert "SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field"

This reverts commit ccb0d93033900be8cead29d3cdd414d8a85f2b03.
Branch: master
https://github.com/mongodb/mongo/commit/bc38590591e0c5509f73482c2431ca28e8f882e8

Comment by Githook User [ 29/Aug/22 ]

Author:

{'name': 'Svilen Mihaylov', 'email': 'svilen.mihaylov@mongodb.com', 'username': 'smihaylov-mongodb'}

Message: SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field
Branch: master
https://github.com/mongodb/mongo/commit/ccb0d93033900be8cead29d3cdd414d8a85f2b03

Comment by Githook User [ 26/Aug/22 ]

Author:

{'name': 'liubov.molchanova', 'email': 'liubov.molchanova@mongodb.com', 'username': 'liubov-molchanova'}

Message: Revert "SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field"

This reverts commit 3ae43985776cf6de9cff18775e4484b9c6904e3e.
Branch: master
https://github.com/mongodb/mongo/commit/70fc032f8e809a74c59934ec70a29b1df3d1e8cc

Comment by Githook User [ 25/Aug/22 ]

Author:

{'name': 'Svilen Mihaylov', 'email': 'svilen.mihaylov@mongodb.com', 'username': 'smihaylov-mongodb'}

Message: SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field
Branch: master
https://github.com/mongodb/mongo/commit/3ae43985776cf6de9cff18775e4484b9c6904e3e

Comment by Rushan Chen [ 11/Jul/22 ]

This is currently in the QO queue joseph.kanaan@mongodb.com 

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