Re: extra function calls from query returning composite type

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: ron(at)yellowbank(dot)com
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: extra function calls from query returning composite type
Date: 2014-12-30 17:27:15
Message-ID: CAHyXU0wHAtBJf8O6CBiUgp=8EnMVGCep=ZWWiXvYWR10v5p-sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Dec 29, 2014 at 9:06 AM, Ronald Peterson <ron(at)hub(dot)yellowbank(dot)com> wrote:
> I added a 'raise notice' to a plpgsql function I was working on
> recently, and noticed that my notification was being raised more often
> than I'd expect. The notification is raised in a function ('getone'
> in my example below) that returns a single composite value. This
> function is then called by another function ('getset') that returns a
> setof that composite value. It appears that 'getone' is called once
> for each column of my composite type. I whittled this down to the
> following example.
>
> I get the expected result from my query. But it appears to me (and
> what do I know) that perhaps something inefficient is happening in the
> way this query is running. Or maybe this is doing exactly what it
> should, in which case this is just a curiosity question - I don't
> understand why my 'getone' notice is called twice as often as I'd
> expect.

This was answered pretty clearly above. The problem is (func()).*
syntax and how it's expanded in the query. This was a longstanding
issue with set returning functions until 9.3 nailed it completely with
LATERAL. Consider (func()).* to be deprecated syntax.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andres Freund 2014-12-30 17:56:47 Re: bdr_init_copy fails when starting 2nd BDR node
Previous Message David Johnston 2014-12-30 16:21:39 Re: [HACKERS] ON_ERROR_ROLLBACK