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(coderd/database): optimize GetRunningPrebuiltWorkspaces#18588

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

Open
johnstcn wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromcj/optimize/GetRunningPrebuiltWorkspaces

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedJun 25, 2025
edited
Loading

@johnstcnjohnstcn marked this pull request as ready for reviewJune 26, 2025 20:50
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I was a bit thrown off by the indentation, but I tried my best 😆, left some suggestions and questions.

ready_agents.job_id = latest_prebuilds.job_id
ORDER BY
latest_prebuilds.workspace_id ASC
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: s/spaces/tabs/

Comment on lines +53 to +54
latest_prebuilds
AS (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
latest_prebuilds
AS (
latest_prebuildsAS (

We could reduce indentation a bit here.

Comment on lines +63 to +65
FROM
workspaces
LEFT JOIN LATERAL (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
FROM
workspaces
LEFT JOIN LATERAL (
FROM
workspaces
LEFT JOIN LATERAL (

As well as here, SQL is a weird syntax in that it doesn't really have any meaningful nesting.

Comment on lines +78 to +79
provisioner_jobs.id
= workspace_builds.job_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
provisioner_jobs.id
=workspace_builds.job_id
provisioner_jobs.id=workspace_builds.job_id

What's this 😆, (see others as well)

AS (
SELECT
latest_prebuilds.job_id,
BOOL_AND(workspace_agents.lifecycle_state = 'ready'::workspace_agent_lifecycle_state)::boolean AS ready
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
BOOL_AND(workspace_agents.lifecycle_state='ready'::workspace_agent_lifecycle_state)::booleanAS ready
workspace_agents.lifecycle_state='ready'::workspace_agent_lifecycle_stateAS ready

What's this, it actually works?

latest_prebuilds.created_at
FROM
latest_prebuilds
LEFT JOIN ready_agents ON
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This join will duplicate rows when there are multiple agents since there is no group-by here or in theready_agents CTE, was this considered?

JOIN workspace_agents ON
workspace_agents.resource_id = workspace_resources.id
WHERE
workspace_agents.deleted = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For consideration: Should we filter out sub agents? I.e.AND workspace_agents.parent_id IS NULL.

Comment on lines +95 to +98
AND latest_build.transition
= 'start'::workspace_transition
AND latest_build.job_status
= 'succeeded'::provisioner_job_status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Potential performance improvement, move these intolatest_build subquery.

Also, please consider whether it should be aLEFT JOIN LATERAL or(INNER) JOIN LATERAL. With these filters it's essentially an INNER join currently.

workspace_builds.workspace_id
= workspaces.id
ORDER BY
workspace_builds.workspace_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggestion: Could remove this redundant ordering due to WHERE filter (keep build_number though).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mafredrimafredrimafredri left review comments

@SasSwartSasSwartAwaiting requested review from SasSwart

At least 1 approving review is required to merge this pull request.

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

bug: GetRunningPrebuiltWorkspaces creates lots of DB load
2 participants
@johnstcn@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp