Initial commit
This commit is contained in:
15
.claude-plugin/plugin.json
Normal file
15
.claude-plugin/plugin.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sql-query-optimizer",
|
||||
"description": "Analyze and optimize SQL queries for better performance, suggesting indexes, query rewrites, and execution plan improvements",
|
||||
"version": "1.0.0",
|
||||
"author": {
|
||||
"name": "Claude Code Plugins",
|
||||
"email": "[email protected]"
|
||||
},
|
||||
"skills": [
|
||||
"./skills"
|
||||
],
|
||||
"commands": [
|
||||
"./commands"
|
||||
]
|
||||
}
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# sql-query-optimizer
|
||||
|
||||
Analyze and optimize SQL queries for better performance, suggesting indexes, query rewrites, and execution plan improvements
|
||||
79
commands/optimize-query.md
Normal file
79
commands/optimize-query.md
Normal file
@@ -0,0 +1,79 @@
|
||||
---
|
||||
description: Analyze and optimize SQL queries for performance
|
||||
---
|
||||
|
||||
# SQL Query Optimizer
|
||||
|
||||
You are an SQL performance optimization expert. Analyze queries and provide optimization recommendations.
|
||||
|
||||
## Analysis Areas
|
||||
|
||||
1. **Query Structure**
|
||||
- Identify N+1 queries
|
||||
- Check for SELECT *
|
||||
- Analyze JOIN operations
|
||||
- Review subquery usage
|
||||
- Detect cartesian products
|
||||
|
||||
2. **Index Recommendations**
|
||||
- Suggest missing indexes
|
||||
- Identify unused indexes
|
||||
- Composite index opportunities
|
||||
- Covering indexes
|
||||
- Index maintenance
|
||||
|
||||
3. **Execution Plan Analysis**
|
||||
- Sequential vs index scans
|
||||
- Join strategies
|
||||
- Sort operations
|
||||
- Temporary tables
|
||||
- Cost estimation
|
||||
|
||||
4. **Query Rewrite Suggestions**
|
||||
- Convert subqueries to JOINs
|
||||
- Use EXISTS vs IN
|
||||
- Optimize WHERE clauses
|
||||
- Reduce column selections
|
||||
- Partition pruning
|
||||
|
||||
## Optimization Checklist
|
||||
|
||||
- **Avoid SELECT ***: Specify only needed columns
|
||||
- **Use EXPLAIN**: Always analyze execution plans
|
||||
- **Index WHERE/JOIN columns**: Speed up filtering and joins
|
||||
- **Limit result sets**: Use LIMIT/TOP appropriately
|
||||
- **Avoid functions on indexed columns**: Breaks index usage
|
||||
- **Use appropriate JOIN types**: INNER vs LEFT vs RIGHT
|
||||
- **Batch operations**: Reduce round trips
|
||||
- **Use connection pooling**: Reuse connections
|
||||
|
||||
## Output Format
|
||||
|
||||
For each query provide:
|
||||
1. **Current Issues**: What's slow and why
|
||||
2. **Optimized Query**: Rewritten version
|
||||
3. **Index Recommendations**: CREATE INDEX statements
|
||||
4. **Performance Impact**: Expected improvement
|
||||
5. **Testing Strategy**: How to verify improvements
|
||||
|
||||
## Example
|
||||
|
||||
**Original Query:**
|
||||
```sql
|
||||
SELECT * FROM orders o
|
||||
WHERE o.user_id IN (SELECT id FROM users WHERE created_at > '2024-01-01');
|
||||
```
|
||||
|
||||
**Optimized Query:**
|
||||
```sql
|
||||
SELECT o.id, o.user_id, o.total, o.created_at
|
||||
FROM orders o
|
||||
INNER JOIN users u ON o.user_id = u.id
|
||||
WHERE u.created_at > '2024-01-01';
|
||||
```
|
||||
|
||||
**Index Recommendation:**
|
||||
```sql
|
||||
CREATE INDEX idx_users_created_at ON users(created_at);
|
||||
CREATE INDEX idx_orders_user_id ON orders(user_id);
|
||||
```
|
||||
61
plugin.lock.json
Normal file
61
plugin.lock.json
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"$schema": "internal://schemas/plugin.lock.v1.json",
|
||||
"pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/database/sql-query-optimizer",
|
||||
"normalized": {
|
||||
"repo": null,
|
||||
"ref": "refs/tags/v20251128.0",
|
||||
"commit": "fbd4043b4606dfc13589347ba76a2c37579e94a0",
|
||||
"treeHash": "95b4a1323fe42422405c7e9ff1fc7123fecf5cb6fc1f20160d6fa4f6f7023dde",
|
||||
"generatedAt": "2025-11-28T10:18:47.116569Z",
|
||||
"toolVersion": "publish_plugins.py@0.2.0"
|
||||
},
|
||||
"origin": {
|
||||
"remote": "git@github.com:zhongweili/42plugin-data.git",
|
||||
"branch": "master",
|
||||
"commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390",
|
||||
"repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data"
|
||||
},
|
||||
"manifest": {
|
||||
"name": "sql-query-optimizer",
|
||||
"description": "Analyze and optimize SQL queries for better performance, suggesting indexes, query rewrites, and execution plan improvements",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"content": {
|
||||
"files": [
|
||||
{
|
||||
"path": "README.md",
|
||||
"sha256": "8ef937a6a85b9f2a9b2bc1cf1ce134c53a49efacfefffa1690d6f27f4d214034"
|
||||
},
|
||||
{
|
||||
"path": ".claude-plugin/plugin.json",
|
||||
"sha256": "df7c7411160089fefbe061a30eb5c54110df8f5049a9f0654fc82314ae747ca6"
|
||||
},
|
||||
{
|
||||
"path": "commands/optimize-query.md",
|
||||
"sha256": "f8af8c9e41c0c9c9cbff6b1e20cd2ef11d5906881578a453831997a83f28bfad"
|
||||
},
|
||||
{
|
||||
"path": "skills/sql-query-optimizer/SKILL.md",
|
||||
"sha256": "df476aa438c7691f2b46c27c964433d91b9140f2be9693d7558ae43aa8297e1a"
|
||||
},
|
||||
{
|
||||
"path": "skills/sql-query-optimizer/references/README.md",
|
||||
"sha256": "3d3f8972ae6ee60ca6c9ed385860cc1c59b1e2e777d2fb67fcf0a03ffccca561"
|
||||
},
|
||||
{
|
||||
"path": "skills/sql-query-optimizer/scripts/README.md",
|
||||
"sha256": "0e7344019abb8dc9e84f4d792e3e5247b66811900f028b9433447ddc4c69e4ba"
|
||||
},
|
||||
{
|
||||
"path": "skills/sql-query-optimizer/assets/README.md",
|
||||
"sha256": "3b06c4bd672009bf5abd3ebbbdd8112e743dea6469e1ba43ce1d601c7edf1adc"
|
||||
}
|
||||
],
|
||||
"dirSha256": "95b4a1323fe42422405c7e9ff1fc7123fecf5cb6fc1f20160d6fa4f6f7023dde"
|
||||
},
|
||||
"security": {
|
||||
"scannedAt": null,
|
||||
"scannerVersion": null,
|
||||
"flags": []
|
||||
}
|
||||
}
|
||||
52
skills/sql-query-optimizer/SKILL.md
Normal file
52
skills/sql-query-optimizer/SKILL.md
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: optimizing-sql-queries
|
||||
description: |
|
||||
This skill analyzes and optimizes SQL queries for improved performance. It identifies potential bottlenecks, suggests optimal indexes, and proposes query rewrites. Use this when the user mentions "optimize SQL query", "improve SQL performance", "SQL query optimization", "slow SQL query", or asks for help with "SQL indexing". The skill helps enhance database efficiency by analyzing query structure, recommending indexes, and reviewing execution plans.
|
||||
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
|
||||
version: 1.0.0
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
This skill empowers Claude to analyze SQL queries, identify performance bottlenecks, and suggest optimizations such as index creation or query rewriting. It leverages the sql-query-optimizer plugin to provide actionable recommendations for improving database performance.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Query Input**: The user provides an SQL query to be optimized.
|
||||
2. **Analysis**: The plugin analyzes the query structure, potential indexing issues, and execution plan (if available).
|
||||
3. **Recommendations**: The plugin generates optimization suggestions, including index recommendations and query rewrites.
|
||||
|
||||
## When to Use This Skill
|
||||
|
||||
This skill activates when you need to:
|
||||
- Optimize a slow-running SQL query.
|
||||
- Identify missing or unused indexes in a database.
|
||||
- Improve the performance of a database application.
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Optimizing a Slow Query
|
||||
|
||||
User request: "Optimize this SQL query: SELECT * FROM orders WHERE customer_id = 123 AND order_date < '2023-01-01';"
|
||||
|
||||
The skill will:
|
||||
1. Analyze the provided SQL query.
|
||||
2. Suggest creating an index on customer_id and order_date columns to improve query performance.
|
||||
|
||||
### Example 2: Finding Indexing Opportunities
|
||||
|
||||
User request: "I need help optimizing a query that filters on product_category and price. Can you suggest any indexes?"
|
||||
|
||||
The skill will:
|
||||
1. Analyze a hypothetical query based on the user's description.
|
||||
2. Recommend a composite index on (product_category, price) to speed up filtering.
|
||||
|
||||
## Best Practices
|
||||
|
||||
- **Provide Full Queries**: Include the complete SQL query for accurate analysis.
|
||||
- **Include EXPLAIN Output**: Providing the output of `EXPLAIN` can help the optimizer identify bottlenecks more effectively.
|
||||
- **Test Recommendations**: Always test the suggested optimizations in a staging environment before applying them to production.
|
||||
|
||||
## Integration
|
||||
|
||||
This skill can be used in conjunction with other database management plugins to automate index creation and query rewriting based on the optimizer's suggestions.
|
||||
6
skills/sql-query-optimizer/assets/README.md
Normal file
6
skills/sql-query-optimizer/assets/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Assets
|
||||
|
||||
Bundled resources for sql-query-optimizer skill
|
||||
|
||||
- [ ] example_queries.sql: A collection of example SQL queries for testing and demonstration.
|
||||
- [ ] query_optimization_report_template.md: A template for generating query optimization reports.
|
||||
10
skills/sql-query-optimizer/references/README.md
Normal file
10
skills/sql-query-optimizer/references/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# References
|
||||
|
||||
Bundled resources for sql-query-optimizer skill
|
||||
|
||||
- [ ] sql_optimization_best_practices.md: A comprehensive guide to SQL optimization best practices.
|
||||
- [ ] postgresql_indexing.md: Detailed information on PostgreSQL indexing strategies.
|
||||
- [ ] mysql_indexing.md: Detailed information on MySQL indexing strategies.
|
||||
- [ ] sqlite_indexing.md: Detailed information on SQLite indexing strategies.
|
||||
- [ ] sql_execution_plan_analysis.md: A guide to analyzing SQL execution plans.
|
||||
- [ ] common_sql_anti_patterns.md: A list of common SQL anti-patterns and how to avoid them.
|
||||
8
skills/sql-query-optimizer/scripts/README.md
Normal file
8
skills/sql-query-optimizer/scripts/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Scripts
|
||||
|
||||
Bundled resources for sql-query-optimizer skill
|
||||
|
||||
- [ ] analyze_query.py: Analyzes the SQL query and identifies potential bottlenecks.
|
||||
- [ ] recommend_indexes.py: Suggests optimal indexes for the given query.
|
||||
- [ ] rewrite_query.py: Proposes optimized query rewrites.
|
||||
- [ ] explain_query.sh: Executes the EXPLAIN command and formats the output for analysis.
|
||||
Reference in New Issue
Block a user