query-optimize

Optimize slow PostgreSQL, MySQL, and SQLite queries with plan analysis and rewrites.

Updated Apr 14, 2026
One-click install
npx skills add https://github.com/bianhaifeng789-hue/openclaw-config --skill query-optimize-bianhaifeng789-hue
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-optimize
Source: https://github.com/bianhaifeng789-hue/openclaw-config/tree/main/skills/tb2/query-optimize
Command: npx skills add https://github.com/bianhaifeng789-hue/openclaw-config --skill query-optimize-bianhaifeng789-hue

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses slow or resource-heavy SQL queries by providing a structured, repeatable process to diagnose performance bottlenecks, propose safer rewrites, and verify both correctness and measurable performance improvements.

Core Features & Use Cases

  • Query plan analysis: Guidance on using EXPLAIN, EXPLAIN ANALYZE, and platform-specific plan inspection to identify full table scans, materialization, and costly join patterns.
  • Optimization techniques: Practical approaches including CTEs, join restructuring, window functions, predicate pushdown, and index recommendations with database-specific cautions for SQLite, PostgreSQL, and MySQL.
  • Verification & benchmarking: Procedures for full-result correctness checks, multi-run timing (cold vs warm cache), and incremental profiling of subqueries or CTEs to validate real gains.
  • Use case: Improve a slow report query that times out during peak hours by reworking correlated subqueries into joins or CTEs, adding covering indexes, and selecting the best-performing rewrite via measured benchmarks.

Quick Start

Analyze the slow query with EXPLAIN/EXPLAIN ANALYZE, identify the primary bottleneck, propose two alternative rewrites with index suggestions, and benchmark each version across multiple runs to confirm correctness and performance.

Frequently Asked Questions about query-optimize

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow SQL queries that are causing full-table scans?

You optimize slow SQL queries by using EXPLAIN ANALYZE to identify full-table scans and costly joins, then applying rewrites like CTEs or window functions and adding covering indexes to reduce execution time and resource consumption.

What is the best way to rewrite correlated subqueries in PostgreSQL for analytics?

The best way to rewrite correlated subqueries in PostgreSQL for analytics is transforming them into joins or CTEs. This restructuring eliminates row-by-row execution overhead, significantly improving report generation speeds during peak transactional workloads.

Does this SQL query optimization approach work with both MySQL and SQLite?

Yes, this SQL query optimization approach works with MySQL and SQLite, providing database-specific cautions for indexing and query rewrites. It applies optimization techniques across all three platforms to improve transactional and analytics workloads.

How do I benchmark SQL query performance after applying optimization techniques?

You benchmark SQL query performance by running multi-run timings comparing cold and warm cache states, profiling incremental subqueries or CTEs, and performing full-result correctness checks. This validates measurable performance gains between original and rewritten queries.

Why does my SQL report query time out during peak hours and how can I fix it?

Your SQL report query times out during peak hours due to inefficient joins or full-table scans. Fix it by restructuring correlated subqueries into joins or CTEs, adding covering indexes, and selecting the best-performing rewrite via measured benchmarks.