- Notifications
You must be signed in to change notification settings - Fork1k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Filter is applied in original workspace query.
INNER JOIN | ||
workspacesonwb.workspace_id=workspaces.id | ||
WHERE | ||
-- Only return workspaces that match the user + organization. | ||
-- Quotas are calculated per user per organization. | ||
NOTworkspaces.deletedAND |
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.
Thisworkspaces.deleted
being placed in this join sub query prevents the workspacesseq scan
from what I can tell.
The alternative place is to place it in the final query asNOT workspaces.deleted
.
This is equivalent though because we are doing anINNER JOIN
onworkspace_builds
andworkspaces
. If theworkspace
is deleted, it's builds are completely omitted fromlatest_builds
Emyrk commentedNov 1, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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!
2d00b50
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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