-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Update MongoDB $or queries to avoid SERVER-13732 bug #3476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update MongoDB $or queries to avoid SERVER-13732 bug #3476
Conversation
MongoDB has an unfixed bug in all supported versions 2.6-3.4 which results in suboptimal index usage for `$or` queries when the query has implicit `$and`s at the query root. When adding `_rperm` to `$or` queries, Parse accidentally creates queries which hit this bug. The fix in this commit applies the suggested workaround of putting the `_rperm` property inside all `$or` subdocuments, moving it from the top level and leaving `$or` as the only top-level operator. MongoDB Bug Link: https://jira.mongodb.org/browse/SERVER-13732
return qobj; | ||
}); | ||
} else { | ||
newQuery._rperm = { "$in" : [null, "*", ...acl]}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spacing between the closing } and the ] is odd here and should have a space as well as the above '$in' in the if block.
@@ -18,7 +18,14 @@ function addWriteACL(query, acl) { | |||
function addReadACL(query, acl) { | |||
const newQuery = _.cloneDeep(query); | |||
//Can't be any existing '_rperm' query, we don't allow client queries on that, no need to $and | |||
newQuery._rperm = { "$in" : [null, "*", ...acl]}; | |||
if (newQuery.hasOwnProperty('$or')) { | |||
newQuery.$or = newQuery.$or.map(function(qobj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to add a comment here that provides a link to the MongoDB JIRA ticket and a note that we are intentionally distributing the _rperm predicate.
Nice catch and workaround! Thanks for the contribution. |
In a prior commit, improvements were made to the addition of `_rperm` in the case of `$or` queries, to avoid MongoDB bug SERVER-13732. As the vast majority of $or queries previously hit this bug due to the presence of `_rperm` on most Parse queries), the present solution avoids the bug and improves query performance in most cases. However, it's still possible for clients to supply their own queries which hit that bug, such as those with `_created_at` or `_updated_at` filters, or their own properties from their data model. This commit makes the logic currently present for `_rperm` available to all top level filters that exist alongside an $or query, meaning SERVER-13732 should be avoided in all cases where keys at the top and inner levels do not have name clashes. - parse-community#3476 - https://jira.mongodb.org/browse/SERVER-13732
In a prior commit, improvements were made to the addition of `_rperm` in the case of `$or` queries, to avoid MongoDB bug SERVER-13732. As the vast majority of $or queries previously hit this bug due to the presence of `_rperm` on most Parse queries), the present solution avoids the bug and improves query performance in most cases. However, it's still possible for clients to supply their own queries which hit that bug, such as those with `_created_at` or `_updated_at` filters, or their own properties from their data model. This commit makes the logic currently present for `_rperm` available to all top level filters that exist alongside an $or query, meaning SERVER-13732 should be avoided in all cases where keys at the top and inner levels do not have name clashes. - #3476 - https://jira.mongodb.org/browse/SERVER-13732
MongoDB has an unfixed bug in all supported versions 2.6-3.4 which
results in suboptimal index usage for
$or
queries when the query hasimplicit
$and
s at the query root.When adding
_rperm
to$or
queries, Parse accidentally createsqueries which hit this bug.
The fix in this commit applies the suggested workaround of putting the
_rperm
property inside all$or
subdocuments, moving it from the toplevel and leaving
$or
as the only top-level operator.MongoDB Bug Link: https://jira.mongodb.org/browse/SERVER-13732