slow query - where not in

From: Jeremiah Elliott <jelliott(at)artcobell(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: slow query - where not in
Date: 2003-03-28 15:38:50
Message-ID: 200303280938.50382.jelliott@artcobell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)artcobell(dot)com
);

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Bruno Wolff III 2003-03-28 15:59:33 Re: slow query - where not in
Previous Message Robert Treat 2003-03-27 21:10:21 Re: max_fsm settings