Update earthdistance extension for parallel query.
All functions provided by this extension are PARALLEL SAFE. Andreas Karlsson
This commit is contained in:
parent
a89b4b1be0
commit
50e5226bb3
|
@ -3,7 +3,8 @@
|
||||||
MODULES = earthdistance
|
MODULES = earthdistance
|
||||||
|
|
||||||
EXTENSION = earthdistance
|
EXTENSION = earthdistance
|
||||||
DATA = earthdistance--1.0.sql earthdistance--unpackaged--1.0.sql
|
DATA = earthdistance--1.1.sql earthdistance--1.0--1.1.sql \
|
||||||
|
earthdistance--unpackaged--1.0.sql
|
||||||
PGFILEDESC = "earthdistance - calculate distances on the surface of the Earth"
|
PGFILEDESC = "earthdistance - calculate distances on the surface of the Earth"
|
||||||
|
|
||||||
REGRESS = earthdistance
|
REGRESS = earthdistance
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* contrib/earthdistance/earthdistance--1.0--1.1.sql */
|
||||||
|
|
||||||
|
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION earthdistance UPDATE TO '1.1'" to load this file. \quit
|
||||||
|
|
||||||
|
ALTER FUNCTION earth() PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION sec_to_gc(float8) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION gc_to_sec(float8) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION ll_to_earth(float8, float8) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION latitude(earth) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION longitude(earth) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION earth_distance(earth, earth) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION earth_box(earth, float8) PARALLEL SAFE;
|
||||||
|
ALTER FUNCTION geo_distance(point, point) PARALLEL SAFE;
|
|
@ -1,4 +1,4 @@
|
||||||
/* contrib/earthdistance/earthdistance--1.0.sql */
|
/* contrib/earthdistance/earthdistance--1.1.sql */
|
||||||
|
|
||||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
\echo Use "CREATE EXTENSION earthdistance" to load this file. \quit
|
\echo Use "CREATE EXTENSION earthdistance" to load this file. \quit
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
-- in order to use different units (or a better value for the Earth's radius).
|
-- in order to use different units (or a better value for the Earth's radius).
|
||||||
|
|
||||||
CREATE FUNCTION earth() RETURNS float8
|
CREATE FUNCTION earth() RETURNS float8
|
||||||
LANGUAGE SQL IMMUTABLE
|
LANGUAGE SQL IMMUTABLE PARALLEL SAFE
|
||||||
AS 'SELECT ''6378168''::float8';
|
AS 'SELECT ''6378168''::float8';
|
||||||
|
|
||||||
-- Astromers may want to change the earth function so that distances will be
|
-- Astromers may want to change the earth function so that distances will be
|
||||||
|
@ -37,49 +37,56 @@ CREATE FUNCTION sec_to_gc(float8)
|
||||||
RETURNS float8
|
RETURNS float8
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT CASE WHEN $1 < 0 THEN 0::float8 WHEN $1/(2*earth()) > 1 THEN pi()*earth() ELSE 2*earth()*asin($1/(2*earth())) END';
|
AS 'SELECT CASE WHEN $1 < 0 THEN 0::float8 WHEN $1/(2*earth()) > 1 THEN pi()*earth() ELSE 2*earth()*asin($1/(2*earth())) END';
|
||||||
|
|
||||||
CREATE FUNCTION gc_to_sec(float8)
|
CREATE FUNCTION gc_to_sec(float8)
|
||||||
RETURNS float8
|
RETURNS float8
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT CASE WHEN $1 < 0 THEN 0::float8 WHEN $1/earth() > pi() THEN 2*earth() ELSE 2*earth()*sin($1/(2*earth())) END';
|
AS 'SELECT CASE WHEN $1 < 0 THEN 0::float8 WHEN $1/earth() > pi() THEN 2*earth() ELSE 2*earth()*sin($1/(2*earth())) END';
|
||||||
|
|
||||||
CREATE FUNCTION ll_to_earth(float8, float8)
|
CREATE FUNCTION ll_to_earth(float8, float8)
|
||||||
RETURNS earth
|
RETURNS earth
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth';
|
AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth';
|
||||||
|
|
||||||
CREATE FUNCTION latitude(earth)
|
CREATE FUNCTION latitude(earth)
|
||||||
RETURNS float8
|
RETURNS float8
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT CASE WHEN cube_ll_coord($1, 3)/earth() < -1 THEN -90::float8 WHEN cube_ll_coord($1, 3)/earth() > 1 THEN 90::float8 ELSE degrees(asin(cube_ll_coord($1, 3)/earth())) END';
|
AS 'SELECT CASE WHEN cube_ll_coord($1, 3)/earth() < -1 THEN -90::float8 WHEN cube_ll_coord($1, 3)/earth() > 1 THEN 90::float8 ELSE degrees(asin(cube_ll_coord($1, 3)/earth())) END';
|
||||||
|
|
||||||
CREATE FUNCTION longitude(earth)
|
CREATE FUNCTION longitude(earth)
|
||||||
RETURNS float8
|
RETURNS float8
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT degrees(atan2(cube_ll_coord($1, 2), cube_ll_coord($1, 1)))';
|
AS 'SELECT degrees(atan2(cube_ll_coord($1, 2), cube_ll_coord($1, 1)))';
|
||||||
|
|
||||||
CREATE FUNCTION earth_distance(earth, earth)
|
CREATE FUNCTION earth_distance(earth, earth)
|
||||||
RETURNS float8
|
RETURNS float8
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT sec_to_gc(cube_distance($1, $2))';
|
AS 'SELECT sec_to_gc(cube_distance($1, $2))';
|
||||||
|
|
||||||
CREATE FUNCTION earth_box(earth, float8)
|
CREATE FUNCTION earth_box(earth, float8)
|
||||||
RETURNS cube
|
RETURNS cube
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE STRICT
|
IMMUTABLE STRICT
|
||||||
|
PARALLEL SAFE
|
||||||
AS 'SELECT cube_enlarge($1, gc_to_sec($2), 3)';
|
AS 'SELECT cube_enlarge($1, gc_to_sec($2), 3)';
|
||||||
|
|
||||||
--------------- geo_distance
|
--------------- geo_distance
|
||||||
|
|
||||||
CREATE FUNCTION geo_distance (point, point)
|
CREATE FUNCTION geo_distance (point, point)
|
||||||
RETURNS float8
|
RETURNS float8
|
||||||
LANGUAGE C IMMUTABLE STRICT AS 'MODULE_PATHNAME';
|
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE AS 'MODULE_PATHNAME';
|
||||||
|
|
||||||
--------------- geo_distance as operator <@>
|
--------------- geo_distance as operator <@>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# earthdistance extension
|
# earthdistance extension
|
||||||
comment = 'calculate great-circle distances on the surface of the Earth'
|
comment = 'calculate great-circle distances on the surface of the Earth'
|
||||||
default_version = '1.0'
|
default_version = '1.1'
|
||||||
module_pathname = '$libdir/earthdistance'
|
module_pathname = '$libdir/earthdistance'
|
||||||
relocatable = true
|
relocatable = true
|
||||||
requires = 'cube'
|
requires = 'cube'
|
||||||
|
|
Loading…
Reference in New Issue