X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 1CAC9D1B531; Tue, 16 Dec 2003 23:50:14 +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 31799-08; Tue, 16 Dec 2003 19:49:45 -0400 (AST) Received: from mail.osdl.org (fw.osdl.org [65.172.181.6]) by svr1.postgresql.org (Postfix) with ESMTP id A8A03D1BC5C; Tue, 16 Dec 2003 19:49:37 -0400 (AST) Received: from ibm-a.pdx.osdl.net (ibm-a.pdx.osdl.net [172.20.1.50]) by mail.osdl.org (8.11.6/8.11.6) with ESMTP id hBGNneZ21642; Tue, 16 Dec 2003 15:49:40 -0800 Subject: update slows down in pl/pgsql function From: Jenny Zhang To: perf-pgsql , pgsql-general@postgresql.org Content-Type: text/plain Organization: osdl Message-Id: <1071618760.10925.17.camel@ibm-a.pdx.osdl.net> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Tue, 16 Dec 2003 15:52:41 -0800 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/917 X-Sequence-Number: 54310 I have stored procedure written in pl/pgsql which takes about 13 seconds to finish. I was able to identify that the slowness is caused by one update SQL: UPDATE shopping_cart SET sc_sub_total=sc_subtotal, sc_date=now() WHERE sc_id=sc_id; If I comment this sql out, the stored procedure returns within 1 second. What puzzles me is that if I execute the same update SQL in psql interface, it returns very fast. The following is the explain analyze output for that SQL. #>explain analyze UPDATE shopping_cart SET sc_sub_total=1, sc_date=now() where sc_id=260706; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------- Index Scan using shopping_cart_pkey on shopping_cart (cost=0.00..5.01 rows=1 width=144) (actual time=0.22..0.37 rows=1 loops=1) Index Cond: (sc_id = 260706::numeric) Total runtime: 1.87 msec (3 rows) Is it true that using pl/pgsql increases the overhead that much? TIA, Jenny -- Jenny Zhang Open Source Development Lab 12725 SW Millikan Way, Suite 400 Beaverton, OR 97005 (503)626-2455 ext 31