pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oskar Liljeblad <osk@hem.passagen.se>
To: pgsql-sql@postgresql.org
Subject: query with subquery abnormally slow?
Date: Mon, 1 Nov 1999 19:47:07 +0100
Message-ID: <19991101194707.A7034@oskar> (raw)

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)

Where package is an indexed varchar field.

The subquery generates 50 rows, and completes quickly when I run
it alone. Now if I manually replace the subquery with these 50
strings - like

  select *
    from items
    where package in
      ('r1', 'r2', 'r3', .., 'r50')

this new query completes in less than a second. The result
of the complete query is 500 rows.

Is this natural? Is there anything I can do to speed things up?
(Besides doing N+1 queries where N is the number of rows the
subquery would produce.)

Oskar Liljeblad (osk@hem.passagen.se)



view thread (8+ messages)  latest in thread

Message-ID: <19991101194707.A7034@oskar>
Permalink:  ../19991101194707.A7034@oskar/
Also on:    postgresql.org/message-id/19991101194707.A7034@oskar

 · 

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: osk@hem.passagen.se
  Subject: Re: query with subquery abnormally slow?
  In-Reply-To: <19991101194707.A7034@oskar>
  References: <19991101194707.A7034@oskar>

* 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