pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Rudow <Christian.Rudow@thinx.ch>
To: PostgreSQL SQL <pgsql-sql@postgreSQL.org>
Subject: NOT IN clause performing badly
Date: Mon, 26 Jul 1999 11:09:07 +0200
Message-ID: <379C25B3.A86C31F8@thinx.ch> (raw)

I have a problem with NOT IN queries
------------------------------------
Has anyone experinced the same problem, or even found a solution to it ?

-- simple NOT IN clause does not perform
-- create a table with an integer primary key and any number and type
   of attributes.
-- load approx. 10'000 records and vacuum;
-- then select a subset of say 8000 id's into a seperate table.
-- now try to find out the Id's of the remaining 2000 records

-- I would use a NOT IN clause
-- but this is what happens :

drop table tempx1;

select mytable.id
       into table tempx1
       from mytable, othertable
       where mytable.id = othertable.id
       and othertable.someattribute = "Somevalue";

-- this will take only a few seconds
-- on platform : PG6.4 SusE 6.0 PII/300mhz
-- rdbms startup : su - postgres -c with parameters :
-- "/sbin/startproc -l $LOGFILE $H -B 256 -i -o -F -D$DATADIR"

-- select count(*) from tempx1 : now returns 8000 rows

select id from mytable
       where id NOT IN (
       select id from tempx1
       );

-- this will take some 100 minutes at least !!!
-- but it does finish ! no crash or hangup.
-- NOTICE:  QUERY PLAN:
-- Seq Scan on mytable  (cost=958.89 size=10000 width=4)
--   SubPlan
--     ->  Seq Scan on tempx1  (cost=0.00 size=0 width=4)
--
-- an index on mytbale(id) exists.

Questions
---------
Is this a known problem ?
What is causing the problem ?
Is it a problem of RDBMS parameters ?
Is there an alternative to the NOT IN clause ?


I'd appreciate any help in this matter.
ThanX
Chris
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Christian Rudow                 E-Mail: Christian.Rudow@thinx.ch
ThinX networked business services    Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



view thread (2+ messages)  latest in thread

Message-ID: <379C25B3.A86C31F8@thinx.ch>
Permalink:  ../379C25B3.A86C31F8@thinx.ch/
Also on:    postgresql.org/message-id/379C25B3.A86C31F8@thinx.ch

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: Christian.Rudow@thinx.ch
  Subject: Re: NOT IN clause performing badly
  In-Reply-To: <379C25B3.A86C31F8@thinx.ch>
  References: <379C25B3.A86C31F8@thinx.ch>

* 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