Re: [SQL] query with subquery abnormally slow?

From: Bill Brandt <brandtwr-pgsql(at)draaw(dot)net>
To: Oskar Liljeblad <osk(at)hem(dot)passagen(dot)se>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] query with subquery abnormally slow?
Date: 1999-11-01 20:35:40
Message-ID: 19991101153540.A1146@draaw.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

have you tried to:
explain <your select statement>
to see the cost of the parts?

I would try this. Then I would try a :
create index <indexname> on items (package)
and repeat the explain to see if it changes the cost.

Bill

On Mon, Nov 01, 1999 at 09:10:30PM +0100, Oskar Liljeblad wrote:
>On Mon, Nov 01, 1999 at 07:47:07PM +0100, Oskar Liljeblad wrote:
>> I'm doing a SELECT query with a subquery on a table with 12K rows
>> but it is very slow (10 seconds+). The query looks like this:
>>
>> select *
>> from items
>> where package in
>> (select package
>> from items
>> where ...blah...
>> group by package)
>
>I could do it much faster with this query:
>
> select distinct i2.package, i1.*
> from items i1, items i2
> where i1.package = i2.package
> and ...blah...
>
>but it is still at least three times slower than
>doing the subquery first, and for each row in the
>result another query. Any ideas?
>
>Oskar Liljeblad (osk(at)hem(dot)passagen(dot)se)
>
>************
>

Bill Brandt
brandtwr(at)draaw(dot)net http://www.draaw.net/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Oskar Liljeblad 1999-11-01 20:36:53 Re: [SQL] query with subquery abnormally slow?
Previous Message Oskar Liljeblad 1999-11-01 20:10:30 Re: [SQL] query with subquery abnormally slow?