Re: Inconsistant query plan

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Daniel Gish <dan(at)centrifugesolutions(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Inconsistant query plan
Date: 2006-01-24 23:30:18
Message-ID: 1138145417.25819.39.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, 2006-01-24 at 17:15, Daniel Gish wrote:
> Hi,
> We are running Postgresql 8.1, and getting dramatically inconsistant results
> after running VACUUM ANALYZE. Sometimes after analyzing the database, the
> query planner chooses a very efficient plan (15 rows, 4.744 ms), and
> sometimes a terrible one (24 rows, 3536.995 ms). Here's the abbreviated
> query:
>
> SELECT * FROM t1 INNER JOIN (t2 INNER JOIN (t3 INNER JOIN t4 ON t3.gid =
> t4.gid) ON t3.gid = t2.gid) ON t2.eid = t1.eid WHERE ...
>
> In the efficient plan, t2 is joined to t3 & t4 before being joined to t1.
> The inefficient plan joins t1 to t2 before joining to the other tables.
>
> We've experimented with different settings, such as shared_buffers &
> max_fsm_pages, to no avail. Anybody have a suggestion for getting the
> efficient plan to execute consistantly? If you'd like to see the actual
> query & query plans let me know.

Have you adjusted the stats target for that column? See \h alter table
in psql for the syntax for that. Then run analyze again.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Michael Fuhr 2006-01-24 23:58:57 Re: Inconsistant query plan
Previous Message Daniel Gish 2006-01-24 23:15:57 Inconsistant query plan