-
Notifications
You must be signed in to change notification settings - Fork 12
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
ID-891 Optimize UserResourcesQuery #1226
Conversation
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.
made a suggestion for now or for the future
join ${ResourceTypeTable as resourceType} on ${resourceType.id} = ${resource.resourceTypeId} | ||
where ${resourceType.name} = ${resourceTypeName} |
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.
if you want to go a little further
join ${ResourceTypeTable as resourceType} on ${resourceType.id} = ${resource.resourceTypeId} | |
where ${resourceType.name} = ${resourceTypeName} | |
where ${resource.resourceTypeId} = ${resourceTypePKsByName(resourceTypeName)} |
also could remove the ResourceTypeTable join and replace
where ${resourceType.name} = ${resourceTypeName}
with
where ${resource.resourceTypeId} = ${resourceTypePKsByName(resourceTypeName)}
src/main/scala/org/broadinstitute/dsde/workbench/sam/dataAccess/PostgresAccessPolicyDAO.scala
Show resolved
Hide resolved
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.
Lets test on Dev and make sure that the query is returning everything and behaving as we expect. Once that's done, to prod we go!
14ab202
to
0f342b3
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@tlangs I ran:
and that returned nothing so they are returning the same rows |
Ticket: https://broadworkbench.atlassian.net/browse/ID-891
What/why:
This query is accounting for the majority of the cpu load in sam, for some reason postgres is doing a full table scan of
sam_effective_resource_policy
every single time the query is ran, despite there being indexes on the table. This modification forces the join ofsam_effective_resource_policy
to filter down to only resource_ids of the type we are looking for.How:
This modification to the query should be functionally equivalent, but forces the postgres query planner to do an index scan instead of a full table scan:
before
-> Parallel Seq Scan on sam_effective_resource_policy effpol (cost=0.00..14559.75 rows=537375 width=24)
after
-> Index Scan using idx_erp_resource_id on sam_effective_resource_policy effpol (cost=0.43..0.63 rows=6 width=24)
PR checklist