query

query is a skill for Claude Code, Codex from arbazkhan971/godmode. It costs 10 tokens per session (1,077 once invoked), scanned A, original, MIT.

A guide to finding and fixing slow database queries using query plans, indexes, and application-generated SQL. EXPLAIN is a database command that shows how a query is expected to run, while EXPLAIN ANALYZE measures its actual run.

In plain words
What is it for?
Use it to investigate slow queries, interpret EXPLAIN output, choose indexes, detect N+1 query patterns, and tune PostgreSQL, MongoDB, or Redis access.
Why use it?
It helps identify issues such as missing indexes, inefficient joins, outdated statistics, and repeated queries. This replaces guesswork with evidence about where query time is spent.

Skill for Claude CodeCodex

Part of the godmode plugin — 133 skills, 1 command, 9 agents, 3 MCP servers shipped together

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.

agentmods
npx agentmods add skills/arbazkhan971/godmode/query
Any agent
npx skills add arbazkhan971/godmode --skill query
Clone the repo
git clone --depth 1 https://github.com/arbazkhan971/godmode

Made for: Claude Code, Codex.

Or install godmode, the plugin that ships this one along with the rest of its 133 skills, 1 command, 9 agents, 3 MCP servers.

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 query

README.md
[![agentmods](https://agentmods.dev/badge/skills/arbazkhan971/godmode/query.svg)](https://agentmods.dev/skills/arbazkhan971/godmode/query)
Your own site
<a href="https://agentmods.dev/skills/arbazkhan971/godmode/query"><img src="https://agentmods.dev/badge/skills/arbazkhan971/godmode/query.svg" alt="Measured on agentmods" height="20"></a>
Per session 10 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,077 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00010 $0.01077
Opus 5 $0.00005 $0.00539
Sonnet 5 $0.00002 $0.00215
Haiku 4.5 $0.00001 $0.00108

Measured 2d ago against content hash 7d3c7b527568, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

query 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 2d 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/query/SKILL.md · 143 lines

How it starts

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

Activate When

  • /godmode:query, "this query is slow", "optimize"
  • EXPLAIN plan interpretation, indexing strategy
  • N+1 problem, complex aggregation, slow query log

Workflow

1. Query Context

Database: PostgreSQL|MySQL|SQLite|MongoDB|Redis
Access via: Raw SQL|Prisma|Django ORM|ActiveRecord|GORM
Table(s): <involved tables>
Estimated rows: <approximate counts>
Current time: <ms>  Target: <ms>
# Extract ORM-generated SQL
# Prisma: new PrismaClient({ log: ['query'] })
# Django: django.db.connection.queries
# Rails: ActiveRecord::Base.logger = Logger.new(STDOUT)

2. EXPLAIN Analysis

-- PostgreSQL (most informative)
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) <query>;
-- Safe mode (no execution)
EXPLAIN (COSTS, FORMAT JSON) <query>;
Red flags:
[ ] Seq Scan on > 10K rows — needs index
[ ] Nested Loop on large tables — use hash join
[ ] Estimated vs actual off > 10x — stale stats
[ ] Sort on disk — needs work_mem or index
[ ] Filter removes > 90% scanned — index needed
[ ] Seq Scan inside loop — N+1 pattern

IF MongoDB: db.collection.find().explain("executionStats") Check totalDocsExamined vs nReturned ratio. IF Redis: SLOWLOG GET 10 for slow commands.

3. Diagnose Issues

Missing Index:
  Evidence: Seq Scan on <table> filtering by <col>
  Fix: CREATE INDEX idx_<table>_<col> ON <table>(<col>)
N+1 Query:
  Evidence: <N> identical queries in loop
  Fix: JOIN or eager loading (includes/select_related)
  ORM: Django select_related, Prisma include,
    Rails includes, SQLAlchemy joinedload
Inefficient Join:
  Evidence: Nested Loop on <N>x<M> rows
  Fix: Ensure join columns indexed both sides
Over-fetching:
  Evidence: SELECT * returning <N> unused columns
  Fix: SELECT only needed columns
Stale Statistics:
  Evidence: Estimated <N> vs actual <M> (off by >10x)
  Fix: ANALYZE <table>

IF improvement < 10% after optimization: diminishing returns. IF query still > 1s after indexes: consider materialized view.

4. Index Recommendations

B-tree (default): equality, range, sort, LIKE 'prefix%'
GIN: full-text search, JSONB, arrays
BRIN: very large tables with natural ordering
Partial: WHERE active=true (smaller, faster)
Covering (INCLUDE): enables index-only scan
-- ALWAYS use CONCURRENTLY in production PostgreSQL
CREATE INDEX CONCURRENTLY idx_name ON table(col);

Trade-off: every index speeds reads, slows writes. IF write-heavy table (> 1000 writes/sec): limit to 3-5 indexes.

Read the full file on GitHub · 143 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. 2d ago First seen · 143 lines · 10 tokens per session scan A 7d3c7b527568

Subscribe to this mod's changes

query is a skill published in the GitHub repository arbazkhan971/godmode (26 stars, last pushed 7d ago), licensed MIT. It adds 10 tokens to every session and 1,077 once invoked, about $0.0001 per session on Opus 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-09-03.

Related

Other skills, from other repositories

database-patterns

DB schema design and query tuning: normalization, indexing, N+1, transactions, EXPLAIN. Triggers: schema, index, slow query, N+1, PostgreSQL, MySQL, EXPLAIN, deadlock, query plan.

softspark/ai-toolkit · 55 tokens

nw-database-technology-selection

Database comparison catalogs, RDBMS vs NoSQL selection criteria, CAP/ACID/BASE theory, OLTP vs OLAP, and technology-specific characteristics.

nWave-ai/nWave · 38 tokens

nuxthub

Use when building NuxtHub v0.10.6 applications - provides database (Drizzle ORM with sqlite/postgresql/mysql), KV storage, blob storage, and cache APIs. Covers configuration, schema definition, migrations, multi-cloud deployment (Cloudflare, Vercel), and the new hub:db, hub:kv, hub:blob virtual module imports.

YuDefine/nuxt-supabase-starter · 78 tokens

edge-serverless-db-expert

Expert guide for Serverless & Edge Databases (Neon Serverless Postgres, Cloudflare D1, Turso/libsql, Upstash Redis), cold-start mitigation, and connection pooling / Panduan ahli database Serverless & Edge (Neon, Cloudflare D1, Turso, Upstash).

roedyrustam/vibes-plug · 69 tokens

managed-db-services

Configure DigitalOcean Managed MySQL, MongoDB, Valkey, Kafka, and OpenSearch for App Platform. Use when setting up non-PostgreSQL databases, configuring trusted sources, or troubleshooting database connectivity.

digitalocean-labs/do-app-platform-skills · 46 tokens

pg-migration

PostgreSQL schema migration safety reviewer and DDL generator. ALWAYS use when writing, reviewing, or planning PostgreSQL schema changes — ALTER TABLE, CREATE/DROP INDEX, column type changes, constraint additions, RLS policy changes, or any DDL touching production tables. Covers lock-level analysis, CREATE INDEX…

johnqtcg/awesome-skills · 135 tokens