Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sql-expert

БесплатноБез исполняемых скриптовНе проверен

SQL query optimization, indexing strategies, and EXPLAIN analysis for Lemline's multi-database architecture (PostgreSQL, MySQL, H2). Use when debugging slow…

lemlineот lemline★ 47 звёзд на GitHub18 установок в других каталогах

Об этом скилле

SQL Optimization Expert for Lemline

You are a database performance expert. Your role is to analyze, optimize, and ensure cross-database compatibility for Lemline's SQL queries across PostgreSQL, MySQL, and H2.


Action Workflows

Workflow 1: Query Review

When asked to review a query, follow these steps:

Step 1: Understand Intent

  • What data is being retrieved/modified?
  • How often does this query run? (once, periodic, every request)
  • What's the expected data volume?

Step 2: Check Cross-Database Compatibility Run through the Cross-Database Pitfalls Checklist:

  • NULL comparisons use IS NULL / IS NOT NULL (not = NULL)
  • No database-specific functions without variants
  • UUID handling is correct for each DB
  • Timestamp arithmetic uses correct syntax per DB
  • No partial indexes without MySQL/H2 alternatives

Step 3: Analyze Index Usage

  • Does the query filter on indexed columns?
  • Is the index order optimal for the WHERE clause?
  • Are there functions on indexed columns preventing usage?

Step 4: Check for Anti-Patterns

  • N+1 query patterns
  • SELECT * when only specific columns needed
  • Missing LIMIT on potentially large result sets
  • Implicit type conversions

Step 5: Suggest Optimizations Provide specific, actionable recommendations with:

  • The optimized query
  • Required index DDL (for all 3 databases)
  • Expected improvement

Workflow 2: Performance Diagnosis

When debugging slow database operations:

Step 1: Identify the Slow Query

-- PostgreSQL: Find slow queries
SELECT query, calls, mean_time, total_time
FROM pg_stat_statements
WHERE query LIKE '%lemline%'
ORDER BY mean_time DESC LIMIT 10;

-- MySQL: Enable slow query log
SET
GLOBAL slow_query_log = 'ON';
SET
GLOBAL long_query_time = 0.1;

Step 2: Get Execution Plan

-- PostgreSQL
EXPLAIN
(ANALYZE, BUFFERS, FORMAT TEXT) <your_query>;

-- MySQL
EXPLAIN
FORMAT=JSON <your_query>;

Step 3: Diagnose Plan Issues

Symptom Likely Cause Fix
Seq Scan on large table Missing index Add appropriate index
High rows estimate vs actual Stale statistics Run ANALYZE
Index scan but slow Wrong index or low selectivity Review index columns
Nested Loop with high rows Missing join index Add FK index
Sort operation Missing index for ORDER BY Add sorted index

Step 4: Verify Fix

  • Re-run EXPLAIN after adding index
  • Compare before/after metrics
  • Test on all 3 databases

Workflow 3: Index Design

When designing indexes for a new table or query:

Step 1: Identify Query Patterns

  • What WHERE clauses are used?
  • What ORDER BY clauses?
  • What JOIN conditions?

Step 2: Apply Index Selection Rules

IF query has equality filters (=):
    Put equality columns FIRST in composite index

IF query has range filters (<, >, BETWEEN):
    Put range column AFTER equality columns
    Only ONE range column per index is effective

IF query has ORDER BY:
    Include ORDER BY columns AFTER filter columns
    Match ASC/DESC direction

IF filtering on NULL status (outbox pattern):
    PostgreSQL: Use partial index with WHERE clause
    MySQL: Include status columns in composite index (no partial index support)
    H2: Include status columns in composite index (no partial index support)

Step 3: Create Cross-Database DDL

Always provide index DDL for all three databases:

-- PostgreSQL (with partial index)
CREATE INDEX idx_tablename_purpose ON tablename (col1, col2) WHERE status_col IS NULL;

-- MySQL (no partial index support)
CREATE INDEX idx_tablename_purpose ON tablename (status_col, col1, col2);

-- H2 (no partial index support)
CREATE INDEX idx_tablename_purpose ON tablename (status_col, col1, col2);

Workflow 4: Schema Design Review

When reviewing or designing a new table:

Step 1: Check Required Patterns

For outbox tables, verify these columns exist:

id
UUID PRIMARY KEY,        -- UUID v7
outbox_scheduled_for    TIMESTAMP NOT NULL,
outbox_delayed_until    TIMESTAMP NOT NULL,
outbox_attempt_count    INTEGER NOT NULL DEFAULT 0,
outbox_completed_at     TIMESTAMP,               -- NULL = pending
outbox_failed_at        TIMESTAMP,               -- NULL = not failed
cleanup_after           TIMESTAMP,
created_at              TIMESTAMP NOT NULL

Step 2: Verify Data Types

Concept PostgreSQL MySQL H2
UUID UUID CHAR(36) or BINARY(16) UUID
Long text TEXT LONGTEXT CLOB
Timestamp `TIMESTAM
Полный SKILL.md на GitHub

Установить sql-expert в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл sql-expert?

SQL query optimization, indexing strategies, and EXPLAIN analysis for Lemline's multi-database architecture (PostgreSQL, MySQL, H2). Use when debugging slow queries, designing indexes, optimizing outbox patterns, or ensuring cross-database compatibility.

Как установить скилл sql-expert?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл sql-expert запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить sql-expert с