
Fix Slow Queries
Diagnoses slow PostgreSQL queries and fixes them with comparisons and regression tests.
Install
npx skills add paperclipai/paperclip --skill fix-slow-queries -g -a claude-code -y- Repository
- paperclipai/paperclip110k
- Category
- Engineering
- Updated
- 3d ago
- License
- MIT
- Context cost
- Mediumabout 2,756 tokens
- Runs scripts
- No, instructions only
What it does
Diagnose and fix slow Paperclip PostgreSQL queries using Cloud and Neon evidence, local reproduction, performance and result comparisons, regression tests, and a PR with passing checks. Use for costly queries, repeated database work, or slow requests with a suspected database cause.
Fix Slow Queries
Deliver a measured improvement with preserved behavior and a reviewable PR whose latest commit passes checks. A list of suspicious SQL or an unverified rewrite is an intermediate result. Respect a narrower request for diagnosis only.
1. Establish the target and finish line
- Resolve the reported URL, environment, company/workspace, deployed revision,
owning repository, and local checkout. Read its
AGENTS.mdand scoped rules. Paperclip and the privatepaperclip-cloudcontrol plane have different rules. - Work in a dedicated branch/worktree. Reuse suitable existing work; keep the checkout running a live server out of branch switching and benchmark setup.
- Select a bounded batch, usually the top two or three query families. Record deferred candidates so discovery does not turn into an unbounded rewrite.
- The finish line is: reproducible baseline, faster treatment, output/behavior proof, relevant regression coverage, and green checks on each final PR head. A concrete access or infrastructure blocker must be reported as incomplete.
2. Find the actual database and rank the work
Read Cloud discovery when starting from a hosted workspace. Follow the chain from Paperclip Cloud fleet admin to the stack's Neon project, branch, endpoint, database, and runtime role. Record the corresponding application deployment and time window. Do not reuse IDs from a previous run.
Capture query text/fingerprint, calls, total execution time, mean time, rows, and available I/O, temporary-file, and lock-wait evidence. Rank both expensive individual calls and frequent work with high aggregate cost. Group variants by their actual caller; do not add unrelated query means into an endpoint latency.
Keep three claims separate:
