indexing-query-optimization

Design indexes and query changes validated by EXPLAIN (ANALYZE, BUFFERS) plans.

4|Updated May 16, 2026
One-click install
npx skills add https://github.com/machenjie/rd-skills --skill indexing-query-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: indexing-query-optimization
Source: https://github.com/machenjie/rd-skills/tree/main/src/foundation/capabilities/indexing-query-optimization
Command: npx skills add https://github.com/machenjie/rd-skills --skill indexing-query-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents slow or risky database changes by replacing blind index addition with index designs driven by actual predicates, sort requirements, cardinality, and execution plan evidence.

Core Features & Use Cases

  • Named-Query-First Index Design: Forces every index to be tied to a specific beneficiary query so usefulness can be validated.
  • Execution Plan Validation (Before/After): Requires representative EXPLAIN (ANALYZE, BUFFERS) evidence to confirm plan changes and real-row behavior.
  • Write- and Migration-Safe Guardrails: Calculates write amplification, mandates online build strategy for large tables, and blocks unsafe pagination patterns on big datasets.

Quick Start

Ask for an indexing-query-optimization plan that names the target SQL query, lists its predicates and ORDER BY, and proposes only the minimal composite/covering indexes validated by EXPLAIN (ANALYZE, BUFFERS) before and after.

Frequently Asked Questions about indexing-query-optimization

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

FAQPage Schema
How do I design composite indexes based on real query execution plans?

Design composite indexes by extracting actual predicates, sort requirements, and cardinality signals from EXPLAIN (ANALYZE, BUFFERS) output. This approach ties every index to a named beneficiary query and validates plan changes using before-and-after execution evidence.

What is the best way to optimize database pagination on large tables?

The best way to optimize database pagination on large tables is to abandon unsafe offset-based patterns and adopt safe pagination strategies guided by write-cost constraints. This prevents latency regressions caused by deep offset scans on massive datasets.

How do I estimate write amplification before adding a new database index?

Estimate write amplification by calculating the additional write operations required for each new index alongside existing ones. This analysis acts as a mandatory guardrail to prevent performance degradation in high-throughput database environments.

When do I need an online index build strategy for database migrations?

You need an online index build strategy for database migrations when modifying large tables to prevent locking and downtime. This mandatory guardrail ensures schema changes maintain production database availability during index construction.

Why does adding an index not improve my ORM query performance?

Adding an index may not improve ORM query performance if the index design ignores actual ORM query patterns and execution plans. Effective optimization requires validating proposed indexes against before-and-after EXPLAIN (ANALYZE, BUFFERS) evidence.