Re: Improving a simple query? - Mailing list pgsql-performance

From Steve Wampler
Subject Re: Improving a simple query?
Date
Msg-id 20030713204610.GA18123@weaver.tuc.noao.edu
Whole thread Raw
In response to Re: Improving a simple query?  ("Richard Huxton" <dev@archonet.com>)
Responses Re: Improving a simple query?
Re: Improving a simple query?
Re: Improving a simple query?
List pgsql-performance
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?

-Steve
--
Steve Wampler -- swampler@noao.edu
Quantum materiae materietur marmota monax si marmota
                    monax materiam possit materiari?

pgsql-performance by date:

Previous
From: Joe Conway
Date:
Subject: Re: Pgsql - Red Hat Linux - VS MySQL VS MSSQL
Next
From: "Jim C. Nasby"
Date:
Subject: Re: Pgsql - Red Hat Linux - VS MySQL VS MSSQL