Claude Skills
CollectionsCompareWorkflowsNominate
Sign inSign up
© 2026 Curated Agent Skills·Learn more about Agent Skills
Back to repository

sql-quality-fix

verified

Automatically fix SQL performance issues with step-by-step measurement. Rewrites problematic SQL patterns (functions on columns, implicit conversions), creates indexes, measures their impact, and rolls back ineffective indexes. Reports improvements at each step with cost reduction percentages.

View on GitHub

Marketplace

sql-quality

koriym/Koriym.SqlQuality

Plugin

sql-quality

Repository

koriym/Koriym.SqlQuality
3stars

skills/sql-quality-fix/SKILL.md

Last Verified

February 1, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/koriym/Koriym.SqlQuality/blob/main/skills/sql-quality-fix/SKILL.md -a claude-code --skill sql-quality-fix

Installation paths:

Claude
.claude/skills/sql-quality-fix/
Powered by add-skill CLI

Instructions

# SQL Quality Fix

Automatically fix SQL performance issues with step-by-step measurement.

## Arguments
- `$ARGUMENTS`: SQL directory and params file
  - Example: "tests/sql tests/params/sql_params.php"
  - With flag: "tests/sql tests/params/sql_params.php --no-index"

## Options
- `--no-index`: Skip index creation, only suggest DDL

## Steps

### Step 0: Initial Analysis

```bash
php bin/sql-quality analyze \
  --sql-dir="$(echo $ARGUMENTS | cut -d' ' -f1)" \
  --params="$(echo $ARGUMENTS | cut -d' ' -f2)" \
  --format=json
```

Record as baseline.

### Step 1: Fix SQL Files

Apply SQL fixes:

| Issue | Fix |
|-------|-----|
| FullTableScan | Add WHERE with indexed columns |
| FunctionInvalidatesIndex | Rewrite: `YEAR(col)=2024` → `col >= '2024-01-01'` |
| IneffectiveLikePattern | Use prefix match if possible |
| IneffectiveJoin | Reorder JOINs, use explicit syntax |

**Re-analyze and record SQL fix impact.**

### Step 2: Create Indexes (one by one)

For each suggested index:

1. **Create index**
   ```sql
   CREATE INDEX idx_name ON table(columns);
   ```

2. **Re-analyze**

3. **Evaluate impact**
   - Cost improved ≥ 5% → Keep index
   - Cost not improved → Rollback
     ```sql
     DROP INDEX idx_name ON table;
     ```
     Record as "ineffective, rolled back"

### Step 3: Generate Report

Save to `build/sql-quality/fix-result.json`:

```json
{
  "executed_at": "2024-01-15T10:30:00",
  "steps": [
    {
      "step": "initial",
      "total_cost": 650.00
    },
    {
      "step": "sql_fix",
      "total_cost": 450.00,
      "improvement": "-30.8%",
      "changes": [
        {"file": "1_full_table_scan.sql", "change": "Added WHERE user_id = :user_id"}
      ]
    },
    {
      "step": "index",
      "total_cost": 57.30,
      "improvement": "-87.3%",
      "indexes_created": [
        {"ddl": "CREATE INDEX idx_posts_user_id ON posts(user_id)", "impact": "-60%"}
      ],
      "indexes_rolled_back": [
        {"ddl": "CREATE INDEX idx_posts_title ON posts(titl

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
2633 chars