Execution Plans & EXPLAIN: Real-World
Module: Query Optimization & Performance
Master advanced execution plan analysis for enterprise-scale optimization. Learn techniques used by database performance specialists at Fortune 500 companies to optimize complex queries with millions of rows, multiple joins, and subqueries. Essential for handling production incidents where queries suddenly become slow.
AWS RDS - Cost Model Tuning for GP3 SSD Storage
AWS RDS customers were experiencing suboptimal query plans after migrating from GP2 to GP3 SSD storage. The database was still using default cost parameters tuned for spinning disks, causing the optimizer to choose table scans over indexes even when indexes would be faster.
Cloud Infrastructure
Tuned PostgreSQL cost parameters for SSD: SET random_page_cost = 1.1 (from 4.0), SET effective_io_concurrency = 200 (from 1). This made the optimizer correctly prefer index scans on GP3 SSDs. Also increased shared_buffers from 25% to 40% of RAM to leverage faster storage. Monitored buffer cache hit ratio and parallel execution efficiency.
Configuration changes applied to RDS parameter group for SSD optimization
Query performance improved 3-5x for index-heavy workloads. Buffer cache hit ratio increased from 85% to 97%. Reduced RDS instance size by one tier, saving $15K annually. The optimization was purely configuration - no code changes needed.
PostgreSQL
Shopify - Parameter Sniffing Resolution
Shopify merchant dashboard queries were experiencing inconsistent performance. Same query would be fast (100ms) for some merchants and slow (30s) for others. Investigation revealed parameter sniffing: the cached plan was optimized for small merchants but terrible for large merchants with millions of products.
E-commerce
Implemented multiple solutions: 1) Added OPTION (RECOMPILE) for queries with high parameter variance, 2) Created separate stored procedures for small vs large merchants, 3) Used plan guides to force optimal plans for known problematic queries, 4) Enabled Query Store to track plan performance and detect regressions, 5) Set up alerts for plan changes.
Used SQL Server Query Store and plan guides to manage parameter-sensitive queries
Eliminated 30-second timeouts for large merchants. Consistent sub-second performance across all merchant sizes. Reduced support tickets by 60%. Query Store enabled proactive detection of plan regressions before customers noticed.
SQL Server