Re: expensive function in select list vs limit clause - Mailing list pgsql-general

From Tom Lane
Subject Re: expensive function in select list vs limit clause
Date
Msg-id 7205.1491402576@sss.pgh.pa.us
Whole thread Raw
In response to expensive function in select list vs limit clause  (Chris Mair <chris@1006.org>)
Responses Re: expensive function in select list vs limit clause  (Chris Mair <chris@1006.org>)
List pgsql-general
Chris Mair <chris@1006.org> writes:
>  From the timings it appears that in the second explain analyze query a function
> call in the select list (expensive()) is evaluated in the sequential scan node
> *for each* row in big, despite the use of limit.

According to the SQL standard, the SELECT list is evaluated before ORDER
BY, so if you need an explicit sort step the function is going to get
calculated first.  This is obviously necessary if the function is used
as the sort key, but otherwise it's possible to be smarter.  We were not
smarter before 9.6 though.  You might find this commit message informative:

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=9118d03a8

            regards, tom lane


pgsql-general by date:

Previous
From: vinny
Date:
Subject: Re: browser interface to forums please?
Next
From: Adrian Klaver
Date:
Subject: Re: browser interface to forums please?