sql-database

Analyze slow SQL queries and generate indexing and migration plans.

16|Updated Apr 30, 2026
One-click install
npx skills add https://github.com/JCETools-Petra/JCE-Opencode-Tools --skill sql-database-jcetools-petra
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-database
Source: https://github.com/JCETools-Petra/JCE-Opencode-Tools/tree/main/config/skills/sql-database
Command: npx skills add https://github.com/JCETools-Petra/JCE-Opencode-Tools --skill sql-database-jcetools-petra

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you design and tune relational databases so SQL queries run faster, migrations stay safe, and data remains consistent as your schema evolves.

Core Features & Use Cases

  • SQL performance and indexing guidance: Choose appropriate B-tree, GIN/trigram, composite, covering, and partial indexes based on real query plans (e.g., Seq Scan, Sort cost, join behavior).
  • Schema design best practices: Model keys and constraints effectively (BIGINT vs INT, TIMESTAMPTZ, foreign keys) and prevent common pitfalls like missing indexes on FKs.
  • Zero-downtime migrations and operational safety: Apply expand–contract strategies, batch backfills, concurrent/non-blocking index creation, and constraint validation workflows.

Quick Start

Use the sql-database skill when you need to analyze why a slow query is running poorly and generate the safest indexing and migration plan to fix it.

Frequently Asked Questions about sql-database

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

FAQPage Schema
How do I optimize slow SQL queries using EXPLAIN ANALYZE?

To optimize slow SQL queries, analyze execution plans from EXPLAIN ANALYZE to identify Seq Scans and high Sort costs, then apply appropriate B-tree, GIN, composite, or partial indexes based on actual join behavior and filter predicates.

What is the expand-contract strategy for zero-downtime migrations?

The expand-contract strategy for zero-downtime migrations deploys backward-compatible schema changes in stages, adding new structures first and removing deprecated ones later, combined with batch backfills and concurrent index creation to avoid locking production tables.

How do I choose the right index type for PostgreSQL or MySQL?

Choosing the right index type for PostgreSQL or MySQL requires evaluating query plans to match specific needs: B-tree for standard range lookups, GIN or trigram indexes for text search, composite indexes for multi-column filters, and covering indexes to avoid heap access.

Does this approach work for designing schemas for production workloads?

Yes, this approach works for designing schemas for production workloads by enforcing best practices like selecting BIGINT vs INT and TIMESTAMPTZ, adding foreign keys, and ensuring missing indexes on FKs are addressed to maintain operational correctness and data consistency.

What's the best way to add constraints without blocking database operations?

The best way to add constraints without blocking database operations is applying constraint validation workflows that create constraints as NOT VALID, backfill data, and then validate them concurrently to maintain operational safety during high-traffic periods.

Why do I need partial indexes and when should I use them?

You need partial indexes to optimize query performance by indexing only rows matching a specific WHERE clause, which reduces index size and maintenance overhead, making them ideal for queries targeting a specific subset of frequently accessed data in large production tables.