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: Tue, 13 Jun 2006 10:36:59 -0400
Message-ID: <22609.1150209419@sss.pgh.pa.us> (raw)
In-Reply-To: <448E5A92.9050206@modgraph-usa.com>
References: <448C505C.2080504@modgraph-usa.com>
	<87ac8jfu7t.fsf@stark.xeocode.com>
	<448E5A92.9050206@modgraph-usa.com>

"Craig A. James" <cjames@modgraph-usa.com> writes:
> But the weird thing is that, in spite of flattening, which would appear to make the queries equivalent, the function gets called in one case, and not in the other.

No, nothing particularly weird about it.  ORDER BY in a subselect
acts as an "optimization fence" that prevents flattening.  An
un-flattened subquery will evaluate all its output columns whether the
parent query reads them or not.  (This is not set in stone mind you,
but in the current planner implementation it's hard to avoid, because
such a sub-query gets planned before we've figured out which columns
the parent wants to reference.)  The cases in which you had the function
in a subquery without ORDER BY were flattenable, and in that case the
planner threw the function expression away as being unreferenced.

			regards, tom lane



view thread (7+ messages)

Message-ID: <22609.1150209419@sss.pgh.pa.us>
Permalink:  ../22609.1150209419@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22609.1150209419@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: <22609.1150209419@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