Conceptual
Login

A Prepared Statement Switches to a Generic Plan After Five Runs

When you run the same prepared statement repeatedly, PostgreSQL plans it fresh with your actual parameter values the first five times, then compares and may switch to one generic plan reused for every set of parameters — saving planning time, but ignoring what those parameters are. If your data is skewed, the generic plan can be much worse than the plan any single value deserved. plan_cache_mode lets you force force_custom_plan or force_generic_plan when you need to.

Questions this Concept answers

  • Why can a generic plan be much worse than the custom plans that preceded it?