Help us improve
Share bugs, ideas, or general feedback.
From grimoire
Writes, reviews, and optimizes SQL queries for correctness, performance, and maintainability. Includes SARGable predicates, execution plan analysis, and anti-pattern prevention.
npx claudepluginhub jeffreytse/grimoire --plugin grimoireHow this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:write-sql-queryThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Write SQL queries that are correct, index-aware, readable, and safe against injection and unintended side effects.
Optimizes SQL queries, designs database schemas, and troubleshoots performance issues. Covers window functions, CTEs, indexing strategies, EXPLAIN ANALYZE interpretation, and query migration across PostgreSQL, MySQL, and SQL Server.
Optimizes SQL queries, designs schemas, and troubleshoots performance issues using window functions, CTEs, indexing, and EXPLAIN plan analysis. Supports PostgreSQL, MySQL, SQL Server, and Oracle.
Optimizes slow SQL queries using systematic patterns, proper indexing, EXPLAIN plan analysis, and N+1 fixes. Useful for debugging performance, schema design, reducing DB load, and improving scalability.
Share bugs, ideas, or general feedback.
Write SQL queries that are correct, index-aware, readable, and safe against injection and unintended side effects.
Adopted by: PostgreSQL community (Use The Index, Luke), Google (BigQuery SQL style guide), GitLab (SQL query guidelines in engineering handbook) Impact: A missing index on a WHERE clause column can cause full table scans — a 10ms query becomes 10 seconds on a 10M row table. Celko's patterns and index-aware SQL are the standard in performance-critical data engineering.
Most SQL performance problems have the same root cause: the query does not use an available index, or no appropriate index exists. Writing index-aware SQL from the start costs nothing; retroactively optimizing a slow query in production is expensive and disruptive.
EXPLAIN ANALYZE (Postgres), EXPLAIN FORMAT=JSON (MySQL), or EXPLAIN PLAN (Oracle) before assuming it is efficient.WHERE YEAR(created_at) = 2026 → not SARGable; WHERE created_at >= '2026-01-01' → SARGable).SELECT * in production queries; enumerate columns. Reduces I/O, prevents index-only scan breakage, and avoids surprises when schema changes.WITH ... AS (...)) for readability; modern optimizers inline CTEs efficiently (Postgres 12+, BigQuery).LIMIT 1 guard in development to prevent accidents.SELECT DISTINCT as a band-aid — it usually signals a missing JOIN condition or a data model problem.Non-SARGable (bad):
SELECT * FROM orders WHERE DATE(created_at) = '2026-03-01';
-- Function on column prevents index use
SARGable (good):
SELECT order_id, total, status
FROM orders
WHERE created_at >= '2026-03-01' AND created_at < '2026-03-02';
-- Range scan on index; only needed columns selected
SELECT * in production — fetches unused columns, breaks index-only scans, causes hidden bugs when columns are added/dropped.WHERE user_id = '42' when user_id is integer triggers type cast on every row, preventing index use.