Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSQLquery plan cache prepared plansSingle-choice MCQ

In PostgreSQL, a PL/pgSQL function repeatedly executes the same parameterized query. After the 6th execution the plan suddenly worsens for a skewed parameter. What internal behavior of the plan cache causes this, and at which execution does it trigger?

PREPARE p AS SELECT * FROM t WHERE status = $1; -- status is heavily skewed: -- 'archived' = 99% of rows, 'pending' = 0.1%