pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: John Pauley <karstdiver@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SELECT statement never completes.
Date: Wed, 9 Oct 2002 10:26:31 -0700 (PDT)
Message-ID: <20021009102456.H4728-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <20021009171021.25211.qmail@web13408.mail.yahoo.com>

On Wed, 9 Oct 2002, John Pauley wrote:

> pgsql-sql,
>
> We are porting a database from IBM DB2 to PostgreSQL.
> In several related scripts, there is a SELECT
> statement that never completes in Postgres but
> completes in a few seconds using DB2, for example:
>
> Table row count:
> SELECT count(*) FROM tableX;
>  112671
> SELECT count(*) from tableY;
>  314625
>
> This statement does not complete:
> SELECT id FROM tableX WHERE id NOT IN (SELECT id FROM
> tableY);
>
> Any suggestions?

Unfortunately IN <subselect> tends to have poor performance
in postgresql.  Often you can get better performance out
of exists, but not always.
You might want to try:
select id from tableX WHERE NOT EXISTS (select * from
 tableY where tableY.id=tableX.id);
and see if it runs better.




view thread (2+ messages)

Message-ID: <20021009102456.H4728-100000@megazone23.bigpanda.com>
Permalink:  ../20021009102456.H4728-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20021009102456.H4728-100000@megazone23.bigpanda.com

 · 

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: sszabo@megazone23.bigpanda.com, karstdiver@yahoo.com
  Subject: Re: SELECT statement never completes.
  In-Reply-To: <20021009102456.H4728-100000@megazone23.bigpanda.com>

* 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