PostgreSQL Replans Prepared Statements When Planner Settings Change at EXECUTE
PostgreSQL offers planner configuration parameters like enable_seqscan and enable_indexscan that shape how query execution plans are generated, not how already-planned queries run. A key question arises with prepared statements: do these settings take effect at PREPARE time, at EXECUTE time, or both? Testing with a simple tasks table and a partial index shows that when enable_indexscan is turned off before EXECUTE, PostgreSQL generates a new plan using a sequential scan instead of the previously chosen index scan. This means planner settings applied before EXECUTE can trigger replanning, overriding the plan cached at PREPARE time. Developers should be aware that changing planner parameters between prepare and execute can significantly alter query behavior and performance.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in