Can simplify 'limit 1' with slow function? - Mailing list pgsql-hackers

From gotoschool6g
Subject Can simplify 'limit 1' with slow function?
Date
Msg-id 53B01D39.1050009@gmail.com
Whole thread Raw
Responses Re: Can simplify 'limit 1' with slow function?  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-hackers
The simplified scene: 
select slowfunction(s) from a order by b limit 1;
is slow than
select slowfunction(s) from (select s from a order by b limit 1) as z;
if there are many records in table 'a'.


The real scene. Function  ST_Distance_Sphere is slow, the query:
SELECT ST_Distance_Sphere(s, ST_GeomFromText('POINT(1 1)')) from road order by c limit 1;
is slow than:
select ST_Distance_Sphere(s, ST_GeomFromText('POINT(1 1)')) from (SELECT s from road order by c limit 1) as a;
There are about 7000 records in 'road'.  

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Escaping from blocked send() reprised.
Next
From: Robert Haas
Date:
Subject: Re: Set new system identifier using pg_resetxlog