EXPLAIN gives a good strategy but nevertheless the query (and EXPLAIN ANLALYZE) runs extremely slowly.

Is there a simple way to force PostgreSQL always query by the same plan that EXPLAIN produces for a given query?

  • 1
    You're thinking about it backwards; explain always shows the actual plan Postgres will use to execute the query.
    – mustaccio
    Aug 6 at 16:31
  • @mustaccio If it is so, then why is EXPLAIN ANALYZE needed?
    – porton
    Aug 6 at 16:40
  • 1
    EXPLAIN without ANALYZE doesn't actually run the query. So it had better be faster.
    – jjanes
    Aug 6 at 16:46
  • EXPLAIN ANALYZE shows the actual execution metrics, while the simple EXPLAIN only shows estimates that the optimizer uses.
    – mustaccio
    Aug 6 at 17:31