agentsclimarketplace

Sql optimization

Skill Amey-Thakur/AI-SKILLS/skills/databases/sql-optimization

Plug-and-play skills and prompts for every AI coding agent

Install
npx -y skills add Amey-Thakur/AI-SKILLS --skill sql-optimization

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 20 days oldThe repository was created 20 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Diagnose and fix slow SQL with the query plan as evidence, not folklore. Use when a query is slow, a table scan appears, or database load climbs.

SKILL.md

2.5 KB, 545 tokens by cl100k_base, as published. Nobody here has run it

SQL optimization

Optimize from the plan, not from vibes. Every database ships an EXPLAIN; folklore fixes applied without it make some queries faster and others quietly worse.

Method

  1. Measure the actual query with real parameters and production-like data volume. A query fast on 1k dev rows tells you nothing about 10M. Capture: rows examined vs rows returned, time, and the plan (EXPLAIN ANALYZE where available).
  2. Read the plan for the expensive truth. The usual suspects, in the order they pay off:
    • Full scan where a seek belongs: filter or join column lacks a usable index, or the predicate defeats it (function on the column, leading wildcard, implicit type cast).
    • Examined ≫ returned: thousands read to return ten: missing composite index, or filtering happens after the join instead of in it.
    • Sort or hash spilling: ORDER BY/GROUP BY/DISTINCT on an unindexed expression over a large set.
    • N+1 at the application seam: one query per row in a loop; the plan looks fine, the trace shows 400 of them.
  3. Fix in this order, cheapest first:
    • Rewrite the predicate to be index-friendly (move the function to the constant side; match types exactly).
    • Add or extend a composite index: equality columns first, then the range column, then covering columns if the engine supports them. One good composite beats three single-column indexes.
    • Restructure the query: select only needed columns, filter before joining, replace correlated subqueries with joins or window functions, paginate by keyset (WHERE id > ?) not OFFSET at depth.
    • Only then reach for denormalization, materialized views, or caching , real costs that need the earlier steps ruled out.
  4. Verify against the same measurement, same data, same parameters. Then check the write side: every index taxes every insert and update on that table. An index that saves one report and slows every checkout is a bad trade.

Rules

  • Never claim a fix without before/after numbers from comparable data.
  • Distrust SELECT * on principle: it defeats covering indexes and widens every row on the wire.
  • A query that cannot be made fast may be the wrong question: say so and propose the schema or access-pattern change honestly.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.