-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Inefficient queries in sync_role_definitions #25040
Labels
good first issue
Good first issues for new contributors
Comments
Hi @eschutho, can this issue be assigned to me. |
Ok |
rusackas
pushed a commit
that referenced
this issue
Oct 11, 2023
…rder to reduce number of query. (#25340)
Closing as the associated PR was merged. |
cccs-rc
pushed a commit
to CybercentreCanada/superset
that referenced
this issue
Mar 6, 2024
…n in order to reduce number of query. (apache#25340)
sfirke
pushed a commit
to sfirke/superset
that referenced
this issue
Mar 22, 2024
…n in order to reduce number of query. (apache#25340)
vinothkumar66
pushed a commit
to vinothkumar66/superset
that referenced
this issue
Nov 11, 2024
…n in order to reduce number of query. (apache#25340)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On init, the security manager syncs role definitions for Admin, Alpha, Gamma, etc. by invoking
set_role
with each role, passing in a function which filtersPermissionView
instances and determines if they should be in that role.set_role
then fetches allPermissionView
instances from the database and invokes the filter function.The filter function checks a load of rules about viewmenu and permission name, so ultimately we need to look at
pvm.permission.name
andpvm.view_menu.name
for everyPermissionView
we retrieved from the database: that's where this function is very inefficient. Because the relations withPermission
andViewMenu
are lazy, it's executing another 2 SELECT queries each for eachpvm
to get those two names, which should have been eagerly loaded when getting all the instances. Additionally, since allPermissionView
instances are fetched for every invocation ofset_role
, these queries are all run another 5x each.So the query count being executed by this sync task is approximately:
There's also a
ViewMenu
for every dataset, sopvm_count
can easily be 10000+.As a result of that, we're seeing this task hammer the database and take upward of 20 mins to execute. If we update it to eagerly load the relations it's likely we could reduce this to a single query and make it ~100x faster.
How to reproduce the bug
SQLALCHEMY_ECHO = True
sync_role_definitions
task, either from the flask shell or as part of thesuperset init
processExpected results
Should be faster and use fewer queries
Actual results
Slow, lots of queries.
Environment
(please complete the following information):
2.1.0
, but also checked the function inmaster
N/A
Checklist
Make sure to follow these steps before submitting your issue - thank you!
Additional context
Here's a sample of some of the queries observed:
clearly showing it's looking up entries individually.
I have a pretty good idea how to fix this so I will raise a PR if I get time, but it's quite a simple fix so perhaps someone who wants to contribute a small change to the project could take a look at it as well. The inefficiency doesn't have enormous impact because it happens during init, but it does nevertheless slow down the init process a lot when you have many datasets, so it would be good to fix.
The text was updated successfully, but these errors were encountered: