Christophe Pettus discusses the plan_cache_mode GUC, which allows overriding PostgreSQL's default prepared statement planning behavior. This setting helps correct poor execution plans caused by inaccurate cost estimates when working with skewed data distributions. It provides a mechanism to choose between first-plan-caching and force-custom-plan strategies.
- Use plan_cache_mode to override automatic plan selection when cost estimates fail.
- Addresses execution plan degradation caused by data skew in prepared statements.
- Allows switching between caching the first plan or forcing a custom plan per execution.
- Valuable for consultants tuning applications with unpredictable query patterns.
- Avoids hardcoding plan hints by adjusting a session-level configuration parameter.