Prompt Engineering SQL Indexes

Missing Index Analysis — Which Indexes, at What Cost

Map every predicate, join, and sort to the index that serves it — or doesn't. Composite order rules, covering decisions, and the write tax nobody mentions.

Overview

Missing-index analysis goes wrong in both directions: indexes that were never needed, and indexes designed with the wrong column order that never get used. This prompt uses the index strategy goal: map every predicate, join column, and sort to the index (or absence) that serves it; design composites by the rules — equality columns first, then ranges, then order-by, because column order decides usability; consider covering with its storage and maintenance price; and count the cost honestly — every index taxes every write, and an index serving one slow report may not be worth slowing every insert. With no index list provided, the contract refuses to assume: checking what exists is step one.

Workflow

  1. Check what exists first

    No assumed indexes: the current state is evidence to gather, and near-miss indexes may just need extending.

  2. Map clauses to indexes

    Every predicate, join, and sort accounted for — no index without a clause it serves.

  3. Pay the write tax knowingly

    Each candidate states which inserts and updates it slows — and whether the workload affords it.

Why This Works

  • Clause mapping replaces index folklore with checkable claims
  • Composite order rules prevent the index that exists but never gets used
  • Write-tax honesty separates index strategy from index hoarding

Best for

  • Endpoints slow under load with unverified index suspicions
  • Tables that accumulated overlapping indexes over years
  • Write-heavy workloads where index costs are real

Not for

  • Reading an existing plan's index choices — that's the Execution Plan Analysis goal
  • Schema redesign — the contract's non-goals rule it out of scope

Use cases

  • Working out which indexes a slow lookup workload is missing
  • Ordering composite index columns correctly
  • Deciding whether a covering index is worth its maintenance

Tip: Save time by exploring related resources and tools that integrate with this workflow.

Explore all resources