-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Simple Parse query translated to a mongodb "or" query #6708
Comments
I doubt that the query in your post matches the explain output. The query does not contain a condition on |
Hello @mtrezza ! While I am 100% sure about the query and the output, it could be environment related. I reproduced this on my existing dev environment. I will try to create an environment from scratch and reproduce it. |
Can you post the output of Sent with GitHawk |
@mtrezza This is definitively environment related because I was not able to reproduce it from scratch. Give me some time to attempt to reproduce it and I will get back to you. |
@mtrezza I think I got it... I still have some things I need to figure out but I am getting closer to it. For some reason, my class schema has the following CLP attributes:
Not sure how When I attempted to reproduce the issue from scratch, the table that I created did not have those in the CLP, which is why I was not able to reproduce it. |
@mtrezza I realized that
are set when we set the user column CLPs using an older version of the Parse Dashboard (2.0.4). In production we used that. However, in my local environment I had 2.1.0, which behaves a bit differently and doesn't set those, which is why I was not able to reproduce it easily. So as a workaround, I think we can upgrade the dashboard in our production env to 2.1.0 and then reset those CLPs so that they are set without Still, if my understanding is correct, this is a legitimate bug that probably needs to be fixed or perhaps documented properly. |
I also haven't been able to add parse-server/spec/PointerPermissions.spec.js Lines 2170 to 2174 in 292bdb7
Also the docs mention the topic but don't even mention these parameters. I can see that @BufferUnderflower has been working on this, maybe they can shed light on this? |
parse-community/parse-dashboard#1478 Allows to set Pointer Permissions (PP) per-operation in advanced mode. Previously it was only possible to set write/read groups ( readUserFields / writeUserFields in schema). Upon saving the field name will go under corresponding operation into pointerFields array. If all (read or write) operations are checked - saves into corresponding readUserFields/writeUserFields array instead. |
Thanks for the info @BufferUnderflower... @mtrezza you could also use version 2.0.4 of the dashboard and easily set them as well: https://recordit.co/mFsbZb8sjm |
If I understand this correctly, if I check all read operations then However, when I set However, back to the original issue:
I understand that the performance issue you mention is not related to the query you point out here. In other words, the issue at question here is whether the query you found is unnecessarily verbose, thus realistically having a potential performance and data traffic implication. That's a valid point. I assume what you identified as "complex" is the additional
It seems that this actually allows to reference parse-server/src/Controllers/DatabaseController.js Lines 1574 to 1581 in 19086a8
Since Parse Server does not have a field type for "Array of Pointers" (≠ Relations), maybe it was assumed that an array of pointers would be stored in a field of type I would conclude, that the query is that complex intentionally, even if it imposes costs (data traffic, DB node resources) on users who don't use this type of pointer reference, so there is room for improvement. |
@mtrezza Thanks for the feedback!
Well... sometime ago I had an issue with a mongodb $or query that was sending my db instance's CPU utilization to 100% and I was pointed out to https://jira.mongodb.org/browse/SERVER-36393. The moment I deployed my PS application with 4.2.0, CPU util quickly went to 100%. Sadly, I cannot confirm at the moment that the issue in the link is what occurred to me when I deployed the PS application. That said, I think the issue in the link can be avoided with proper maintenance of the table's indexes (e.g. removing unused).
Right, Since I am not able to confirm what I stated above, this is the primary reason why I opened the issue. Under normal conditions the queries work well. However, I speculate that it will add unnecessary stress that will make the system less scalable under heavy loads.
Well, regardless of the What is more interesting is that in the current PS version that I am running (3.6.0), this behavior does not happen and the query gets translated to the following mongodb query, which I consider simpler and more acceptable:
|
I have updated my previous comment.
It seems this issue is only related to pointer permissions. The query is that complex to allow pointer permissions for an array of user pointers, not only a single user pointer. If my previous comment analyzed this correctly, then this is actually a legacy issue that only occurs when a schema contains
That is likely because you don't have |
|
Yes, so apart from the query complexity, is there another issue? |
That was exactly my idea behind the PR, since these fields don't allow any granularity. I tried not to break backwards compatibility with '[read/write]UserFields'. However chances are I've messed smth. Will be able to play with the code next week only. I believe this is the code in question |
Nope, that is the main reason of this issue. I think I had identified a workaround that we could use to do the upgrade (i.e. using the new dashboard and resetting some of the CLPs), but it would be great if this issue gets fixed to avoid any unexpected performance issues in the future. |
more interesting is that in the current PS version that I am running (3.6.0), this behavior does not happen and the query gets translated to the following mongodb query, which I consider simpler and more acceptable:
It is definitely simpler, but it does not consider the columns of type 'Array', where you can hold an array of users who are granted some permission by pointer. |
OK, so there are 2 separate issues:
@mess-lelouch
@BufferUnderflower
Do you have the |
As for the |
@mess-lelouch Would you want to look into a PR for this? |
Ahh I see... I didn't knew this was possible. I always assumed it only worked on a single _User pointer column. That said, not sure if I would encourage using Array of user pointers as CLP over roles, but if this behavior exists in previous versions then I agree it should be preserved. I am interested to see how this works in 3.6.0 so I will give it a try.
@BufferUnderflower Yeah, this is the interesting bit. And this is the main reason I started investigating everything. Had the behavior remained the same in 4.x.x I would not have noticed it. I have been testing for the past day switching between versions on my Parse Server application.
@mtrezza not sure, but I will try to make some time for it. |
@BufferUnderflower I think I found a very related issue (to this one) but I am not sure if it is an issue or if the behavior was replaced by something else. I haven't created a github issue yet since I haven't confirmed if it is a bug or not. https://community.parseplatform.org/t/permission-denied-for-action-find-on-class/365 |
I am closing this as it seems to be resolved by #6747. Feel free to comment if you have any questions and we can re-open this issue. However, there is still the issue of legacy fields not set that was revealed in the process. |
@mtrezza I already submitted a fix for the pointer CLPs issue here parse-community/parse-dashboard#1556. It is already merged, but please let me know if there are any questions or concerns and I will go ahead and address them. |
Amazing! Thanks for the fix. |
Issue Description
I am currently using Parse Server 3.6.0. Last week I attempted to migrate to the latest version of Parse Server and I had to revert back due to performance issues related to specific queries. I think I know how to solve the performance issues, however, I found an interesting behavior during my investigation.
It seems that in the new version of Parse Server, whenever I query a table which has a CLP entry that gives access to the user in a specific column of the table, the resultant mongodb query ends up as an
$or
query. Also, one of the branches in the $or query has a clause to match the user pointer object (which seems useless because pointers are not stored that way in the mongodb table).Steps to reproduce
I am close to a 100% sure (but not 100% sure) that the following steps reproduce the problem.
Create a class
FooClass
with two columns:name | String
anduser | Pointer<User>
.Add a CLP giving read/write access to the
user
column.explain
mode and look at the mongodb query. In my environment, I reproduced it using a user session token. Not sure if it can be reproduced with a master key.Expected Results
A simpler mongodb query
Actual Outcome
Environment Setup
Server
Database
Logs/Trace
The text was updated successfully, but these errors were encountered: