Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50e5226

Browse files
committed
Update earthdistance extension for parallel query.
All functions provided by this extension are PARALLEL SAFE. Andreas Karlsson
1 parent a89b4b1 commit 50e5226

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

contrib/earthdistance/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
MODULES = earthdistance
44

55
EXTENSION = earthdistance
6-
DATA = earthdistance--1.0.sql earthdistance--unpackaged--1.0.sql
6+
DATA = earthdistance--1.1.sql earthdistance--1.0--1.1.sql \
7+
earthdistance--unpackaged--1.0.sql
78
PGFILEDESC = "earthdistance - calculate distances on the surface of the Earth"
89

910
REGRESS = earthdistance
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* contrib/earthdistance/earthdistance--1.0--1.1.sql */
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use "ALTER EXTENSION earthdistance UPDATE TO '1.1'" to load this file. \quit
5+
6+
ALTER FUNCTION earth() PARALLEL SAFE;
7+
ALTER FUNCTION sec_to_gc(float8) PARALLEL SAFE;
8+
ALTER FUNCTION gc_to_sec(float8) PARALLEL SAFE;
9+
ALTER FUNCTION ll_to_earth(float8, float8) PARALLEL SAFE;
10+
ALTER FUNCTION latitude(earth) PARALLEL SAFE;
11+
ALTER FUNCTION longitude(earth) PARALLEL SAFE;
12+
ALTER FUNCTION earth_distance(earth, earth) PARALLEL SAFE;
13+
ALTER FUNCTION earth_box(earth, float8) PARALLEL SAFE;
14+
ALTER FUNCTION geo_distance(point, point) PARALLEL SAFE;

contrib/earthdistance/earthdistance--1.0.sql renamed to contrib/earthdistance/earthdistance--1.1.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* contrib/earthdistance/earthdistance--1.0.sql */
1+
/* contrib/earthdistance/earthdistance--1.1.sql */
22

33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION earthdistance" to load this file. \quit
@@ -8,7 +8,7 @@
88
-- in order to use different units (or a better value for the Earth's radius).
99

1010
CREATE FUNCTION earth() RETURNS float8
11-
LANGUAGE SQL IMMUTABLE
11+
LANGUAGE SQL IMMUTABLE PARALLEL SAFE
1212
AS 'SELECT ''6378168''::float8';
1313

1414
-- Astromers may want to change the earth function so that distances will be
@@ -37,49 +37,56 @@ CREATE FUNCTION sec_to_gc(float8)
3737
RETURNS float8
3838
LANGUAGE SQL
3939
IMMUTABLE STRICT
40+
PARALLEL SAFE
4041
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';
4142

4243
CREATE FUNCTION gc_to_sec(float8)
4344
RETURNS float8
4445
LANGUAGE SQL
4546
IMMUTABLE STRICT
47+
PARALLEL SAFE
4648
AS 'SELECT CASE WHEN $1 < 0 THEN 0::float8 WHEN $1/earth() > pi() THEN 2*earth() ELSE 2*earth()*sin($1/(2*earth())) END';
4749

4850
CREATE FUNCTION ll_to_earth(float8, float8)
4951
RETURNS earth
5052
LANGUAGE SQL
5153
IMMUTABLE STRICT
54+
PARALLEL SAFE
5255
AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth';
5356

5457
CREATE FUNCTION latitude(earth)
5558
RETURNS float8
5659
LANGUAGE SQL
5760
IMMUTABLE STRICT
61+
PARALLEL SAFE
5862
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';
5963

6064
CREATE FUNCTION longitude(earth)
6165
RETURNS float8
6266
LANGUAGE SQL
6367
IMMUTABLE STRICT
68+
PARALLEL SAFE
6469
AS 'SELECT degrees(atan2(cube_ll_coord($1, 2), cube_ll_coord($1, 1)))';
6570

6671
CREATE FUNCTION earth_distance(earth, earth)
6772
RETURNS float8
6873
LANGUAGE SQL
6974
IMMUTABLE STRICT
75+
PARALLEL SAFE
7076
AS 'SELECT sec_to_gc(cube_distance($1, $2))';
7177

7278
CREATE FUNCTION earth_box(earth, float8)
7379
RETURNS cube
7480
LANGUAGE SQL
7581
IMMUTABLE STRICT
82+
PARALLEL SAFE
7683
AS 'SELECT cube_enlarge($1, gc_to_sec($2), 3)';
7784

7885
--------------- geo_distance
7986

8087
CREATE FUNCTION geo_distance (point, point)
8188
RETURNS float8
82-
LANGUAGE C IMMUTABLE STRICT AS 'MODULE_PATHNAME';
89+
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE AS 'MODULE_PATHNAME';
8390

8491
--------------- geo_distance as operator <@>
8592

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# earthdistance extension
22
comment = 'calculate great-circle distances on the surface of the Earth'
3-
default_version = '1.0'
3+
default_version = '1.1'
44
module_pathname = '$libdir/earthdistance'
55
relocatable = true
66
requires = 'cube'

0 commit comments

Comments
 (0)