Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 6F8689FB7A1 for ; Fri, 25 May 2007 06:25:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 21436-04 for ; Fri, 25 May 2007 06:25:14 -0300 (ADT) X-Greylist: delayed 00:28:07.687214 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 45BFA9FB76D for ; Fri, 25 May 2007 06:25:18 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from server.gdfi.pl (fal94.internetdsl.tpnet.pl [83.13.11.94]) by svr4.postgresql.org (Postfix) with ESMTP id 2EE8B5AF031 for ; Fri, 25 May 2007 08:57:09 +0000 (GMT) Received: from [192.168.0.196] by server.gdfi.pl with esmtpa (Exim 4.63) (envelope-from ) id 1HrVWH-00053Z-Ai for pgsql-performance@postgresql.org; Fri, 25 May 2007 10:51:33 +0200 Message-ID: <4656A4E0.7020400@datera.pl> Date: Fri, 25 May 2007 10:57:04 +0200 From: Michal Szymanski User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Big problem with sql update operation Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/489 X-Sequence-Number: 24879 Recently I've wrote few pgSql procedures that generates invoices and store it in postgres table. Small test has shown that there is performance problem. I've thought that string operation in pgsql are not perfect but it has appeared that 90% of time program waste on very simple update. Below is my simplified procedures: CREATE TABLE group_fin_account_tst ( group_fin_account_tst_id BIGSERIAL PRIMARY KEY, credit NUMERIC(8,2) DEFAULT 0.00 NOT NULL ) ; ALTER TABLE group_fin_account_tst OWNER TO freeconetadm; INSERT INTO group_fin_account_tst (credit) VALUES (4); CREATE OR REPLACE FUNCTION test() RETURNS void AS $BODY$ DECLARE BEGIN FOR v_i IN 1..4000 LOOP UPDATE group_fin_account_tst SET credit = v_i WHERE group_fin_account_tst_id = 1; -- for real procedure I update different rows END LOOP; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; ALTER FUNCTION test() OWNER TO freeconetadm; select test(); The strange thing is how program behave when I increase number of iteration. Below my results (where u/s is number of updates per second) On windows 500 - 0.3s(1666u/s) 1000 - 0.7s (1428u/s) 2000 - 2.3s (869u/s) 4000 - 9s (444u/s) 8000 -29s (275u/s) 16000-114s (14u/s) On linux: 500 - 0.5s(1000u/s) 1000 - 1.8s (555u/s) 2000 - 7.0s (285u/s) 4000 - 26s (153u/s) 8000 -101s (79u/s) 16000-400s (40u/s) On both systems relation between number of iteration and time is strongly nonlinear! Do you know what is a problem? Is it possible to commit transaction inside pgsql procedure because I think that maybe transaction is too long? Regards Michal Szymanski http://blog.szymanskich.net