AgentStack
SKILL verified MIT Self-run

Query Optimizer

skill-m-binimran-dev-pack-query-optimizer · by m-binimran

Diagnose and fix slow Postgres queries using EXPLAIN ANALYZE, index suggestions, and N+1 detection. Use when a query is slow, a page is slow because of the DB, or before shipping a query that touches a large table.

No reviews yet
0 installs
14 views
0.0% view→install

Install

$ agentstack add skill-m-binimran-dev-pack-query-optimizer

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Query Optimizer? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

query-optimizer

Make the query fast based on evidence, not guesses.

Process

  1. Get the plan: run EXPLAIN (ANALYZE, BUFFERS) . Never optimize without it.
  2. Read the plan top-down: find the costliest node. Look for:
  • Seq Scan on a big table where an index could be used.
  • Rows Removed by Filter high → missing/!selective index.
  • Estimated vs actual rows far apart → stale stats (ANALYZE).
  • Nested loop over many rows → maybe a hash/merge join is better.
  1. Propose the smallest fix: an index, a rewritten predicate, a LIMIT, or pagination.
  2. Re-measure with EXPLAIN ANALYZE and report before/after timing. Don't claim a win without it.

Common fixes

  • Composite index ordered by selectivity for multi-column filters.
  • Partial index (where active) for queries that always filter the same way.
  • Replace OFFSET pagination with keyset (where id > $last) for deep pages.
  • Kill N+1: one query per row in app code → use a join or IN (...)/= ANY.

Output

  • The plan's bottleneck in one sentence.
  • The fix (SQL/DDL).
  • Before/after timing from real EXPLAIN ANALYZE runs.

Guardrails

  • An index isn't free — it slows writes. Only add what the plan justifies.
  • Don't add an index that duplicates an existing one's prefix.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.