[SERVER-73697] Do not split out match expression on meta field when it's not renameable Created: 07/Feb/23  Updated: 29/Oct/23  Resolved: 10/Feb/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.4, 6.3.0-rc0, 6.2.0-rc6
Fix Version/s: 7.0.0-rc0, 6.0.5, 6.3.0-rc1

Type: Bug Priority: Critical - P2
Reporter: Yoon Soo Kim Assignee: Yoon Soo Kim
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by SERVER-73535 Add more support for $jsonSchema in '... Closed
Related
related to SERVER-55492 Implement renames for kOther and kArr... Backlog
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.3, v6.0
Steps To Reproduce:

// $size issue repro
db.createCollection("ts", {timeseries: {timeField: "time", metaField: "tag"}});
db.ts.insert({time: ISODate(), tag: {a: [1, 2]}, f: 1});
db.ts.insert({time: ISODate(), tag: {a: [1]}, f: 2});
 
db.non_ts.insert({time: ISODate(), tag: {a: [1, 2]}, f: 1});
db.non_ts.insert({time: ISODate(), tag: {a: [1]}, f: 2});
 
db.ts.find({"tag.a": {$size: 1}});
// no results
db.ts.explain().find({"tag.a": {$size: 1}});
// The wrong filter is pushed down to the COLLSCAN. "tag.a" should have been renamed as "meta.a"
...
					"winningPlan" : {
						"stage" : "COLLSCAN",
						"filter" : {
							"tag.a" : {
								"$size" : 1
							}
						},
						"direction" : "forward"
					},
...
db.ts.find({"tag.a": {$size: 2}});
// no results
db.ts.explain().find({"tag.a": {$size: 2}});
// Same as above
...
					"winningPlan" : {
						"stage" : "COLLSCAN",
						"filter" : {
							"tag.a" : {
								"$size" : 2
							}
						},
						"direction" : "forward"
					},
...
db.non_ts.find({"tag.a": {$size: 1}});
// { "_id" : ObjectId("63e1b2df7904f99bc29bd5d3"), "time" : ISODate("2023-02-07T02:09:35.334Z"),
// "tag" : { "a" : [ 1 ] }, "f" : 2 }
db.non_ts.find({"tag.a": {$size: 2}});
// { "_id" : ObjectId("63e1b2de7904f99bc29bd5d1"), "time" : ISODate("2023-02-07T02:09:34.767Z"),
// "tag" : { "a" : [ 1, 2 ] }, "f" : 1 }
 
// $elemMatch issue repro
> db.ts.find({"tag.a": {$elemMatch: {$gt: 1}}});
// no results
> db.ts.find({"tag.a": {$gt: 1}});
{ "time" : ISODate("2023-02-07T02:06:34.469Z"), "tag" : { "a" : [ 1, 2 ] }, "f" : 1, "_id" : ObjectId("63e1b22a7904f99bc29bd5cd") }
> db.non_ts.find({"tag.a": {$gt: 1}});
{ "_id" : ObjectId("63e1c6edca1cee615824301b"), "time" : ISODate("2023-02-07T03:35:09.023Z"), "tag" : { "a" : [ 1, 2 ] }, "f" : 1 }
> db.non_ts.find({"tag.a": {$elemMatch: {$gt: 1}}});
{ "_id" : ObjectId("63e1b2de7904f99bc29bd5d1"), "time" : ISODate("2023-02-07T02:09:34.767Z"), "tag" : { "a" : [ 1, 2 ] }, "f" : 1 }

Sprint: QE 2023-02-20
Participants:

 Description   

The array match expressions such as $elemMatch and $size are not properly pushed down to the timeseries system.buckets collection.

I strongly suspect that this is because $elemMatch & $size are array match expressions and splitMatchExpressionBy() function supports only renameable match expressions but the array match expressions are not categorized as "renameable" by hasOnlyRenameableMatchExpressionChildren(). I don't know why splitMatchExpressionBy() supports only renameable match expressions.

Note that $jsonSchema-related internal match expressions are also not categorized as "renameable" and I expect that the same issues exists for $jsonSchema expression(s).

Some of $jsonSchema-related internal match expressions will be supported by SERVER-73535.



 Comments   
Comment by Githook User [ 21/Feb/23 ]

Author:

{'name': 'Yoonsoo Kim', 'email': 'yoonsoo.kim@mongodb.com', 'username': 'yun-soo'}

Message: SERVER-73697 Do not split out match expression on meta field when it's not renameable

(cherry picked from commit 02eaef3b79524560ff4d651255e1ae3f280f5bcd)
Branch: v6.3
https://github.com/mongodb/mongo/commit/bdacd70b1ce3f721f4157231d63d187a3eb33dfb

Comment by Githook User [ 21/Feb/23 ]

Author:

{'name': 'Yoonsoo Kim', 'email': 'yoonsoo.kim@mongodb.com', 'username': 'yun-soo'}

Message: SERVER-73697 Do not split out match expression on meta field when it's not renameable

(cherry picked from commit 02eaef3b79524560ff4d651255e1ae3f280f5bcd)
Branch: v6.0
https://github.com/mongodb/mongo/commit/72bf5680cbba28b5f2c909459093fba6c9f348d4

Comment by Githook User [ 10/Feb/23 ]

Author:

{'name': 'Yoonsoo Kim', 'email': 'yoonsoo.kim@mongodb.com', 'username': 'yun-soo'}

Message: SERVER-73697 Do not split out match expression on meta field when it's not renameable
Branch: master
https://github.com/mongodb/mongo/commit/02eaef3b79524560ff4d651255e1ae3f280f5bcd

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