X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 8AC84D1DB96 for ; Sat, 17 Apr 2004 09:25:45 -0300 (ADT) 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 11282-02 for ; Sat, 17 Apr 2004 09:25:45 -0300 (ADT) Received: from mailhost2.tudelft.nl (mailhost2.tudelft.nl [130.161.180.2]) by svr1.postgresql.org (Postfix) with ESMTP id BCAD9D1DB17 for ; Sat, 17 Apr 2004 09:25:41 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by rav.antivirus (Postfix) with ESMTP id 8ACF7213A0; Sat, 17 Apr 2004 14:25:44 +0200 (MEST) Received: from listserv.tudelft.nl (listserv.tudelft.nl [130.161.180.33]) by mailhost2.tudelft.nl (Postfix) with ESMTP id 54BA9212F9; Sat, 17 Apr 2004 14:25:44 +0200 (MEST) Received: from oli.tudelft.nl (jochemd.tnw-s.tudelft.nl [145.94.90.156]) by listserv.tudelft.nl (8.12.10/8.12.8) with ESMTP id i3HCPfF7009695; Sat, 17 Apr 2004 14:25:43 +0200 (MEST) Message-ID: <40812244.5080001@oli.tudelft.nl> Date: Sat, 17 Apr 2004 14:25:40 +0200 From: Jochem van Dieten Organization: OnLine Internet User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: rstpierre@syscor.com Cc: pgsql-performance@postgresql.org Subject: Re: Index Problem? References: <40800CC2.3050707@syscor.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at tudelft.nl X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/299 X-Sequence-Number: 6599 Ron St-Pierre wrote: > I am using postgres 7.4.1 and have a problem with a plpgsql function. > When I run the function on the production server it takes approx 33 > minutes to run. I dumped the DB and copied it to a similarly configured > box and ran the function and it ran in about 10 minutes. Can anyone > offer advice on tuning the function or my database? Here are the > lengthy, gory details. > > F u n c t i o n > It updates seven columns of a table 1 to 4 times daily. Current data = > 42,000 rows, new data = 30,000 rows. > > CREATE TYPE employeeType AS (empID INTEGER, updateDate DATE, bDate > INTEGER, val1 NUMERIC, val2 NUMERIC, val3 NUMERIC, val4 NUMERIC, favNum > NUMERIC); > > CREATE OR REPLACE FUNCTION updateEmployeeData() RETURNS SETOF > employeeType AS ' > DECLARE > rec RECORD; > BEGIN > FOR rec IN SELECT empID, updateDate, bDate, val1, val2, val3, val4, favNum FROM newData LOOP > RETURN NEXT rec; > UPDATE currentData SET val1=rec.val1, val2=rec.val2, val3=rec.val2, val4=rec.val4, favNum=rec.favNum, updateDate=rec.updateDate > WHERE empID=rec.empID; > END LOOP; > RETURN; > END; > ' LANGUAGE 'plpgsql'; Can't you handle this with a simple update query? UPDATE currentData SET val1 = newData.val1, val2 = newData.val2, val3 = newData.val3, val4 = newData.val4, favNum = newData.favNum, updateDate = newData.updateDate FROM newData WHERE newDate.empID = currentData.empID Jochem -- I don't get it immigrants don't work and steal our jobs - Loesje