Optimizing Sql Queries
by jeremylongshore
|
Skill Details
Repository Files
1 file in this skill directory
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.
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
- Query Input: The user provides an SQL query to be optimized.
- Analysis: The plugin analyzes the query structure, potential indexing issues, and execution plan (if available).
- 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:
- Analyze the provided SQL query.
- 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:
- Analyze a hypothetical query based on the user's description.
- 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
EXPLAINcan 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.
Related Skills
Attack Tree Construction
Build comprehensive attack trees to visualize threat paths. Use when mapping attack scenarios, identifying defense gaps, or communicating security risks to stakeholders.
Grafana Dashboards
Create and manage production Grafana dashboards for real-time visualization of system and application metrics. Use when building monitoring dashboards, visualizing metrics, or creating operational observability interfaces.
Matplotlib
Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.
Scientific Visualization
Create publication figures with matplotlib/seaborn/plotly. Multi-panel layouts, error bars, significance markers, colorblind-safe, export PDF/EPS/TIFF, for journal-ready scientific plots.
Seaborn
Statistical visualization. Scatter, box, violin, heatmaps, pair plots, regression, correlation matrices, KDE, faceted plots, for exploratory analysis and publication figures.
Shap
Model interpretability and explainability using SHAP (SHapley Additive exPlanations). Use this skill when explaining machine learning model predictions, computing feature importance, generating SHAP plots (waterfall, beeswarm, bar, scatter, force, heatmap), debugging models, analyzing model bias or fairness, comparing models, or implementing explainable AI. Works with tree-based models (XGBoost, LightGBM, Random Forest), deep learning (TensorFlow, PyTorch), linear models, and any black-box model
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Query Writing
For writing and executing SQL queries - from simple single-table queries to complex multi-table JOINs and aggregations
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Scientific Visualization
Meta-skill for publication-ready figures. Use when creating journal submission figures requiring multi-panel layouts, significance annotations, error bars, colorblind-safe palettes, and specific journal formatting (Nature, Science, Cell). Orchestrates matplotlib/seaborn/plotly with publication styles. For quick exploration use seaborn or plotly directly.
