Post

Alexander Ioffe: Postgres runs your query fast exactly five times. Then it changes its mind. One prepared statement, twelve EXPLAIN ANALYZE runs on one connection, a plan change on run six, and why a single run could never have shown it. https://postgr.es/p/9uD #postgresql

0 reposts1 like

Rails people: this applies to you by default. ActiveRecord prepares statements on Postgres (prepared_statements: true, a 1000-statement cache per connection), so any tenant_id = $1 query hits the run-six flip. database.yml takes the fix: variables: { plan_cache_mode: force_custom_plan }.