X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 542669FA5DD for ; Sun, 11 Jun 2006 14:39:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 26044-02 for ; Sun, 11 Jun 2006 14:39:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 812EF9FA3D7 for ; Sun, 11 Jun 2006 14:39:32 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k5BHdU8F018420; Sun, 11 Jun 2006 13:39:30 -0400 (EDT) To: "Craig A. James" cc: pgsql-performance@postgresql.org Subject: Re: function not called if part of aggregate In-reply-to: <448C505C.2080504@modgraph-usa.com> References: <448C505C.2080504@modgraph-usa.com> Comments: In-reply-to "Craig A. James" message dated "Sun, 11 Jun 2006 10:18:20 -0700" Date: Sun, 11 Jun 2006 13:39:30 -0400 Message-ID: <18419.1150047570@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/119 X-Sequence-Number: 19476 "Craig A. James" writes: > select count(1) from (select foo_init(value) from foo_init_table order by value_id) as foo; > And indeed, it count() returns 800, as expected. But my function foo_init() never gets called! Really? With the ORDER BY in there, it does get called, in my experiments. What PG version is this exactly? However, the short answer to your question is that PG does not guarantee to evaluate parts of the query not needed to determine the result. You could do something like select count(x) from (select foo_init(value) as x from foo_init_table order by value_id) as foo; to ensure that foo_init() must be evaluated. regards, tom lane