[SERVER-79585] A valid $match query fails on time-series collection Created: 01/Aug/23  Updated: 29/Oct/23  Resolved: 26/Sep/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 7.1.0-rc0, 7.0.1, 6.0.9
Fix Version/s: 7.2.0-rc0, 7.0.3, 6.0.12

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

Issue Links:
Backports
Related
related to SERVER-79692 Duplicated predicates pushed down int... Open
Assigned Teams:
Query Integration
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0, v6.0
Steps To Reproduce:

> db.createCollection("ts", { timeseries: { timeField: "time", metaField: "meta", granularity: "minutes" }})
> db.ts.insertMany([{time: new Date(), meta: {key: 2, val: 0}, val: 42, key: 1},{time: new Date(), meta: {key: 1, val: 0}, val: 43, key: 1}])
 
single predicate with non-consts
> db.ts.aggregate({$match: {$expr: {$lt: ["$meta.val","$val"]}}})
correctly returns both docs from the collection
 
two const predicates, combined with $and,
> db.ts.aggregate({$match: {$expr: {$and: [{$lt: ["$meta.val",42]}, {$eq: ["$meta.key",1]}]}}})
correctly returns one matching doc from the collection
 
two predicates, one of them non-const
> db.ts.aggregate({$match: {$expr: {$and: [{$lt: ["$meta.val","$val"]}, {$eq: ["$meta.key",1]}]}}})
raises error:
"errmsg" : "Failed to optimize pipeline :: caused by :: createComparisonPredicate() does not handle metadata predicates: 0xAAAB14AD4640",
"code" : 6707200
 
two non-const predicates, split across two $match stages
> db.ts.aggregate([{$match: {$expr: {$lt: ["$meta.val","$val"]}}}, {$match: {$expr: {$eq: ["$meta.key","$key"]}}}])
correctly returns one matching doc from the collection

Participants:

 Description   

The same query executes fine on a non-time-series collection with the same inserted documents. The error is specific to the predicates re-write we do for time-series.



 Comments   
Comment by Githook User [ 28/Sep/23 ]

Author:

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

Message: SERVER-79585 Prevent rewriting $expr predicates with $and children that cannot be MatchExpressions for time-series collections

(cherry picked from commit c20ad7bd3911aab538f70361150d903823978951)
Branch: v6.0
https://github.com/mongodb/mongo/commit/8bd9ce3e94bb0d5dda1bd1b4b6bff334d5b7ca94

Comment by Githook User [ 28/Sep/23 ]

Author:

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

Message: SERVER-79585 Prevent rewriting $expr predicates with $and children that cannot be MatchExpressions for time-series collections
Branch: v7.0
https://github.com/mongodb/mongo/commit/c20ad7bd3911aab538f70361150d903823978951

Comment by Githook User [ 22/Sep/23 ]

Author:

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

Message: SERVER-79585 Prevent rewriting $expr predicates with $and children that cannot be MatchExpressions for time-series collections
Branch: master
https://github.com/mongodb/mongo/commit/67c53243d454f121e9af9facea8d6fac08af7d74

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