Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Plan Cache, Parameterization and Parameter Sniffing: Symptoms, Diagnosis and Fixes
Parameter sniffing is a cached plan compiled for the first parameter value that does not fit other values on skewed data: the same procedure did 7,709 logical reads for customer 1 in one order and 612,850 in the other. Ad hoc/prepared plans, simple and forced parameterization, the price of RECOMPILE and OPTIMIZE FOR, 2022's PSP optimization, 2025's OPPO, and plan cache bloat from ORM parameter lengths.
Statistics and Cardinality Estimation: Histograms, Density and the Cost of a Wrong Estimate
The optimizer estimates row counts from statistics: if the value is a histogram step the estimate is exact, inside a step it is an average, and when unknown it falls back to the density vector. On 1 million Bookstore orders: reading the histogram, verifying the auto-update threshold (31,623 changes) by experiment, a plan 24 times more expensive due to the ascending key, CE models on correlated columns, and CE feedback.