Prompt Engineering SQL Execution Plans

Execution Plan Analysis — Read What the Engine Actually Chose

Optimize what the engine does, not what the SQL looks like: cost concentration, estimate-vs-actual gaps, and plan warnings — with forensic evidence rules.

Overview

Query text is the intention; the execution plan is the truth. This prompt uses the plan-analysis goal — work from the actual plan, find the one or two operators where the cost concentrates, compare estimates against actuals (large gaps mean stale statistics or unmodelable predicates, and invalidate downstream choices), and follow row counts between operators, because where rows explode or collapse is where the story is. The forensic mode makes it rigorous: every conclusion cites its operator, missing evidence becomes the exact command to gather it, and generic advice is forbidden. The loaded scenario — a settlement batch that tripled its runtime — starts where plan work usually starts: the plan not yet captured.

Workflow

  1. Capture before concluding

    No plan, no analysis: the first recommendation is the platform's capture command.

  2. Find the concentration

    One or two operators usually own the cost — the rest is noise to ignore.

  3. Trust actuals over estimates

    Where they diverge, fix the statistics story first — downstream choices depend on it.

Why This Works

  • Plan-first discipline optimizes reality instead of appearances
  • Cost concentration prevents effort spent on cheap operators
  • Estimate-vs-actual reading finds why the engine chose wrong, not just that it did

Best for

  • Queries whose text looks innocent and whose runtime is not
  • Batch jobs that degraded gradually over months
  • Engineers learning to read plans instead of guessing

Not for

  • Application-level performance hunting — that's the Debugging Prompt Generator
  • Plan-free quick passes — that's this tool's Fast Review evidence mode

Use cases

  • Setting up a rigorous plan review for a degrading batch job
  • Finding which operator actually owns the runtime
  • Turning missing plan evidence into capture commands

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

Explore all resources