Re: BUG #14525: select <function>.* takes extremely long time

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: martin(dot)langwisch(at)gmx(dot)net, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14525: select <function>.* takes extremely long time
Date: 2017-02-02 14:27:32
Message-ID: 32417.1486045652@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> 2017-02-02 10:05 GMT+01:00 <martin(dot)langwisch(at)gmx(dot)net>:
>> I have a function f that returns a composite type.
>> The following query:
>> select f().*
>> takes about ten times as long as either
>> select f()
>> or
>> select (f).* from (select f() as f) a;

> SELECT (fx()).* is translated by parser to query SELECT fx().a, fx().b,
> fx().c ....

> When your function fx is slow, then you cannot to use a (fx()).* pattern

Yeah. Putting the function in FROM is the recommended fix. You can
simplify the pattern to

select f.* from f() as f

or if the function needs arguments from a table,

select f.* from tab, lateral f(x,y) as f

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message bricklen 2017-02-02 15:20:28 Re: Bug in postgres log file
Previous Message tiago.babo 2017-02-02 14:07:01 BUG #14526: no unique or exclusion constraint matching the ON CONFLICT