sql
Skill33 starsChanged 34 days agoMITView on GitHub
Use when writing or optimizing SQL. Covers query planning, indexing strategy, window functions, CTEs, transaction isolation, and reading EXPLAIN output. Trigger on "this query is slow", "how do i read this explain plan", "write a window function for running totals", "what isolation level should i use". Do not use when the whole database is the bottleneck under load — see the database-performance skill; for Postgres-specific operations, see the postgres skill.
15 other projects use a version of this.
Adopted by
Most recently taken up by
- base58ed/claude_code_filestheir own version, first seen Oct 20, 2026
- G1Joshi/Agent-Skillstheir own version, first seen Oct 13, 2026
- zeeshanalimughal/claude-skillstheir own version, first seen Oct 13, 2026
- BrendenKennedy/claude-for-ai-platformstheir own version, first seen Oct 13, 2026
- sendou-ink/sendou.inktheir own version, first seen Oct 8, 2026
- SparkDevNetwork/Rocktheir own version, first seen Oct 8, 2026
Other versions15 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 15
- Zafer-Liu/Data-Analysis-Agent★ 2.6ksame name
- SparkDevNetwork/Rock★ 701same name
- sendou-ink/sendou.ink★ 303same name
- maragudk/skills★ 49same name
- G1Joshi/Agent-Skills★ 15same name
- redpanda-data/skills★ 8same name
- thechandanbhagat/claude-skills★ 8same name
- Spardutti/claude-skills★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
5 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository137 other files it gives its agents.
- agent-instructionsSkill
- agent-memorySkill
- hooksSkill
- plugin-developmentSkill
- skill-authoringSkill
- skill-reviewSkill
- slash-commandsSkill
- subagentsSkill
- agent-designSkill
- context-engineeringSkill
- fine-tuningSkill
- llm-cost-optimizationSkill
- llm-evaluationSkill
- llm-integrationSkill
- mcp-serverSkill
- ml-pipelineSkill
- model-selectionSkill
- prompt-engineeringSkill
- ragSkill
- structured-outputSkill
- api-designSkill
- background-jobsSkill
- cachingSkill
- djangoSkill
- event-driven-architectureSkill
- fastapiSkill
- graphqlSkill
- microservicesSkill
- nestjsSkill
- realtime-websocketsSkill
- spring-bootSkill
- competitive-analysisSkill
- lead-researchSkill
- product-analysisSkill
- resumeSkill
- user-researchSkill
- database-performanceSkill
- data-modelingSkill
- data-qualitySkill
- pandasSkill
- postgresSkill
- sparkSkill
- brand-guidelinesSkill
- generative-artSkill
- themingSkill
- ui-reviewSkill
- visual-designSkill
- architecture-decisionsSkill
- bug-fix-protocolSkill
- cli-developmentSkill
- code-reviewSkill
- debuggingSkill
- design-patternsSkill
- domain-modelingSkill
- git-workflowSkill
- legacy-modernizationSkill
- refactoringSkill
- repository-explorationSkill
- simple-designSkill
- system-designSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Write SQL that the planner can execute efficiently, and read execution plans well enough to know why it did not.
- Very specific: line 56
Never run an unbounded UPDATE or DELETE on a large table in one transaction — batch it.
- Very specific: line 58
Prefer keyset pagination (WHERE id > :last) over OFFSET — offset cost grows linearly with page depth.
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQL
Purpose
Write SQL that the planner can execute efficiently, and read execution plans well enough to know why it did not.
When to Use
- Writing non-trivial queries: aggregations, window functions, recursive CTEs.
- Diagnosing a slow query.
- Designing indexes for a known access pattern.
- Choosing a transaction isolation level.
- Reviewing migrations for lock risk.
Capabilities
- Query authoring: joins, CTEs, window functions, lateral joins, upserts.
- Index design: composite ordering, covering indexes, partial indexes.
- Plan reading:
EXPLAIN (ANALYZE, BUFFERS)and the shapes that signal trouble. - Isolation levels and the anomalies each one permits.
- Safe migrations: concurrent index builds, backfills, lock avoidance.
Inputs
- The query, the schema, and the row counts of the tables involved.
- Existing indexes.
- The actual execution plan, not a guess about it.
Outputs
- A rewritten query, an index, or both — with a before/after plan.
- Migration statements that do not hold long locks.
Workflow
- Get the plan —
EXPLAIN (ANALYZE, BUFFERS). Never optimize a query you have not profiled. - Find the expensive node — Look for sequential scans on large tables, nested loops with high row counts, and estimates that diverge from actuals by an order of magnitude.
- Fix the cause — Bad estimate means stale statistics. Sequential scan on a selective filter means a missing index. High row counts through a join means the filter is applied too late.
- Index deliberately — Column order in a composite index is equality columns first, then the range or sort column.
- Re-measure — Confirm with a fresh plan, and check that write throughput did not regress.
Best Practices
- An index on
(a, b)serves queries filtering ona, and onaandb— but not onbalone. - Wrapping an indexed column in a function (
WHERE lower(email) = ...) disables the index unless the index is on the expression. SELECT *in application code prevents index-only scans and breaks when the schema changes.- Never run an unbounded
UPDATEorDELETEon a large table in one transaction — batch it. CREATE INDEX CONCURRENTLYin production; the plain form locks writes for the duration.- Prefer keyset pagination (
WHERE id > :last) overOFFSET— offset cost grows linearly with page depth.
Examples
Window function instead of a correlated subquery:
-- Latest order per customer, one pass.
SELECT customer_id, order_id, placed_at, total_cents
FROM (
SELECT
o.customer_id,
o.id AS order_id,
o.placed_at,
o.total_cents,
ROW_NUMBER() OVER (
PARTITION BY o.customer_id
ORDER BY o.placed_at DESC
) AS rn
FROM orders o
WHERE o.placed_at >= now() - interval '90 days'
) ranked
WHERE rn = 1;Index matching the access pattern:
-- Query: WHERE tenant_id = $1 AND status = 'open' ORDER BY created_at DESC LIMIT 50
CREATE INDEX CONCURRENTLY idx_tickets_tenant_open_recent
ON tickets (tenant_id, status, created_at DESC)
WHERE deleted_at IS NULL;Notes
- The partial index above only covers live rows, keeping it small and hot in cache.
READ COMMITTED(the default in PostgreSQL) permits non-repeatable reads. If a transaction reads a row, decides, and writes based on that decision, you needREPEATABLE READplus retry logic, orSELECT ... FOR UPDATE.- Statistics drift after bulk loads. Run
ANALYZEbefore benchmarking anything.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

