-
Notifications
You must be signed in to change notification settings - Fork 924
chore: remove excess join in GetQuotaConsumedForUser query #15338
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
Conversation
Filter is applied in original workspace query.
INNER JOIN | ||
workspaces on wb.workspace_id = workspaces.id | ||
WHERE | ||
-- Only return workspaces that match the user + organization. | ||
-- Quotas are calculated per user per organization. | ||
NOT workspaces.deleted AND |
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.
This workspaces.deleted
being placed in this join sub query prevents the workspaces seq scan
from what I can tell.
The alternative place is to place it in the final query as NOT workspaces.deleted
.
This is equivalent though because we are doing an INNER JOIN
on workspace_builds
and workspaces
. If the workspace
is deleted, it's builds are completely omitted from latest_builds
@spikecurtis You did ask in the other thread if a Bitmap Heap Scan locks the entire
I do not know at what scale these fine locks get more coarse. I imagine adding indices would just do a page lock on an index? Not really sure, but I am going to hold off adding more indices at this time. |
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.
LGTM!
Followup of #15261
Filter is applied in original workspace query. We do not need to join
workspaces
twice. Also used build_number instead ofcreated_at
for determining the last build.Plans below run on dev.coder.com database. Interestingly the
seq scan
onworkspaces
goes away. It was happening on the second join? Because of this, ourSIReadLock
becomes finer on theworkspaces
table. It goes fromworkspaces/relation/SIReadLock
toworkspaces/tuple/SIReadLock: page=0 tuple=1
Before
Plan
SIReadLock
Locks:Raw locks
After
Plan
SIReadLock
Locks:Raw locks