Re: select slows from 3 seconds to 30 seconds

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: select slows from 3 seconds to 30 seconds
Date: 2007-05-05 00:57:07
Message-ID: 12822.1178326627@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> writes:
> I have the query below which when run takes approx 3 seconds. However when I
> add the condition 'and w_ws_id = 10' onto the end changes to 30+ seconds.
> Can anyone see why? I've included the explain for the long select.

You really ought to provide EXPLAIN ANALYZE output for both versions if
you want intelligent commentary --- otherwise we're just guessing.

But I would guess the problem is that the planner is way off about the
number of rows satisfying the joint condition --- it thinks two:

> -> Index Scan using walon_hide_index on walon (cost=0.00..85.04 rows=2 width=140)
> Index Cond: (w_hide = 0)
> Filter: (w_ws_id = 10)

This plan is good if there really are only a couple rows, but degrades
quickly if there are many...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2007-05-05 21:05:52 Sequence vs. Index Scan
Previous Message Richard Broersma Jr 2007-05-04 22:16:51 Re: Insert into VIEW using RULE. Not possible to use nextval()?