pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Craig A. James <cjames@modgraph-usa.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: function not called if part of aggregate
Date: Sun, 11 Jun 2006 13:39:30 -0400
Message-ID: <18419.1150047570@sss.pgh.pa.us> (raw)
In-Reply-To: <448C505C.2080504@modgraph-usa.com>
References: <448C505C.2080504@modgraph-usa.com>

"Craig A. James" <cjames@modgraph-usa.com> 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



view thread (7+ messages)  latest in thread

Message-ID: <18419.1150047570@sss.pgh.pa.us>
Permalink:  ../18419.1150047570@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18419.1150047570@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cjames@modgraph-usa.com
  Subject: Re: function not called if part of aggregate
  In-Reply-To: <18419.1150047570@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox