[PERFORM] Can improve 'limit 1' ? with slow function

2014-06-27 Thread songtebo
The simplified scene: 
select slowfunction() from a order by b limit 1
is slow than
select slowfunction() from ( select * from a order by b limit 1)
if there are many records in table 'a'

The real scene:

function  ST_Distance_Sphere is slow than ST_Distance, the query:

SELECT ST_Distance_Sphere(s, ST_GeomFromText('POINT(1 1)')) from road order by 
ST_Distance(s, ST_GeomFromText('POINT(1 1)')) limit 1

is slow than:

select ST_Distance_Sphere(s, ST_GeomFromText('POINT(1 1)')) from (SELECT s from 
road order by ST_Distance(s, ST_GeomFromText('POINT(1 1)')) limit 1) as a

There are about 7000 records in 'road'.  





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


Re: [PERFORM] 60 core performance with 9.3

2014-06-27 Thread Andres Freund
On 2014-06-27 14:28:20 +1200, Mark Kirkwood wrote:
 My feeling is spinlock or similar, 'perf top' shows
 
 kernel find_busiest_group
 kernel _raw_spin_lock
 
 as the top time users.

Those don't tell that much by themselves, could you do a hierarchical
profile? I.e. perf record -ga? That'll at least give the callers for
kernel level stuff. For more information compile postgres with
-fno-omit-frame-pointer.

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


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


Re: [PERFORM] 60 core performance with 9.3

2014-06-27 Thread Mark Kirkwood

On 27/06/14 21:19, Andres Freund wrote:

On 2014-06-27 14:28:20 +1200, Mark Kirkwood wrote:

My feeling is spinlock or similar, 'perf top' shows

kernel find_busiest_group
kernel _raw_spin_lock

as the top time users.


Those don't tell that much by themselves, could you do a hierarchical
profile? I.e. perf record -ga? That'll at least give the callers for
kernel level stuff. For more information compile postgres with
-fno-omit-frame-pointer.



Excellent suggestion, will do next week!

regards

Mark



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