Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: improve performance of 'GetLatestWorkspaceBuildsByWorkspaceIDs'#19452

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

Merged

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedAug 20, 2025
edited
Loading

Closescoder/internal#716

This prevents a scan over the entireworkspace_build table by removing ajoin. This is still imperfect as we are still scanning over the number of builds for the workspaces in the arguments. Ideally we would have some index or something precomputed. Then we could skip scanning over the builds for the correct workspaces that are not the latest.

So this could be better, but this is a quick & cheap order of magnitude win.

Before: (69k rows scanned)

https://explain.dalibo.com/plan/d91d553ge694a18c

After: (2,500 rows scanned)

https://explain.dalibo.com/plan/6ec4eehde8c381a7#plan

Query used hits 2 workspaces with >1k builds.

EXPLAIN ANALYZESELECTDISTINCT ON (workspace_id)*FROMworkspace_build_with_user AS workspace_buildsWHEREworkspace_id = ANY(ARRAY['bb601d85-5354-4b72-a00a-a9293dcaf9fb', '192acfe6-339b-4745-8cd5-1b44a4e76348'] :: uuid[])ORDER BYworkspace_id, build_number DESC -- latest first;

Other notes

I tried to mess around with some indexes like: (plan)

CREATE INDEX idx_ws_build_latestON workspace_builds (workspace_id, build_number DESC)

This did not seem to help over theexisting index without theDESC. (plan)

ALTER TABLE ONLY workspace_builds    ADD CONSTRAINT workspace_builds_workspace_id_build_number_key UNIQUE (workspace_id, build_number);

Both indexs still scan over all the rows (105 in the plans).

Some latest evidence on dev

Screenshot From 2025-08-20 12-56-29

@EmyrkEmyrk marked this pull request as ready for reviewAugust 20, 2025 19:35
@cstyan
Copy link
Contributor

The query change makes sense.

I noticed that we're not enforcing a value to the limit parameter and we're also not logging (and I can't find tracing spans that have this info either) whether a limit value was passed, how many workspace IDs were passed, which pagination offset was passed, etc. All of which would help us identify whether the P99 is related to any of those.

@Emyrk
Copy link
MemberAuthor

I noticed that we're not enforcing a value to the limit parameter and we're also not logging (and I can't find tracing spans that have this info either) whether a limit value was passed, how many workspace IDs were passed, which pagination offset was passed, etc. All of which would help us identify whether the P99 is related to any of those.

We probably should have a sensible limit

@johnstcn
Copy link
Member

I noticed that we're not enforcing a value to the limit parameter and we're also not logging (and I can't find tracing spans that have this info either) whether a limit value was passed, how many workspace IDs were passed, which pagination offset was passed, etc. All of which would help us identify whether the P99 is related to any of those.

We probably should have a sensible limit

It's hard to know where to put the upper limit tbh without some real-world data. Let's revisit this idea when we do.

@EmyrkEmyrk merged commitef0d74f intomainAug 26, 2025
32 checks passed
@EmyrkEmyrk deleted the stevenmasley/better_GetLatestWorkspaceBuildsByWorkspaceIDs branchAugust 26, 2025 14:26
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 26, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

bug: GetLatestWorkspaceBuildsByWorkspaceIDs creates a lot of DB load
3 participants
@Emyrk@cstyan@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp