pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bill Brandt <brandtwr-pgsql@draaw.net>
To: Oskar Liljeblad <osk@hem.passagen.se>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] query with subquery abnormally slow?
Date: Mon, 1 Nov 1999 15:35:40 -0500
Message-ID: <19991101153540.A1146@draaw.net> (raw)
In-Reply-To: <19991101211030.A8132@oskar>
References: <19991101194707.A7034@oskar>
	<19991101211030.A8132@oskar>

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@hem.passagen.se)
>
>************
>

Bill Brandt                                   
brandtwr@draaw.net                              http://www.draaw.net/



view thread (8+ messages)  latest in thread

Message-ID: <19991101153540.A1146@draaw.net>
Permalink:  ../19991101153540.A1146@draaw.net/
Also on:    postgresql.org/message-id/19991101153540.A1146@draaw.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: brandtwr-pgsql@draaw.net, osk@hem.passagen.se
  Subject: Re: [SQL] query with subquery abnormally slow?
  In-Reply-To: <19991101153540.A1146@draaw.net>
  References: <19991101194707.A7034@oskar> <19991101211030.A8132@oskar> <19991101153540.A1146@draaw.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox