Radim Marek: Your biggest tenant runs someone else's plan
Radim Marek analyzes how PostgreSQL can plan a large tenant's query using a generic plan derived from smaller tenants' executions in multi-tenant applications. The issue arises when one tenant is much bigger than others and the query is sent as a prepared statement, with the plan kept for the connection's lifetime. In one case a plan estimated a cost of a few hundred and one row, while production read thousands of buffers per call. He reproduced it on PostgreSQL 18.7 with pageinspect while working on RegreSQL, which compares plans by cost.
AI-written summary, checked against the cited sources. How summaries work