Re: function not called if part of aggregate

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: function not called if part of aggregate
Date: 2006-06-13 14:36:59
Message-ID: 22609.1150209419@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Craig A. James" <cjames(at)modgraph-usa(dot)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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Benjamin Arai 2006-06-13 16:04:15 Question about clustering multiple columns
Previous Message J. Andrew Rogers 2006-06-13 13:46:10 Re: 64-bit vs 32-bit performance ... backwards?