slow query - where not in - Mailing list pgsql-performance

From Jeremiah Elliott
Subject slow query - where not in
Date
Msg-id 200303280938.50382.jelliott@artcobell.com
Whole thread Raw
Responses Re: slow query - where not in  (Bruno Wolff III <bruno@wolff.to>)
Re: slow query - where not in  (Greg Stark <gsstark@mit.edu>)
List pgsql-performance
here is the query that is killing me:

select shoporder from sodetailtabletrans where shoporder not in(select
shoporder from soheadertable)

This is just an example query. Any time I use 'where not in(' it takes several
hours to return a resultset. The postgres version is 7.2.3 although I have
tried it on my test server which has 7.3 on it and it runs just as slow. The
server is a fast server 2GHz with a gig of ram.  I have tried several
differant index setups but nothing seems to help.

soheadertable - 5104 rows
CREATE TABLE "soheadertable" (
   "shoporder" numeric(10,0) NOT NULL,
   "initrundate" date,
   "actualrundate" date,
   "processedminutes" numeric(10,0),
   "starttime" timestamptz,
   "endtime" timestamptz,
   "line" int4,
   "personcount" numeric(10,0),
   "product" varchar(15),
   "qtytomake" numeric(10,3),
   "linestatus" numeric(2,0) DEFAULT 1,
   "finishlinestatus" numeric(2,0) DEFAULT 1,
   "qtyinqueue" numeric(10,3),
   "lastcartonprinted" numeric(10,0),
   "qtydone" int8,
   "warehouse" text,
   "rescheduledate" date,
   "calculateddatetorun" date
);
CREATE  UNIQUE INDEX "shoporder_soheadertable_ukey" ON "soheadertable"
("shoporder");

sodetailtabletrans - 31494 rows
CREATE TABLE "sodetailtabletrans" (
   "shoporder" numeric(10,0) NOT NULL,
   "soseq" numeric(5,0) NOT NULL,
   "product" char(15) NOT NULL,
   "qtyqueued" numeric(17,2),
   "qtyneeded" numeric(17,2),
   "qtyallocated" numeric(17,2),
   "qtyused" numeric(17,2),
   "linestatus" numeric(2,0) DEFAULT 1,
   "unitsperenditem" numeric(10,1),
   CONSTRAINT "sodetailtrans_pk" PRIMARY KEY ("shoporder", "soseq")

-Jeremiah Elliott
jelliott@artcobell.com
);


pgsql-performance by date:

Previous
From: Robert Treat
Date:
Subject: Re: max_fsm settings
Next
From: Bruno Wolff III
Date:
Subject: Re: slow query - where not in