SQL 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ộc src/infra/.
--query=<sql>: Query cần phân tích; chỉ dùng dialect-specific analysis khi DB đã approved.
--mode=audit|fix|index: audit phân tích, fix tạo recommendation, index thiết kế index theo DB approved.
Architecture Profile gate
- Đọc Architecture Profile, Constitution, CLAUDE và constraints.
- Xác minh DB, ORM/query layer, migration mechanism và test command đã
APPROVED cù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
IN query 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.md và 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.
1---2name: sql-performance-tuner3description: Audit hiệu năng persistence adapter theo Architecture Profile, gồm N+1, index/query-plan gap và layer violation4---56# SQL Performance Tuner (`/sql-performance-tuner`)78Audit 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.910## Tham số1112- `--file=<path>`: Persistence adapter cần audit, phải thuộc `src/infra/`.13- `--query=<sql>`: Query cần phân tích; chỉ dùng dialect-specific analysis khi DB đã approved.14- `--mode=audit|fix|index`: `audit` phân tích, `fix` tạo recommendation, `index` thiết kế index theo DB approved.1516## Architecture Profile gate17181. Đọc Architecture Profile, Constitution, CLAUDE và constraints.192. Xác minh DB, ORM/query layer, migration mechanism và test command đã `APPROVED` cùng evidence.203. 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.214. Binding đã chọn thì chỉ dùng syntax/API/command của binding đó.2223## Checklist2425- Không có DB client/query builder/ORM import ngoài `src/infra/`; usecase chỉ phụ thuộc port.26- Không có database call trong loop khi selected adapter có batch loading, join, relation loading hoặc `IN` query phù hợp.27- 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.md` và persistence binding đã xác định.28- Không `SELECT *` nếu usecase cần ít field; parameterize input; transaction scope nhỏ; lock order nhất quán.29- Production index/schema change cần safety constraint, rollback plan và Human Final Review.3031## Output3233```text34PERSISTENCE PERFORMANCE AUDIT REPORT35Feature: {slug} | Profile: v{version} | Binding: {approved database + ORM/query layer}3637LAYER VIOLATION:38 [ARCH-01] {path}:{line} — {DB access outside src/infra}39CRITICAL:40 [N+1|INDEX|LOCK] {path}:{line} — {evidence and impact}41WARNING:42 [QUERY|PAGINATION|PROJECTION] {path}:{line} — {finding}43CONFIGURATION GAP:44 {unselected binding; no adapter-specific remediation generated}45REMEDIATION:46 - Binding: {approved binding}47 - Change: {profile-compatible action}48 - Verification: {exact approved command or N/A with reason}49 - Spec/Plan impact: {artifact or N/A with reason}50```5152Nế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.