Can simplify 'limit 1' with slow function?
gotoschool6g <gotoschool6g@gmail.com>
From: "gotoschool6g" <gotoschool6g@gmail.com>
To: "pgsql-hackers" <pgsql-hackers@postgresql.org>
Date: 2014-06-29T14:05:50Z
Lists: 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'.