What a Prepared Statement's Parameter Is, and Why the Engine Cannot See Its Value
A parameter is a placeholder in a prepared statement, written $1 or ?, whose value arrives separately when the statement runs. The statement's text never changes, so the same query text serves every value, which is what makes plan reuse possible. The catch is that when the database plans a statement without knowing the value, it has to guess how many rows the condition will keep, and a guess made for an average value can be badly wrong for an unusual one.
Questions this Concept answers
Why can a plan chosen without knowing a parameter's value be badly wrong for some values?
J
jeremy
Text
PostgreSQL plan_cache_mode
This article explains what happens when an application runs a query as a prepared statement, where the query text carries a placeholder and the real value is sent separately at execution time. Becaus…