Skip to content

perf(artifact): seek pinned reuse lookups on their own partial index - #667

Open
harlan-github-agent[bot] wants to merge 1 commit into
mainfrom
fix/issue-663
Open

harlan-github-agent[bot] wants to merge 1 commit into
mainfrom
fix/issue-663

Conversation

@harlan-github-agent

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Closes #663

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking 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:

SEARCH r USING INDEX idx_artifact_resolutions_ready_public_commit (commit_sha=?)
SEARCH a USING INDEX sqlite_autoindex_artifacts_1 (id=?)
USE TEMP B-TREE FOR ORDER BY

After (path variant; the named variant seeks the same way through its own index on all five equality columns):

SEARCH r USING INDEX idx_artifact_resolutions_ready_public_pinned_path (commit_sha=? AND resolved_owner=? AND resolved_repository=? AND skill_path=?)
SEARCH a USING INDEX sqlite_autoindex_artifacts_1 (id=?)

Two indexes instead of one because a lookup cannot seek past the first column it leaves unconstrained: a path lookup leaves selector_type unconstrained and a name lookup leaves skill_path unconstrained, 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.

🤖 AI disclosure: Harlan Agent Kit modified this description. My AI open-source policy.

@harlan-github-agent harlan-github-agent Bot added harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. labels Oct 20, 2026
@harlan-github-agent

harlan-github-agent Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 QUEUED

Harlan Agent Kit posted this automated review. AI open source policy. The Dashboard shows the exact Queue position.

Next: Review starts when an Agent is free.

@harlan-github-agent harlan-github-agent Bot added harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. and removed harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. labels Oct 20, 2026
@harlan-github-agent harlan-github-agent Bot added harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. and removed harlan-agent-running An Agent holds a Task on this issue or pull request right now. harlan-agent-review-required Pull request triage requires an adversarial Review for this head commit. labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pinned artifact reuse lookup scans every ready row of the commit

0 participants