Query Optimizer

by openclaw

skill

Optimize SQL and Prisma queries using AI. Use when your queries are slow and you need performance help.

Skill Details

Repository Files

8 files in this skill directory


name: query-optimizer description: Optimize SQL and Prisma queries using AI. Use when your queries are slow and you need performance help.

Query Optimizer

Slow queries killing your app? Paste your SQL or Prisma code and get optimization suggestions. Index recommendations, query rewrites, N+1 detection. The stuff that takes hours to figure out manually.

One command. Zero config. Just works.

Quick Start

npx ai-query-optimize "SELECT * FROM users WHERE email LIKE '%@gmail.com'"

What It Does

  • Analyzes SQL and Prisma queries for performance issues
  • Suggests missing indexes with CREATE INDEX statements
  • Rewrites queries to avoid common antipatterns
  • Detects N+1 problems in ORM code
  • Explains why changes improve performance

Usage Examples

# Optimize a SQL query
npx ai-query-optimize "SELECT * FROM orders WHERE created_at > NOW() - INTERVAL '30 days'"

# Analyze a Prisma query file
npx ai-query-optimize queries.ts

# Check for N+1 issues
npx ai-query-optimize src/api/users.ts --check-n-plus-one

# Get index recommendations
npx ai-query-optimize schema.sql --suggest-indexes

Best Practices

  • Include your schema - Context about tables and existing indexes helps a lot
  • Measure before and after - EXPLAIN ANALYZE doesn't lie
  • Test with real data - Optimizations that work on 100 rows might fail on 1M
  • Don't optimize prematurely - Fix actual slow queries, not theoretical ones

When to Use This

  • Database queries are showing up in your APM as slow
  • Users are complaining about loading times
  • You inherited a codebase with questionable query patterns
  • Learning SQL optimization and want to understand the patterns

Part of the LXGIC Dev Toolkit

This is one of 110+ free developer tools built by LXGIC Studios. No paywalls, no sign-ups, no API keys on free tiers. Just tools that work.

Find more:

Requirements

No install needed. Just run with npx. Node.js 18+ recommended. Requires OPENAI_API_KEY environment variable.

export OPENAI_API_KEY=sk-...
npx ai-query-optimize --help

How It Works

Parses your query or code file to understand the data access patterns. Applies database optimization knowledge to identify issues like missing indexes, expensive operations (LIKE with leading wildcards), and ORM antipatterns. Provides specific, actionable fixes.

License

MIT. Free forever. Use it however you want.

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.

skill

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.

skill

Matplotlib

Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.

skill

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.

skill

Seaborn

Statistical visualization. Scatter, box, violin, heatmaps, pair plots, regression, correlation matrices, KDE, faceted plots, for exploratory analysis and publication figures.

skill

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

skill

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.

skill

Query Writing

For writing and executing SQL queries - from simple single-table queries to complex multi-table JOINs and aggregations

skill

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.

skill

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.

skill

Skill Information

Category:Skill
Last Updated:1/28/2026