X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3DF6DD1D249 for ; Thu, 12 Feb 2004 21:49:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 22108-04 for ; Thu, 12 Feb 2004 17:49:25 -0400 (AST) Received: from web60803.mail.yahoo.com (web60803.mail.yahoo.com [216.155.196.66]) by svr1.postgresql.org (Postfix) with SMTP id 64374D1B917 for ; Thu, 12 Feb 2004 17:49:22 -0400 (AST) Message-ID: <20040212214923.98051.qmail@web60803.mail.yahoo.com> Received: from [64.81.205.234] by web60803.mail.yahoo.com via HTTP; Thu, 12 Feb 2004 13:49:23 PST Date: Thu, 12 Feb 2004 13:49:23 -0800 (PST) From: ow Subject: Re: 7.4 - FK constraint performance To: Tom Lane Cc: pgsql-sql@postgresql.org In-Reply-To: <4559.1076601260@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/120 X-Sequence-Number: 16811 --- Tom Lane wrote: > ow writes: > > When I try to delete record, it takes > 3 min. > > I think it must be using a seqscan for the foreign key check query. > Could you try this and show the results? 1) SELECT 1 FROM ONLY "my"."large" x WHERE "small_id" = 201 FOR UPDATE OF x; QUERY PLAN Index Scan using small_fk on large x (cost=0.00..6.01 rows=1 width=6) (actual time=0.251..0.251 rows=0 loops=1) Index Cond: ((small_id)::integer = 201) Total runtime: 0.338 ms 2) prepare foo(my.dint) as SELECT 1 FROM ONLY "my"."large" x WHERE "small_id" = $1 FOR UPDATE OF x; explain analyze execute foo(201); QUERY PLAN Seq Scan on large x (cost=0.00..1787052.30 rows=7893843 width=6) (actual time=210566.301..210566.301 rows=0 loops=1) Filter: ((small_id)::integer = ($1)::integer) Total runtime: 210566.411 ms Thanks __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html