Prompt Engineering SQL Performance

Slow Query Investigation — Degrading Month Over Month

Queries that were instant at launch and crawl a year later: scale-aware investigation of work that grows faster than the data, before it owns the server.

Overview

Some queries do not have a bug — they have a trajectory. This prompt uses the scaling goal on the classic case: dashboard queries degrading every month as data grows. The priorities target growth itself: reason at the scale every conclusion assumes (fine at 100K rows can own the server at 100M), identify work that grows faster than the data — join shapes that multiply, sorts that will spill, aggregates over ever-growing history — bound the working set with time-windowing and keyset pagination, and check growth asymmetry, because the right plan today may invert as table ratios change. The symptom framing matters: degradation correlated with data growth is itself evidence about the cause's shape.

Workflow

  1. Read the trajectory as evidence

    Month-over-month degradation points at growth-coupled work — the symptom narrows the suspects.

  2. Find the super-linear work

    What grows faster than the data: multiplying joins, spilling sorts, unbounded aggregates.

  3. Bound the working set

    Time windows, keyset pagination, pruning — queries that touch a bounded set stop degrading.

Why This Works

  • Trajectory-as-evidence thinking separates growth problems from regressions
  • The super-linear lens finds what will fail, not just what is slow today
  • Bounded working sets fix the class of problem, not the instance

Best for

  • Dashboards and feeds over growing tables
  • Queries whose slowness correlates with data volume
  • Teams who keep "fixing" the same query every quarter

Not for

  • A query that got slow suddenly overnight — check deployments first with the Debugging Prompt Generator
  • One-off reporting runs — that's the Reporting Query Optimization goal

Use cases

  • Investigating dashboards that slow a little every month
  • Finding the operation that grows faster than the data
  • Bounding queries that read ever-growing history

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

Explore all resources