Skip site navigation (1) Skip section navigation (2)

Re: Forcing the use of particular execution plans

From: "Dave Dutcher" <dave(at)tridecap(dot)com>
To: "'Tim Truman'" <tim(at)advam(dot)com>,<pgsql-performance(at)postgresql(dot)org>
Subject: Re: Forcing the use of particular execution plans
Date: 2006-09-27 15:51:26
Message-ID: 007b01c6e24c$ccfc8190$ (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
> -----Original Message-----
> From: pgsql-performance-owner(at)postgresql(dot)org
[mailto:pgsql-performance-owner(at)postgresql(dot)org] On Behalf Of  Tim Truman
> Hi,
> I have the following query which has been running very slowly 
> and after a
> lot of testing/trial and error I found an execution plan that 
> ran the query
> in a fraction of the time (and then lost the statistics that 
> produced it).
> What I wish to know is how to force the query to use the 
> faster execution
> plan.

It would be a bit easier to diagnose the problem if you posted EXPLAIN
ANALYZE rather than just EXPLAIN.  The two plans you posted looked very
similar except for the order of the nested loop in subquery 1 and an index
scan rather than a seq scan in subquery 2.  

My guess would be that the order of the nested loop is determined mostly by
estimates of matching rows.  If you ran an EXPLAIN ANALYZE you could tell if
the planner is estimating correctly.  If it is not, you could try increasing
your statistics target and running ANALYZE.  

To make the planner prefer an index scan over a seq scan, I would first
check the statistics again, and then you can try setting enable_seqscan to
false (enable_seqscan is meant more for testing than production) or, you
could try reducing random_page_cost, but you should test that against a
range of queries before putting it in production.


In response to


pgsql-performance by date

Next:From: Edoardo CeccarelliDate: 2006-09-27 16:08:30
Subject: autovacuum on a -mostly- r/o table
Previous:From: Tobias BroxDate: 2006-09-27 15:36:19
Subject: Re: Merge Join vs Nested Loop

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group