chore: optimize GetPrebuiltWorkspaces query #18717
Open
+346
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hopefully fixes coder/internal#715 this time.
Second attempt at this.
Previous attempt incorrectly returned all rows for which there existed a prebuild that had previously had a successful start transition at some point: #18588
Explain before (71.1ms): https://explain.dalibo.com/plan/9be18ab833b7a000
Explain after (9.8ms): https://explain.dalibo.com/plan/b4a94742gaha229g(EDIT: not selecting from correct CTE)Explain after (11.2ms): https://explain.dalibo.com/plan/bea42b563ff7fbe7
Manually verified against dogfood db:
Diff is only due to unstable row order, also added additional testing in
coderd/database/querier_test.go
to validate changes.If we want to be super careful about this, I can instead break out the updated query into a new function and diff the old versus the new on each reconcile call.