Parameter Sensitive Plan Optimization — Complete Guide
Parameter Sensitive Plan Optimization — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of SQL Server Tutorial on Toolliyo Academy.
On this page
SQL Server Tutorial · Lesson 84 of 100
Parameter Sensitive Plan Optimization
SQL basics ✓ → Queries ✓ → Advanced
Advanced · 3 — Procedures · ~10 min · SQL — 2022 & Cloud
What is this?
PSPO (SQL Server 2022) can cache multiple plans for a query with different parameter values when data is skewed — reducing classic sniffing pain.
Why should you care?
One plan for a huge customer and a tiny customer often fails; PSPO keeps variants.
See it live — copy this example
Run in SQL Server Management Studio (SSMS) or Azure Data Studio.
USE DataVerse;
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SENSITIVE_PLAN_OPTIMIZATION = ON;
CREATE OR ALTER PROCEDURE dbo.usp_OrdersByCityPspo @City NVARCHAR(50)
AS
SELECT OrderId, Amount FROM dbo.Orders WHERE City = @City;
EXEC dbo.usp_OrdersByCityPspo @City = N'Mumbai';
EXEC dbo.usp_OrdersByCityPspo @City = N'Pune';
What happened?
- Enabling PSPO lets the engine consider multiple plans for sensitive parameters.
- Still design indexes well — PSPO is not a substitute for schema quality.
Practice next
- Enable PSPO on your database (2022+).
- Run the city proc for skewed cities.
- Inspect Query Store for multiple plans.
- Check Query Store plan counts for the proc.
- Update stats and retest.
Remember
PSPO caches multiple parameter plans. Helps skewed data. Available on SQL Server 2022+.
Skewed city traffic
DataVerse Mumbai dwarfs other cities.
Outcome: PSPO keeps separate plans; Pune stops timing out.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!