&gt; 1. Add an option to EXPLAIN that will cause PostgreSQL&#x27;s optimizer to spit out multiple plans it considered, with costs, and with a description of the plan that PostgreSQL can easily parse and fit to a query.<p>The biggest problem with that approach is that the way query planning works isn&#x27;t that a 100 different plans are fully built, cost evaluated, and then compared. Instead it&#x27;s more like a dynamic programming approach where you iteratively build pieces of a query plan from ground up, and then combine those pieces to build the layer one up.  Given the space of possible query plans, especially with several relations and indexes on each relation involved, such an approach is required to actually <i>ever</i> finish planning.<p>&gt; Add a PLAN command that can be applied to a prepared statement and will set its plan. It is an error to submit a plan that does not match the query.<p>It&#x27;s not easily, if at all in the generic case!, possible to prove that a specific plan matches a query. You could obviously try to build every possible plan and match against each of those, but that&#x27;s computationally infeasible (we&#x27;re talking factorial number of plans, depending on relations here).<p>So I think such an approach has no chance of working.<p>What&#x27;s more realistic is a running queries in a &quot;training&quot; mode. That training mode would, matching on the specific parsetree, store the resulting plans in a table. Before exiting training mode you&#x27;d mark all these plans approved (after looking for bad cases obviously).  After that preparing a new query still does the original query planning, but by default the query stored in the &quot;approved plans&quot; table would be used. The cost differential and the new plan would then be associated with the currently approved plan.  Regularly the DBA (or whoever fulfills that role), checks the potential plans and approves new ones.<p>Based on a configuration option queries without approved plans would error out, raise a log message, or just work.<p>Now even that has significant problems because e.g. DDL will have the tendency to &quot;invalidate&quot; all the approved plans. But that&#x27;s manageable in comparison to being woken up Friday night.