X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 15978D1B523 for ; Mon, 20 Oct 2003 17:27:50 +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 70691-03 for ; Mon, 20 Oct 2003 14:27:19 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id B7634D1B508 for ; Mon, 20 Oct 2003 14:27:17 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.5) with ESMTP-TLS id 437147; Mon, 20 Oct 2003 10:26:09 -0700 Message-ID: <3F941A43.1040802@joeconway.com> Date: Mon, 20 Oct 2003 10:24:19 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Richard Huxton Cc: Michael Pohl , pgsql-sql@postgresql.org, "George A.J" Subject: Re: Which is faster SQL or PL/PGSQL References: <200310201809.51830.dev@archonet.com> In-Reply-To: <200310201809.51830.dev@archonet.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/243 X-Sequence-Number: 15643 Richard Huxton wrote: > So - gain by not re-planning on every call, but maybe lose because your plan > is not so precise. > > Of course, any queries you build dynamically and run via EXECUTE will have to > be planned each time. > This question gets even more complex in 7.4, where many simple SQL functions will get inlined, and library preloading is available to speed that first PL/pgSQL call. I think the best way to answer this question for any particular function is to try it both ways (if the function *can* be written as a SQL function) and see for yourself. And if you do this in 7.3, redo it when you upgrade to 7.4. HTH, Joe