X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id A266C310D0A for ; Tue, 1 Jul 2003 20:03:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 16042-10 for ; Tue, 1 Jul 2003 17:03:27 -0300 (ADT) Received: from www.postgresql.com (www.postgresql.com [64.117.225.209]) by svr1.postgresql.org (Postfix) with ESMTP id A7836310D2D for ; Tue, 1 Jul 2003 17:02:47 -0300 (ADT) Received: from mail.blarg.net (floyd.blarg.net [206.124.128.8]) by www.postgresql.com (Postfix) with ESMTP id 78873CF7975 for ; Tue, 1 Jul 2003 14:58:17 -0300 (ADT) Received: from poindextrose.org (poindextrose.org [206.124.144.246]) by mail.blarg.net (Postfix) with ESMTP id ED6E937F14 for ; Tue, 1 Jul 2003 10:55:07 -0700 (PDT) Date: Tue, 1 Jul 2003 10:55:06 -0700 Subject: Re: need some help with a delete statement Content-Type: text/plain; delsp=yes; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) From: Matthew Hixson To: Content-Transfer-Encoding: 7bit In-Reply-To: Message-Id: <25F95360-ABED-11D7-AB18-000393669C1A@poindextrose.org> X-Mailer: Apple Mail (2.552) X-Archive-Number: 200307/19 X-Sequence-Number: 14133 On Tuesday, July 1, 2003, at 05:47 AM, scott.marlowe wrote: >>> >>> what does the output of psql say if you have the /timing switch on? >> >> # select cart_id from carts except (select distinct cart_id from >> cart_contents) limit 1; >> cart_id >> --------- >> 2701 >> (1 row) >> Time: 10864.89 ms >> >> # explain analyze delete from carts where cart_id=2701; >> QUERY PLAN >> ---------------------------------------------------------------------- >> -- >> -------------------------------------------- >> Index Scan using carts_pkey on carts (cost=0.00..3.16 rows=1 >> width=6) >> (actual time=0.50..0.52 rows=1 loops=1) >> Index Cond: (cart_id = 2701) >> Total runtime: 1.06 msec >> (3 rows) >> Time: 257.83 ms > > Well, it looks like the fks are running really slow, which may well > mean > that they are seq scanning. Examine your table definition and make > sure > that they are the same types on both ends, and if not, recreate the > table > so that they are either the same types or one is coerced to the other > when > referencing it. Here are my table definitions. # \d v_carts; Table "public.carts" Column | Type | Modifiers -------------+----------------------- +-------------------------------------------------- cart_id | integer | not null default nextval('carts_sequence'::text) cart_cookie | character varying(24) | Indexes: carts_pkey primary key btree (cart_id), cart_cart_cookie btree (cart_cookie) # \d cart_contents; Table "public.cart_contents" Column | Type | Modifiers ------------------+----------------------------- +---------------------------------------------------------- cart_contents_id | integer | not null default nextval('cart_contents_sequence'::text) cart_id | integer | not null content_id | integer | not null expire_time | timestamp without time zone | Indexes: cart_contents_pkey primary key btree (cart_contents_id), cart_contents_cart_id btree (cart_id), cart_contents_content_id btree (content_id) The fk cart_contents.cart_id points to the pk carts.cart_id, and they are both integers. -M@