Update MongoDB $or queries to avoid SERVER-13732 bug#3476
Merged
TylerBrock merged 1 commit intoparse-community:masterfrom Feb 4, 2017
Merged
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
TylerBrock
reviewed
Feb 4, 2017
| return qobj; | ||
| }); | ||
| } else { | ||
| newQuery._rperm = { "$in" : [null, "*", ...acl]}; |
Contributor
There was a problem hiding this comment.
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.
TylerBrock
reviewed
Feb 4, 2017
| //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) { |
Contributor
There was a problem hiding this comment.
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.
Contributor
|
Nice catch and workaround! Thanks for the contribution. |
NotBobTheBuilder
added a commit
to NotBobTheBuilder/parse-server
that referenced
this pull request
Feb 24, 2017
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
flovilmart
pushed a commit
that referenced
this pull request
Feb 26, 2017
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MongoDB has an unfixed bug in all supported versions 2.6-3.4 which
results in suboptimal index usage for
$orqueries when the query hasimplicit
$ands at the query root.When adding
_rpermto$orqueries, Parse accidentally createsqueries which hit this bug.
The fix in this commit applies the suggested workaround of putting the
_rpermproperty inside all$orsubdocuments, moving it from the toplevel and leaving
$oras the only top-level operator.MongoDB Bug Link: https://jira.mongodb.org/browse/SERVER-13732