pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14525: select <function>.* takes extremely long time
3+ messages / 3 participants
[nested] [flat]

* BUG #14525: select <function>.* takes extremely long time
@ 2017-02-02 09:05 martin.langwisch@gmx.net
  2017-02-02 12:13 ` Re: BUG #14525: select <function>.* takes extremely long time Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: martin.langwisch@gmx.net @ 2017-02-02 09:05 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14525
Logged by:          Martin Langwisch
Email address:      martin.langwisch@gmx.net
PostgreSQL version: 9.6.1
Operating system:   openSUSE 11.4 (x86_64)
Description:        

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;

It doesn't matter whether the function returns a composite type or a set of
composite type.

This behaviour strikes me as odd, to say the least and it took me quite some
time to find out why my code was so slow.

yours
Martin


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14525: select <function>.* takes extremely long time
  2017-02-02 09:05 BUG #14525: select <function>.* takes extremely long time martin.langwisch@gmx.net
@ 2017-02-02 12:13 ` Pavel Stehule <pavel.stehule@gmail.com>
  2017-02-02 14:27   ` Re: BUG #14525: select <function>.* takes extremely long time Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Pavel Stehule @ 2017-02-02 12:13 UTC (permalink / raw)
  To: martin.langwisch@gmx.net; +Cc: pgsql-bugs

Hi

2017-02-02 10:05 GMT+01:00 <martin.langwisch@gmx.net>:

> The following bug has been logged on the website:
>
> Bug reference:      14525
> Logged by:          Martin Langwisch
> Email address:      martin.langwisch@gmx.net
> PostgreSQL version: 9.6.1
> Operating system:   openSUSE 11.4 (x86_64)
> Description:
>
> 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;
>
> It doesn't matter whether the function returns a composite type or a set of
> composite type.
>
> This behaviour strikes me as odd, to say the least and it took me quite
> some
> time to find out why my code was so slow.
>

Although it looks strange - it is expected behave - and it is not a bug

XT is a composite type (a, b, c)

fx is a function with XT result.

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

Regards

Pavel



>
> yours
> Martin
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14525: select <function>.* takes extremely long time
  2017-02-02 09:05 BUG #14525: select <function>.* takes extremely long time martin.langwisch@gmx.net
  2017-02-02 12:13 ` Re: BUG #14525: select <function>.* takes extremely long time Pavel Stehule <pavel.stehule@gmail.com>
@ 2017-02-02 14:27   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2017-02-02 14:27 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-bugs

Pavel Stehule <pavel.stehule@gmail.com> writes:
> 2017-02-02 10:05 GMT+01:00 <martin.langwisch@gmx.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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2017-02-02 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-02-02 09:05 BUG #14525: select <function>.* takes extremely long time martin.langwisch@gmx.net
2017-02-02 12:13 ` Pavel Stehule <pavel.stehule@gmail.com>
2017-02-02 14:27   ` Tom Lane <tgl@sss.pgh.pa.us>

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