X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 49C80529E5 for ; Tue, 28 Jun 2005 05:33:19 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64481-02 for ; Tue, 28 Jun 2005 08:33:16 +0000 (GMT) Received: from mailhub1.une.edu.au (mailhub1.une.edu.au [129.180.1.122]) by svr1.postgresql.org (Postfix) with ESMTP id 368D352862 for ; Tue, 28 Jun 2005 05:33:14 -0300 (ADT) Received: from icarus.une.edu.au (icarus.une.edu.au [129.180.47.120]) by mailhub1.une.edu.au (Postfix) with ESMTP id 610E57EA0; Tue, 28 Jun 2005 18:33:16 +1000 (EST) Received: from kgb (unknown [129.180.47.225]) by icarus.une.edu.au (Postfix) with SMTP id 49C02355562; Tue, 28 Jun 2005 18:33:16 +1000 (EST) Date: Tue, 28 Jun 2005 18:36:35 +1000 From: Klint Gore To: David Mitchell Cc: pgsql-performance@postgresql.org Subject: Re: How can I speed up this function? In-Reply-To: <42C0B7EE.4040608@telogis.com> References: <42C0B7EE.4040608@telogis.com> Message-Id: <42C10C1338.6F82KG@129.180.47.120> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver 1.25.06 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/543 X-Sequence-Number: 13180 On Tue, 28 Jun 2005 14:37:34 +1200, David Mitchell wrote: > FOR transaction IN SELECT t.trans_id as ID > FROM pending_trans AS t WHERE fetched = false > ORDER BY trans_id LIMIT 50 What the the average number of statements per transaction? if avg > 2 then you could save a small amount of time by lowering the limit. You might also save some time by using FOR UPDATE on the select since the next thing you're going to do is update the value. > FOR statement IN SELECT s.id, s.transaction_id, s.table_name, s.op, > s.data > FROM dbmirror.pending_statement AS s > WHERE s.transaction_id = transaction.id > ORDER BY s.id ASC Have you explained this to make sure it's using the created index? You might need to order by both transaction_id, id. klint. +---------------------------------------+-----------------+ : Klint Gore : "Non rhyming : : EMail : kg@kgb.une.edu.au : slang - the : : Snail : A.B.R.I. : possibilities : : Mail University of New England : are useless" : : Armidale NSW 2351 Australia : L.J.J. : : Fax : +61 2 6772 5376 : : +---------------------------------------+-----------------+