Re: Where clause efficiency using "IN"

From: "Scott Marlowe" <smarlowe(at)qwest(dot)net>
To: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
Cc: "Postgres" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Where clause efficiency using "IN"
Date: 2004-10-22 15:42:16
Message-ID: 1098459735.21035.97.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, 2004-10-22 at 09:07, Sean Davis wrote:
> Just a quick general question: Can someone comment on using where
> clauses like:
>
> (sample = 2 OR sample = 3 OR sample = 4)
>
> as compared to
>
> sample in (2,3,4)
>
> in terms of efficiency?

I believe they are pretty much the same, in that the planner will turn
the in clause you have there into a series of ors. However, if it is a
subselect, then the planner can use a hashed aggregate method, as long
as the dataset can fit into memory, as defined by some setting, (I think
it's sort_mem, but I'm not completely sure).

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2004-10-22 15:56:36 Re: Where clause efficiency using "IN"
Previous Message Sean Davis 2004-10-22 15:07:45 Where clause efficiency using "IN"