pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hannu Krosing <hannu@tm.ee>
To: Steve Wampler <swampler@noao.edu>
Cc: pgsql-performance@postgresql.org
Subject: Re: Improving a simple query?
Date: 14 Jul 2003 02:58:28 +0300
Message-ID: <1058140707.19113.0.camel@fuji.krosing.net> (raw)
In-Reply-To: <20030713204610.GA18123@weaver.tuc.noao.edu>
References: <1058119515.23012.114.camel@weaver.tuc.noao.edu>
	<49293.192.168.1.32.1058123357.squirrel@mainbox.archonet.com>
	<20030713204610.GA18123@weaver.tuc.noao.edu>

Steve Wampler kirjutas P, 13.07.2003 kell 23:46:
> On Sun, Jul 13, 2003 at 08:09:17PM +0100, Richard Huxton wrote:
> > > I'm not an SQL or PostgreSQL expert.
> > >
> > > I'm getting abysmal performance on a nested query and
> > > need some help on finding ways to improve the performance:
> > [snip]
> > >  select * from attributes_table where id in (select id from
> > >       attributes where (name='obsid') and (value='oid00066'));
> > 
> > This is the classic IN problem (much improved in 7.4 dev I believe). The
> > recommended approach is to rewrite the query as an EXISTS form if
> > possible. See the mailing list archives for plenty of examples.
> > 
> > Could you not rewrite this as a simple join though?
> 
> Hmmm, I don't see how.  Then again, I'm pretty much the village
> idiot w.r.t. SQL...
> 
> The inner select is locating a set of (2049) ids (actually from
> the same table, since 'attributes' is just a view into
> 'attributes_table').  The outer select is then locating all
> records (~30-40K) that have any of those ids.  Is that really
> something a JOIN could be used for?

There may be some subtle differences, but most likely the 'join' form
wis like this:

select at.*
  from attributes_table at,
       attributes a
 where at.id = a.id
   and a.name='obsid'
   and a.value='oid00066'

--------------
Hannu




view thread (8+ messages)  latest in thread

Message-ID: <1058140707.19113.0.camel@fuji.krosing.net>
Permalink:  ../1058140707.19113.0.camel@fuji.krosing.net/
Also on:    postgresql.org/message-id/1058140707.19113.0.camel@fuji.krosing.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-performance@postgresql.org
  Cc: hannu@tm.ee, swampler@noao.edu
  Subject: Re: Improving a simple query?
  In-Reply-To: <1058140707.19113.0.camel@fuji.krosing.net>
  References: <1058119515.23012.114.camel@weaver.tuc.noao.edu> <49293.192.168.1.32.1058123357.squirrel@mainbox.archonet.com> <20030713204610.GA18123@weaver.tuc.noao.edu> <1058140707.19113.0.camel@fuji.krosing.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