pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Itai Zukerman <zukerman@math-hat.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: count(*), EXISTS, indexes
Date: Fri, 11 Apr 2003 18:11:58 -0400
Message-ID: <14252.1050099118@sss.pgh.pa.us> (raw)
In-Reply-To: <87vfxkrap2.fsf@matt.w80.math-hat.com>
References: <874r54sr8q.fsf@matt.w80.math-hat.com>
	<13918.1050095452@sss.pgh.pa.us>
	<87vfxkrap2.fsf@matt.w80.math-hat.com>

Itai Zukerman <zukerman@math-hat.com> writes:
>>> I'd like to calculate:
>>> SELECT sum(v) FROM A WHERE EXISTS (SELECT 1 FROM B WHERE A.x=B.x);
>>> ...but then it won't use the primary key index on A.x.
>> 
>> In CVS tip (7.4-to-be) I think
>> SELECT sum(v) FROM A WHERE A.x IN (SELECT B.x FROM B);

> Oops.  I guess I should've changed the example to "WHERE A.x>=B.x"
> since that's what I'm really doing.  Oh, well, my goof.

Anything else you didn't bother to mention?  Because in that case I
think your query reduces to

SELECT sum(v) FROM A WHERE A.x >= (SELECT min(x) FROM B);

which ought to run reasonably well (I'm sure it'll still want to
do a seqscan --- but not a nested loop).

			regards, tom lane




view thread (14+ messages)  latest in thread

Message-ID: <14252.1050099118@sss.pgh.pa.us>
Permalink:  ../14252.1050099118@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14252.1050099118@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, zukerman@math-hat.com
  Subject: Re: count(*), EXISTS, indexes
  In-Reply-To: <14252.1050099118@sss.pgh.pa.us>

* 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