database-query-optimization

database-query-optimization is a skill for Claude Code, Codex from KraitDev/skiLL.Md. It costs 23 tokens per session (1,587 once invoked), scanned A, original, MIT.

A method for finding and fixing slow database access. It examines query plans and application code to identify issues such as repeated queries, unnecessary table scans, and missing indexes.

In plain words
What is it for?
Use it for complex SQL or ORM queries, slow read-heavy endpoints, database migrations for growing data, and loops that repeatedly query the database.
Why use it?
It replaces performance guesswork with evidence from database analysis, helping slow endpoints and high database CPU usage be traced to specific causes.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument; mentions Codex.

Good fit Use it for complex SQL or ORM queries, slow read-heavy endpoints, database migrations for growing data, and loops that repeatedly query the database.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/kraitdev/skill.md/database-query-optimization
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add KraitDev/skiLL.Md --skill database-query-optimization
Clone the repo
git clone --depth 1 https://github.com/KraitDev/skiLL.Md

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for database-query-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/kraitdev/skill.md/database-query-optimization/github.svg)](https://agentmods.dev/skills/kraitdev/skill.md/database-query-optimization)
Your own site
<a href="https://agentmods.dev/skills/kraitdev/skill.md/database-query-optimization"><img src="https://agentmods.dev/badge/skills/kraitdev/skill.md/database-query-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for database-query-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/kraitdev/skill.md/database-query-optimization"><img src="https://agentmods.dev/badge/skills/kraitdev/skill.md/database-query-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 23 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,587 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00023 $0.01587
Opus 5.5 $0.00009 $0.00635
Sonnet 5.5 $0.00005 $0.00317
Haiku 4.5 $0.00002 $0.00159

Measured 1mo ago against content hash 4aaaf594b2dc, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

database-query-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/backend/database-query-optimization/SKILL.md · 161 lines

How it starts

The opening of the file, as written. The whole thing — 161 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Query Optimization

Purpose

Slow databases kill applications. This skill replaces guesswork with systematic performance analysis, using EXPLAIN plans and profiling to eliminate N+1 queries, eliminate unnecessary scans, and add targeted indexes so the database bears the computational load, not the application.

When to use

  • Writing complex SQL queries or ORM access functions
  • Resolving performance bottlenecks on read-heavy endpoints
  • Designing schema migrations for growing datasets
  • Refactoring loops that make repeated database calls

When NOT to use

  • Schema design (different concern)
  • Database selection (architectural decision)
  • Caching strategies (use Caching Strategies skill)
  • Application-level performance (profilers, algorithms)

Inputs required

  • Slow query logs or endpoint metrics
  • ORM code accessing the database
  • Database schema (tables, columns, indexes)
  • EXPLAIN ANALYZE capability (test environment)

Workflow

  1. Profile the Bottleneck: Run EXPLAIN ANALYZE on slow queries to identify sequential scans and high-cost operations
  2. Identify N+1: Locate loops making repetitive database calls for the same entity type
  3. Measure Selectivity: Analyze WHERE clause filters and add indexes to highly selective columns
  4. Replace Loops: Replace N+1 with single IN queries or ORM eager-loading (JOINs)
  5. Remove Over-Fetching: Replace SELECT * with explicit column names
  6. Add Indexes: Add B-Tree indexes to WHERE, JOIN, and ORDER BY columns in slow queries
  7. Paginate: Enforce LIMIT and OFFSET (or cursor pagination) on all collection queries
  8. Verify Performance: Re-run EXPLAIN ANALYZE and benchmark end-to-end latency

Rules

  • MUST explicitly define selected columns (NEVER use SELECT * in production)
  • MUST NEVER have database operations inside loops
  • MUST perform filtering and aggregation in the database, not application memory
  • MUST enforce LIMIT and OFFSET on collection queries
  • MUST EXPLAIN before adding indexes (verify they reduce cost)
  • MUST rollback indexes if they degrade INSERT/UPDATE performance
  • MUST NOT over-index (each index has maintenance cost)

Read the full file on GitHub · 161 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 161 lines · 23 tokens per session scan A 4aaaf594b2dc

Subscribe to this mod's changes

database-query-optimization is a skill published in the GitHub repository KraitDev/skiLL.Md (6 stars, last pushed 4mo ago), licensed MIT. It adds 23 tokens to every session and 1,587 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

sql-query-optimization

Diagnoses and optimises slow SQL queries using EXPLAIN ANALYZE. Covers identifying bottlenecks (sequential scans, bad estimates, heap fetches), index strategy, query rewrites, and verification. Invoked when the user asks to optimize a query, fix a slow database query, or improve database performance.

soulcodex/agentic · 70 tokens

SQL Query Optimizer

Reviews SQL queries for performance issues and rewrites them with optimized execution plans.

Notysoty/openagentskills · 20 tokens

sql-optimization

A guide to improving SQL queries, the commands used to read and change data in databases. It covers examining how MySQL and PostgreSQL execute queries and designing indexes that help them find data faster.

chaterm/terminal-skills · 10 tokens

sql-sentinel

Audit SQL for the cost & performance anti-patterns that burn warehouse credits. Catches SELECT , full-table scans, non-sargable predicates, Cartesian joins, NULL-trap NOT IN, and 17 more rules. Scores warehouse health 0-100 and outputs a prioritized cost-reduction plan for BigQuery, Snowflake, Redshift, and Postgres.

takeaseatventure/sql-sentinel · 77 tokens

PostgreSQL Database Administration

Comprehensive PostgreSQL database administration skill for customer support tech enablement, covering database design, optimization, performance tuning, backup/recovery, and advanced query techniques.

manutej/luxor-claude-marketplace · 37 tokens

PostgreSQL Performance Optimization

Production-grade PostgreSQL query optimization, indexing strategies, performance tuning, and modern features including pgvector for AI/ML workloads. Master EXPLAIN plans, query analysis, and database design for high-performance applications.

bobmatnyc/mcp-skillset · 47 tokens