Skip to content
Back to skills

Query Optimization

ASecurity

Diagnose a slow database query using workload evidence and execution plans, then verify a bounded change without altering result semantics.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 13, 2026
ai-agentssqlgitdatabase

Security analysis

A100/100

Scanned October 13, 2026

npx -y skills add sujith011/agentic-pro-skills --skill query-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Query Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Query Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sujith011-query-optimization/badge)](https://www.skillsdirectory.com/skills/sujith011-query-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: query-optimization
description: "Diagnose a slow database query using workload evidence and execution plans, then verify a bounded change without altering result semantics."
---

# Query Optimization

## Process
1. Capture the exact query shape, parameters, cardinality, concurrency, latency distribution, and database/version. Inspect ORM-generated SQL and repeated queries.
2. Obtain an estimated plan first. Actual-plan tools such as EXPLAIN ANALYZE execute the statement; use an authorized safe environment and a bounded workload. A rollback cannot undo every external or sequence side effect.
3. Compare estimated and actual row counts, scanned rows, joins, sorts/spills, index usage, lock waits, and network/materialization cost. A sequential scan may be correct for a broad result.
4. Change one cause: query shape, unnecessary columns, batching, index, or statistics. Account for index write/storage cost and deployment lock behavior.
5. Re-measure with representative data, several parameter distributions, and comparable cache conditions. Confirm identical ordering, null handling, and authorization.

## Example
A list endpoint makes one customer query per row. Fetch the required customer summaries in a bounded batch and compare query count and latency while preserving pagination order.

## Stop conditions
Do not run heavy plans or index operations against production without target authorization. Do not force index usage solely because a scan appears in a plan.

## Evidence
- Before/after SQL, plans, and dataset context.
- Latency/query-count measurements.
- Result-equivalence checks and rollout cost.

## Reference
Workflow independently written after reviewing [postgresql-optimization](https://github.com/sickn33/agentic-awesome-skills/blob/cb30121a2dfd007531bd2fbefb56f68de927da6a/skills/postgresql-optimization/SKILL.md).

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.