NOT IN query takes forever

From: Marius Andreiana <mandreiana(at)rdslink(dot)ro>
To: pgsql-performance(at)postgresql(dot)org
Subject: NOT IN query takes forever
Date: 2004-08-03 08:49:02
Message-ID: 1091522942.4936.5.camel@marte.biciclete.ro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi

I have 2 tables like this:
CREATE TABLE query (
query_id int not null,
dat varchar(64) null ,
sub_acc_id int null ,
query_ip varchar(64) null ,
osd_user_type varchar(64) null
)
;

CREATE TABLE trans (
transaction_id varchar(64) not null ,
date varchar(64) null ,
query_id int not null ,
sub_acc_id int null ,
reg_acc_id int null
)
;

CREATE UNIQUE INDEX query_query_id_idx
ON query (query_id)
;

CREATE INDEX trans_reg_acc_id_idx
ON trans (reg_acc_id)
;

CREATE INDEX trans_query_id_idx
ON trans(query_id)
;
osd=> select count(*) from trans
osd-> ;
count
--------
598809
(1 row)

osd=>
osd=> select count(*) from query
osd-> ;
count
--------
137042
(1 row)

I just vacuum analyse'd the database.

Trying to run this query:
EXPLAIN ANALYSE
select * FROM trans
WHERE query_id NOT IN (select query_id FROM query)

but it will remain like that forever (cancelled after 30 min).

My postgresql.conf is the default:
# - Memory -

shared_buffers = 1000 # min 16, at least max_connections*2,
8KB each
#sort_mem = 1024 # min 64, size in KB
#vacuum_mem = 8192 # min 1024, size in KB

Should I adjust something?

Using postgresql 7.4.2, saw in release notes that IN/NOT IN queries are
at least as faster than EXISTS.

Thank you!
--
Marius Andreiana
Galuna - Solutii Linux in Romania
http://www.galuna.ro

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Lending, Rune 2004-08-03 09:09:26 pg_autovacuum parameters
Previous Message Scott Marlowe 2004-08-03 00:17:16 Re: my boss want to migrate to ORACLE