From data-engineer
Analyze and optimize SQL queries — identify performance issues, suggest rewrites, and explain execution plans
npx claudepluginhub silviaare95/xari-plugins --plugin data-engineerThis skill uses the workspace's default tool permissions.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Designs, audits, and improves analytics tracking systems using Signal Quality Index for reliable, decision-ready data in marketing, product, and growth.
Enforces A/B test setup with gates for hypothesis locking, metrics definition, sample size calculation, assumptions checks, and execution readiness before implementation.
Optimize the SQL for: $ARGUMENTS
Parse the query — Read the SQL and understand:
Identify performance issues:
| Issue | Symptom | Fix |
|---|---|---|
| Full table scan | No WHERE clause index match | Add index or rewrite filter |
| SELECT * | Fetching unused columns | Select only needed columns |
| Correlated subquery | Subquery runs per row | Rewrite as JOIN or CTE |
| Implicit type cast | Filter on wrong type | Cast explicitly or fix schema |
| Missing JOIN index | Slow JOIN on unindexed column | Add index on join column |
| Unnecessary DISTINCT | Masking a join issue | Fix the join instead |
| ORDER BY + LIMIT without index | Sort on full result set | Add composite index |
| N+1 in application | Multiple queries in loop | Use JOIN or IN clause |
Rewrite the query — Produce an optimized version with:
Suggest schema changes if needed:
Estimate impact — Qualitative assessment:
## Query Analysis
### Original Query
```sql
<original>
<rewritten query with comments>
CREATE INDEX idx_name ON table (col1, col2);
## Constraints
- Preserve query semantics — the optimized query must return the same results
- Prefer readability over micro-optimization — CTEs over nested subqueries
- Consider write impact of new indexes (don't index write-heavy tables recklessly)
- Be dialect-aware: Postgres, MySQL, and BigQuery have different optimization strategies
- Don't suggest changes that require application-level rewrites unless the SQL alone can't fix it