Can simplify 'limit 1' with slow function?

From: "gotoschool6g" <gotoschool6g(at)gmail(dot)com>
To: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Can simplify 'limit 1' with slow function?
Date: 2014-06-29 14:05:50
Message-ID: 53B01D39.1050009@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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'.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-06-29 14:06:39 Re: Array of composite types returned from python
Previous Message Abhijit Menon-Sen 2014-06-29 13:24:50 Re: [Fwd: Re: proposal: new long psql parameter --on-error-stop]