sql-optimization-patterns

sql-optimization-patterns is a skill for Claude Code, Codex from LuizEduPP/Rememb. It costs 45 tokens per session (3,365 once invoked), scanned A, original, MIT.

A guide to improving SQL, the language used to query databases, through indexes, query-plan analysis, and database design techniques. It focuses on how databases find and combine stored data.

In plain words
What is it for?
Use it to inspect EXPLAIN query plans, choose indexes, design efficient schemas, improve response times, reduce database load, and resolve N+1 query problems.
Why use it?
It helps diagnose slow queries and reduce unnecessary database work, especially as datasets grow. It also addresses common problems such as scanning whole tables and making repeated queries for related data.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to inspect EXPLAIN query plans, choose indexes, design efficient schemas, improve response times, reduce database load, and resolve N+1 query problems.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/luizedupp/rememb/sql-optimization-patterns
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 LuizEduPP/Rememb --skill sql-optimization-patterns
Clone the repo
git clone --depth 1 https://github.com/LuizEduPP/Rememb

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 sql-optimization-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/luizedupp/rememb/sql-optimization-patterns/github.svg)](https://agentmods.dev/skills/luizedupp/rememb/sql-optimization-patterns)
Your own site
<a href="https://agentmods.dev/skills/luizedupp/rememb/sql-optimization-patterns"><img src="https://agentmods.dev/badge/skills/luizedupp/rememb/sql-optimization-patterns/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 sql-optimization-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/luizedupp/rememb/sql-optimization-patterns"><img src="https://agentmods.dev/badge/skills/luizedupp/rememb/sql-optimization-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 45 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,365 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.00045 $0.03365
Opus 5.5 $0.00018 $0.01346
Sonnet 5.5 $0.00009 $0.00673
Haiku 4.5 $0.00005 $0.00336

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

Security

Grade A, and why

sql-optimization-patterns 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.

src/rememb_skills/sql-optimization-patterns/SKILL.md · 516 lines

How it starts

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

SQL Optimization Patterns

Transform slow database queries into lightning-fast operations through systematic optimization, proper indexing, and query plan analysis.

When to Use

  • Debugging slow-running queries
  • Designing performant database schemas
  • Optimizing application response times
  • Reducing database load and costs
  • Improving scalability for growing datasets
  • Analyzing EXPLAIN query plans
  • Implementing efficient indexes
  • Resolving N+1 query problems

Core Concepts

1. Query Execution Plans (EXPLAIN)

Understanding EXPLAIN output is fundamental to optimization.

PostgreSQL EXPLAIN:

-- Basic explain
EXPLAIN SELECT * FROM users WHERE email = '[email protected]';

-- With actual execution stats
EXPLAIN ANALYZE
SELECT * FROM users WHERE email = '[email protected]';

-- Verbose output with more details
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT u.*, o.order_total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.created_at > NOW() - INTERVAL '30 days';

Key Metrics to Watch:

  • Seq Scan: Full table scan (usually slow for large tables)
  • Index Scan: Using index (good)
  • Index Only Scan: Using index without touching table (best)
  • Nested Loop: Join method (okay for small datasets)
  • Hash Join: Join method (good for larger datasets)
  • Merge Join: Join method (good for sorted data)
  • Cost: Estimated query cost (lower is better)
  • Rows: Estimated rows returned
  • Actual Time: Real execution time

2. Index Strategies

Indexes are the most powerful optimization tool.

Index Types:

  • B-Tree: Default, good for equality and range queries
  • Hash: Only for equality (=) comparisons
  • GIN: Full-text search, array queries, JSONB
  • GiST: Geometric data, full-text search
  • BRIN: Block Range INdex for very large tables with correlation
-- Standard B-Tree index
CREATE INDEX idx_users_email ON users(email);

-- Composite index (order matters!)
CREATE INDEX idx_orders_user_status ON orders(user_id, status);

-- Partial index (index subset of rows)
CREATE INDEX idx_active_users ON users(email)
WHERE status = 'active';

-- Expression index
CREATE INDEX idx_users_lower_email ON users(LOWER(email));

-- Covering index (include additional columns)
CREATE INDEX idx_users_email_covering ON users(email)
INCLUDE (name, created_at);

-- Full-text search index
CREATE INDEX idx_posts_search ON posts
USING GIN(to_tsvector('english', title || ' ' || body));

-- JSONB index
CREATE INDEX idx_metadata ON events USING GIN(metadata);

Read the full file on GitHub · 516 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 · 516 lines · 45 tokens per session scan A 0c6e9dd8fb5c

Subscribe to this mod's changes

sql-optimization-patterns is a skill published in the GitHub repository LuizEduPP/Rememb (5 stars, last pushed 12d ago), licensed MIT. It adds 45 tokens to every session and 3,365 once invoked, about $0.0002 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

release-db-config-sync

Compute the remote DB migration + Nacos config diff before a test release — apc release db-config-sync really spawns sync-test-migrations.ts --dry-run (never a stub) and diffs Nacos key dumps, stopping at the write boundary. green(0) no diff · staged(3) pending migrations/missing keys await approval · blocked(1) real…

Prismer-AI/PrismerCloud · 91 tokens

prismer-airtable

Airtable REST API via curl. Records CRUD, filters, upserts.

Prismer-AI/PrismerCloud · 21 tokens

firebase-cloud-firestore

Use when setting up Firestore, designing schemas, doing CRUD, creating listeners, paginating queries, configuring indexes, enabling offline persistence, or writing security rules.

evanca/flutter-ai-rules · 37 tokens

firebase-database

Use when syncing real-time data, structuring JSON trees, reading/writing, creating listeners, enabling offline persistence, managing presence, sharding, or writing security rules.

evanca/flutter-ai-rules · 38 tokens

firebase-data-connect

Use when setting up Data Connect, writing GraphQL queries/mutations, configuring generated SDKs, handling offline, or applying security rules.

evanca/flutter-ai-rules · 31 tokens

kmd-lint

Health check for a markdown knowledge base (Obsidian-compatible, the LLM-wiki pattern) — personal or shared. Use whenever asked to lint, audit, check, review, or clean up a KB, on any scheduled hygiene/maintenance run, or when KB quality is in doubt (stale pages, contradictions, broken links, unprocessed sources…

yasik/kmd · 102 tokens