Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6DDB3E60239 for ; Sun, 29 Jan 2012 19:05:10 -0400 (AST) Received: from toroondcbmts08.bellnexxia.net ([207.236.237.42] helo=toroondcbmts08-srv.bellnexxia.net) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rrdo4-0007oz-Du for pgsql-performance@postgresql.org; Sun, 29 Jan 2012 23:05:10 +0000 Received: from toip41-bus.srvr.bell.ca ([67.69.240.42]) by toroondcbmts08-srv.bellnexxia.net (InterMail vM.8.00.01.00 201-2244-105-20090324) with ESMTP id <20120129230453.YGZT10851.toroondcbmts08-srv.bellnexxia.net@toip41-bus.srvr.bell.ca>; Sun, 29 Jan 2012 18:04:53 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EAAnMJU9GMVPj/2dsb2JhbABDrlqBBYFyAQEFCGYLDAEDAgYDDQQEAQEKBBoHGRoTCQgBAQQTCAECh3q3X4gtDykEKRgHBoJ1P4NhYwSIDDOFBAGNTox3 Received: from unknown (HELO CAPRICA) ([70.49.83.227]) by toip41-bus.srvr.bell.ca with ESMTP; 29 Jan 2012 18:04:53 -0500 From: "Carlo Stonebanks" To: "'Pavel Stehule'" Cc: "'Merlin Moncure'" , References: <90C49E334DFE48C582A3214BA56E1DD4@CAPRICA> In-Reply-To: Subject: Re: pl/pgsql functions outperforming sql ones? Date: Sun, 29 Jan 2012 18:04:53 -0500 Message-ID: <5EE15F7F99964B33A11D6029F39A4FE8@CAPRICA> 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: Aczdh483IUOBsrbCSdGdWu6mwhjAKQBULP+A X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.17609 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/113 X-Sequence-Number: 46125 Pavel, are you saying that the code of the stored function is actually = being added to the SQL query, instead of a call to it? For example, I have = seen this: SELECT myVar FROM myTable WHERE myVar > 0 AND myFunc(myVar) And seen the SQL body of myVar appended to the outer query: ... Filter: SELECT CASE WHERE myVar < 10 THEN true ELSE false END Is this what we are talking about? Two questions: 1) Is this also done when the function is called as a SELECT column;=20 e.g. would: SELECT myFunc(myVar) AS result=20 - become: SELECT ( SELECT CASE WHERE myVar < 10 THEN true ELSE false END ) AS result? 2) Does that not bypass the benefits of IMMUTABLE? -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Pavel = Stehule Sent: January 28, 2012 1:38 AM To: Carlo Stonebanks Cc: Merlin Moncure; pgsql-performance@postgresql.org Subject: Re: [PERFORM] pl/pgsql functions outperforming sql ones? 2012/1/27 Carlo Stonebanks : > 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. > It is not necessary usually - simple SQL functions are merged to outer query - there are e few cases where this optimization cannot be processed and then there are performance lost. For example this optimization is not possible (sometimes) when some parameter is volatile Regards Pavel Stehule --=20 Sent via pgsql-performance mailing list = (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance