Skip site navigation (1) Skip section navigation (2)

Re: slow query

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Ryan Bradetich <rbradetich(at)uswest(dot)net>
Cc: Oleg Lebedev <oleg(dot)lebedev(at)waterford(dot)org>,"pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: slow query
Date: 2003-02-23 21:47:58
Message-ID: (view raw or whole thread)
Lists: pgsql-performance

> > The above should use an EXISTS clause, not IN, unless you are absolutely
> > sure that the subquery will never return more than 12 rows.
> I am assuming you said this because EXISTS is faster for > 12 rows?
> Interesting :)

That's my rule of thumb, *NOT* any kind of relational-calculus-based truth.

Basically, one should only use IN for a subquery when one is *absolutely* sure 
that the subquery will only return a handful of records, *and* the subquery 
doesn't have to do an complex work like aggregating or custom function 

You're safer using EXISTS for all subqueries, really.

Josh Berkus
Aglio Database Solutions
San Francisco

In response to


pgsql-performance by date

Next:From: Tom LaneDate: 2003-02-24 02:28:54
Subject: Re: slow query
Previous:From: Ryan BradetichDate: 2003-02-23 21:05:34
Subject: Re: slow query

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group