sql-performance-tuner
Audit hiệu năng persistence adapter theo Architecture Profile, gồm N+1, index/query-plan gap và layer violation
SKILL.md.claude/skills/sql-performance-tuner/SKILL.md
GitHubSQL Performance Tuner (/sql-performance-tuner)
Audit persistence performance cho TypeScript + Node.js + Clean Architecture. Chỉ src/infra/ được truy cập DB; DB/ORM call trong domain, usecase hoặc interface là ARCH-01 violation.
Tham số
--file=<path>: Persistence adapter cần audit, phải thuộcsrc/infra/.--query=<sql>: Query cần phân tích; chỉ dùng dialect-specific analysis khi DB đã approved.--mode=audit|fix|index:auditphân tích,fixtạo recommendation,indexđề xuất thiết kế index theo DB approved. Cả ba mode đều là read-only proposal; không ghi SQL, migration hay schema.
Architecture Profile gate
- Đọc Architecture Profile, Constitution, CLAUDE và constraints.
- Xác minh DB, ORM/query layer, migration mechanism và test command đã
APPROVEDcùng evidence. - DB/ORM chưa chọn thì chỉ audit layer boundary và báo
CONFIGURATION GAP; không sinh SQL dialect, index syntax, migration, ORM method, package name hoặc command suy đoán. - Binding đã chọn thì chỉ dùng syntax/API/command của binding đó.
Checklist
- Không có DB client/query builder/ORM import ngoài
src/infra/; usecase chỉ phụ thuộc port. - Không có database call trong loop khi selected adapter có batch loading, join, relation loading hoặc
INquery phù hợp. - Chỉ review query plan, index, filter, join, sort, pagination, deletion/soft-delete strategy và migration sau khi DB binding được chọn; soft-delete chỉ áp dụng khi
SPEC.mdvà persistence binding đã xác định. - Không
SELECT *nếu usecase cần ít field; parameterize input; transaction scope nhỏ; lock order nhất quán. - Production index/schema change cần safety constraint, rollback plan và Human Final Review.
Output
PERSISTENCE PERFORMANCE AUDIT REPORT
Feature: {slug} | Profile: v{version} | Binding: {approved database + ORM/query layer}
LAYER VIOLATION:
[ARCH-01] {path}:{line} — {DB access outside src/infra}
CRITICAL:
[N+1|INDEX|LOCK] {path}:{line} — {evidence and impact}
WARNING:
[QUERY|PAGINATION|PROJECTION] {path}:{line} — {finding}
CONFIGURATION GAP:
{unselected binding; no adapter-specific remediation generated}
REMEDIATION:
- Binding: {approved binding}
- Change: {profile-compatible action}
- Verification: {exact approved command or N/A with reason}
- Spec/Plan impact: {artifact or N/A with reason}
Nếu performance change đổi data contract, consistency, SLA hoặc schema behavior, cập nhật SPEC.md/PLAN.md trước code. Dùng /sdd-review cho profile/schema decision trước execution.
Hướng dẫn sử dụng
- Khi dùng: Audit persistence performance trong
src/infra/và tạo proposal fix/index theo binding đã approved. - Không dùng:
fixvàindexvẫn là read-only proposal; không emit SQL/index/migration/ORM call khi DB binding chưa chọn, không ghi schema ngoài/add-executeboundary. - Input:
--filephải thuộcsrc/infra/; optional--queryvà--mode=audit|fix|index; reject dialect-specific analysis without approved DB. - Điều kiện trước: DB, ORM/query layer, migration mechanism và exact command đã
APPROVEDcó evidence; target file nằm trongsrc/infra/. - Evidence:
PERSISTENCE PERFORMANCE AUDIT REPORT, query-plan/index evidence, exact verification result hoặcN/Areason, recommendation pending. - Dừng khi:
ARCH-01layer violation, configuration gap, production index/schema change thiếu rollback + Human Final Review, hoặc data-contract impact chưa có Spec decision. - Human quyết định: Human duyệt schema/index/migration và profile decision; write chỉ xảy ra qua task
/add-executeđã approved. - Lệnh tiếp theo:
/sdd-review --target=<audit report> --status=<APPROVED|REVISE|REJECTED> ...;/sdd-update --feature=<slug> --artifact=spec --bump=... --reason="..."khi đổi data contract/SLA/schema behavior. - Ví dụ:
/sql-performance-tuner --file=src/infra/persistence/order-repository.ts --mode=auditbáo N+1 mà không viết query mới.
Completion output
Dùng Completion output contract sau PERSISTENCE PERFORMANCE AUDIT REPORT. Nêu audited infra scope, approved DB/ORM binding, query-plan/index evidence, verification result và Spec/Plan impact. Kết quả audit sạch không có action scope mới chọn continue với action không-command: giữ evidence và chỉ theo persisted feature/delivery Follow-up hiện có. Data contract, SLA, schema hoặc migration change là Human decision required để update/review relevant artifact/profile; CONFIGURATION GAP, ARCH-01 hoặc unresolved CRITICAL là BLOCKED. Không emit SQL/index/migration/ORM command khi binding chưa approved.