Slow DELETE with IN clausule - Mailing list pgsql-performance

From Jirka Novak
Subject Slow DELETE with IN clausule
Date
Msg-id 3DDA4A01.5040403@netsystem.cz
Whole thread Raw
Responses Re: Slow DELETE with IN clausule
Re: Slow DELETE with IN clausule
List pgsql-performance
Hello,

   does have IN operator in WHERE clausule any "undocumented" slowdown?
I have tables:

CREATE TABLE A (
         pkA int NOT NULL
         num int
    ...
);

CREATE TABLE B (
         fkA int NOT NULL,
    ...
);

ALTER TABLE B ADD CONSTRAINT FK_B_fkB_A_pkA FOREIGN KEY (fkB) REFERENCES
A(pkA);

   I have 3000 records in A and same number in B. For each record A I
have one record in B.
   When I do:


DELETE FROM B WHERE fkB IN (SELECT pkA FROM A WHERE num=1)

   postgresql start working for 2-3 minutes. But select (from IN
clausule) SELECT pkA FROM A WHERE num=1 end in few seconds. The slowest
is this DELETE when IN SELECT returns no records.
   Does any have some idea whats wrong?

                            Jirka Novak


pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: for/loop performance in plpgsql ?
Next
From: Andrew Sullivan
Date:
Subject: Re: Slow DELETE with IN clausule