Repository navigation
perf(artifact): seek pinned reuse lookups on their own partial index - #667
Open
harlan-github-agent[bot] wants to merge 1 commit into
Open
harlan-github-agent[bot] wants to merge 1 commit into
harlan-github-agent[bot] wants to merge 1 commit into
Conversation
Contributor
Author
🤖 QUEUED
Next: Review starts when an Agent is free. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🔗 Linked issue
Closes #663
❓ Type of change
📚 Description
The d1-query-review routine found that the lookup for a build pinned to a commit read all 878 ready rows of that commit and sorted them on every execution: 31,984 executions in one week, 20.9% of all Artifact lookup time. The only ready-public partial index leads with the columns the resolved lookup supplies, so a pinned lookup could seek nothing but the commit itself.
Migration 0158 adds one ready-public partial index per pinned variant, Skill path and Skill name. Each holds every equality column its lookup supplies and ends in the query's
ORDER BY created_at DESC, id DESC, so SQLite seeks straight to the candidates newest first and stops at the first one whose Artifact is available, with no sort. The resolved lookup keeps migration 0131, and a plan test now pins that so it stays.Same statement over the real migration chain in a local fixture, before:
After (path variant; the named variant seeks the same way through its own index on all five equality columns):
Two indexes instead of one because a lookup cannot seek past the first column it leaves unconstrained: a path lookup leaves
selector_typeunconstrained and a name lookup leavesskill_pathunconstrained, so no single column order serves both.One thing I could not check locally: this relies on D1's planner running without statistics, exactly as migration 0131 does, and the real rows-read drop needs a fresh D1 Insights window after this deploys.