Prompt Engineering SQL SQL Server

SQL Server Query Tuning — Plans, Sniffing, Clustering Keys

Fast for most customers, 30x slower for the largest two — the parameter sniffing signature. SQL Server tuning with actual plans, clustering-key economics, and CONVERT_IMPLICIT hunting.

Overview

SQL Server tuning has engine-specific realities that generic SQL advice misses entirely. This prompt carries them: demand actual execution plans with SET STATISTICS IO, TIME ON (estimated plans hide spills and estimate-vs-actual gaps); reason about the clustered index — every nonclustered index carries the clustering key, so a wide key taxes every index; check parameter sniffing when performance varies by parameter — the loaded scenario is exactly that signature, fast for most customers and 30x slower for the largest; and watch for CONVERT_IMPLICIT in the plan, where a VARCHAR/NVARCHAR mismatch turns seeks into scans. A high-execution Key Lookup gets flagged as the covering-index candidate it is.

Workflow

  1. Demand the actual plan

    SET STATISTICS IO, TIME ON plus the actual plan — estimates hide exactly what matters.

  2. Check the sniffing signature

    Performance varying by parameter value points at a plan compiled for unrepresentative values — evidence before OPTIMIZE FOR.

  3. Cost against the clustering key

    Every index recommendation accounts for what the clustered index makes it carry.

Why This Works

  • Engine-specific guidance replaces the advice that ignores how SQL Server actually works
  • The sniffing check turns a classic mystery into a testable hypothesis
  • Clustering-key economics keep index advice from being free-lunch thinking

Best for

  • .NET and SQL Server shops tuning production queries
  • Parameter-dependent performance mysteries
  • Plans that look fine estimated and terrible actual

Not for

  • PostgreSQL or MySQL tuning — platform modes exist because the realities differ
  • Investigating whether the database is the problem at all — that's the Debugging Prompt Generator

Use cases

  • Diagnosing queries fast for some parameters and slow for others
  • Reading actual plans for spills and key lookups
  • Costing nonclustered indexes against a wide clustering key

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

Explore all resources