Hello folks!
I am currently running Parse Server 3.6.0 and mongodb 3.6.9. Last week I tried to update Parse server to the latest version (4.2.0) and it was a horrible experience. Some of the queries against a large table (+5m records) started taking too long.
I haven’t really found the root cause of the problem, however, one of the things I noticed differently is that in the latest version, simple queries done with a session token seem to be “converted” to an $or query at the mongodb level. For example:
For a single query, this is how it get translated to the mongodb query in version 3.6
"command" : {
"find" : "lineItem",
"filter" : {
"$and" : [
{
"_p_user" : "_User$userId"
},
{
"_p_user" : "_User$userId",
"_p_receipt" : "receipt$receiptId",
"status" : {
"$in" : [
"status1",
"status2",
"status3",
"status4"
]
}
}
],
"_rperm" : {
"$in" : [
role1,
"*",
"*",
"role2",
"role3",
"userId"
]
}
},
"sort" : {
},
"projection" : {
},
"limit" : 100,
"returnKey" : false,
"showRecordId" : false,
"$db" : "test"
}
And this is how it gets translated to the mongodb query in version 4.2.0
"command" : {
"find" : "lineItem",
"filter" : {
"$or" : [
{
"$and" : [
{
"_p_user" : "_User$userId"
},
{
"_p_user" : "_User$userId",
"_p_receipt" : "receipt$receiptId",
"status" : {
"$in" : [
"status1",
"status2",
"status3",
"status4"
]
}
}
]
},
{
"$and" : [
{
"_p_user" : {
"$all" : [
{
"__type" : "Pointer",
"className" : "_User",
"objectId" : "userid"
}
]
}
},
{
"_p_user" : "_User$userId",
"_p_receipt" : "receipt$receiptId",
"status" : {
"$in" : [
"status1",
"status2",
"status3",
"status4"
]
}
}
]
}
],
"_rperm" : {
"$in" : [
role1,
"*",
"*",
"role2",
"role3",
"userId"
]
}
},
"sort" : {
},
"projection" : {
},
"limit" : 100,
"returnKey" : false,
"showRecordId" : false,
"lsid" : {
"id" : UUID("15fe77ed-45ad-4625-b486-ba008b3aebb2")
},
"$db" : "test"
},
This leads me to the following questions:
-
Why does a simple Parse Query with a couple of
equalTo
and acontainedIn
gets translated into a complicated $or query in the latest version? I tried it in versions 4.0.0 and above and I get the same behavior. -
Why does the query in the latest version adds a clause to match for the user in the following way?
“_p_user” : {
“$all” : [
{
“__type” : “Pointer”,
“className” : “_User”,
“objectId” : “userid”
}
]
}I may be wrong, but it seems to me it is useless to search this way since pointers are not stored this way in the mongodb tables.
-
Does this means that on average, the queries in the old version of parse server are more performant than in the new version because of the increased complexity in the query?
I am aware that there are few corner cases in which $or queries can mess up performance in some versions of mongodb, see https://jira.mongodb.org/browse/SERVER-36393.
I hope someone can help me clarify my doubts above.
Best regards,
- Musa