Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 20FD91259185 for ; Fri, 27 Jan 2012 15:59:29 -0400 (AST) Received: from toroondcbmts05.bellnexxia.net ([207.236.237.39] helo=toroondcbmts05-srv.bellnexxia.net) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RqrxG-0001xk-8y for pgsql-performance@postgresql.org; Fri, 27 Jan 2012 19:59:28 +0000 Received: from toip40-bus.srvr.bell.ca ([67.69.240.41]) by toroondcbmts05-srv.bellnexxia.net (InterMail vM.8.00.01.00 201-2244-105-20090324) with ESMTP id <20120127195912.TONM9955.toroondcbmts05-srv.bellnexxia.net@toip40-bus.srvr.bell.ca>; Fri, 27 Jan 2012 14:59:12 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgsFAK/9Ik9GMVPj/2dsb2JhbABEoiOML4EFgXIBAQUIZAIIAwwBAwIGAw0EBAEBAQkEGgcZCBITCQgBAQQTCAECh3m4EokPJjIRAg6CZ0kDgSQBgktjBIgMM4UEAY1PhQmHaQ Received: from unknown (HELO CAPRICA) ([70.49.83.227]) by toip40-bus.srvr.bell.ca with ESMTP; 27 Jan 2012 14:59:08 -0500 From: "Carlo Stonebanks" To: "'Deron'" Cc: References: <90C49E334DFE48C582A3214BA56E1DD4@CAPRICA> In-Reply-To: Subject: Re: pl/pgsql functions outperforming sql ones? Date: Fri, 27 Jan 2012 14:59:08 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 Thread-Index: AczdKfMrffLFPMKcR/m7MD0XtM7aBgAA+mKw X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.17609 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/97 X-Sequence-Number: 46109 Was I even right in thinking I would gain any performance by converting = to SQL? -----Original Message----- From: Deron [mailto:fecastle@gmail.com]=20 Sent: January 27, 2012 2:29 PM To: Carlo Stonebanks Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] pl/pgsql functions outperforming sql ones? You can use PREPARE... EXECUTE to "cache" the plan (as well as parsing). However, I find it unlikely this will would explain the loss in performance you experienced. Deron On Fri, Jan 27, 2012 at 11:36 AM, Carlo Stonebanks wrote: > Yes, I did test it =A0- i.e. I ran the functions on their own as I had always > noticed a minor difference between EXPLAIN ANALYZE results and direct query > calls. > > Interesting, so sql functions DON'T cache plans? Will plan-caching be = of any > benefit to SQL that makes no reference to any tables? The SQL is = emulating > the straight non-set-oriented procedural logic of the original = plpgsql. > > -----Original Message----- > From: Merlin Moncure [mailto:mmoncure@gmail.com] > Sent: January 27, 2012 10:47 AM > To: Carlo Stonebanks > Cc: pgsql-performance@postgresql.org > Subject: Re: [PERFORM] pl/pgsql functions outperforming sql ones? > > On Thu, Jan 26, 2012 at 6:09 PM, Carlo Stonebanks > wrote: >> Assuming there was some sort of cost to pl/pgsql, I rewrote a bunch = of >> stored functions s in straight SQL. Each stored proc was calling the next, >> so to get the full effect I had to track down all the pl/pgsql stored >> functions and convert them to sql. However, I was surprised to find = after >> all of the rewrites, the LANGUAGE sql procs caused the queries to run > slower >> than the LANGUAGE plpgsql. > > One reason that plpgsql can outperform sql functions is that plpgsql > caches plans. =A0That said, I don't think that's what's happening = here. > Did you confirm the performance difference outside of EXPLAIN ANALYZE? > =A0In particular cases EXPLAIN ANALYZE can skew times, either by > injecting time calls or in how it discards results. > > merlin > > > -- > Sent via pgsql-performance mailing list = (pgsql-performance@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-performance