From b8527514b77d1c1af1abad2fea3af72cc5e9e1cb Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Mon, 6 Nov 2017 18:09:48 +0100 Subject: [PATCH 1/6] Client: Add PARALLEL and VOLATILE categories I'm not 100% sure what's appropiate for plproxy functions so, for now, I've set them up as VOLATILE and PARALLEL UNSAFE --- client/Makefile | 19 +++++++++++++++++++ client/sql/10_geocoder_server_conn.sql | 2 +- client/sql/15_config_management.sql | 2 +- client/sql/20_table_augmentation.sql | 16 ++++++++-------- client/sql/35_precheck_functions.sql | 2 +- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/client/Makefile b/client/Makefile index 895f39f..7c4da43 100644 --- a/client/Makefile +++ b/client/Makefile @@ -8,6 +8,11 @@ SED = sed ERB = erb REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g' NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql +AWK = awk + +# Parallel support macros +PG_CONFIG = pg_config +PG_PARALLEL := $(shell $(PG_CONFIG) --version | ($(AWK) '{$$2*=1000; if ($$2 >= 9600) print 1; else print 0;}' 2> /dev/null || echo 0)) # OLD_VERSIONS = $(wildcard old_versions/*.sql) # DATA = $(NEW_EXTENSION_ARTIFACT) \ @@ -50,6 +55,13 @@ SOURCES_DATA = $(wildcard $(SOURCES_DATA_DIR)/*.sql) $(GENERATED_SQL_FILES) $(NEW_EXTENSION_ARTIFACT): $(SOURCES_DATA) rm -f $@ cat $(SOURCES_DATA_DIR)/*.sql >> $@ +ifeq ($(PG_PARALLEL), 0) +# Remove PARALLEL in aggregates and functions + $(eval TMPFILE := $(shell mktemp /tmp/$(basename $0).XXXXXXXX)) + $(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' \ + -e 's/PARALLEL [A-Z]*/''/g' $@ > $(TMPFILE) + mv $(TMPFILE) $@ +endif .PHONY: all all: $(DATA) @@ -61,6 +73,13 @@ release: $(EXTENSION).control $(SOURCES_DATA) $(SED) $(REPLACEMENTS) $(EXTENSION).control git add $(EXTENSION).control cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql +ifeq ($(PG_PARALLEL), 0) +# Remove PARALLEL in aggregates and functions + $(eval TMPFILE := $(shell mktemp /tmp/$(basename $0).XXXXXXXX)) + $(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' \ + -e 's/PARALLEL [A-Z]*/''/g' $@ > $(TMPFILE) + mv $(TMPFILE) $@ +endif git add $(EXTENSION)--$(NEW_VERSION).sql $(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql $(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql diff --git a/client/sql/10_geocoder_server_conn.sql b/client/sql/10_geocoder_server_conn.sql index d180ab6..cf1b2f5 100644 --- a/client/sql/10_geocoder_server_conn.sql +++ b/client/sql/10_geocoder_server_conn.sql @@ -13,4 +13,4 @@ BEGIN SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str; RETURN db_connection_str; END; -$$ LANGUAGE 'plpgsql'; \ No newline at end of file +$$ LANGUAGE 'plpgsql' STABLE PARALLEL SAFE; diff --git a/client/sql/15_config_management.sql b/client/sql/15_config_management.sql index 6a27cf6..16c8188 100644 --- a/client/sql/15_config_management.sql +++ b/client/sql/15_config_management.sql @@ -34,4 +34,4 @@ BEGIN result.organization_name = organization_name; RETURN result; END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; \ No newline at end of file +$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL SAFE; diff --git a/client/sql/20_table_augmentation.sql b/client/sql/20_table_augmentation.sql index fb69387..18f0d77 100644 --- a/client/sql/20_table_augmentation.sql +++ b/client/sql/20_table_augmentation.sql @@ -41,7 +41,7 @@ BEGIN RETURN result; END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_PopulateTableOBS_GetMeasure( table_name text, @@ -89,7 +89,7 @@ BEGIN RETURN result; END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PrepareTableOBS_GetMeasure( @@ -134,7 +134,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PrepareTableOBS_GetMeas ) return True -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PopulateTableOBS_GetMeasure( username text, @@ -227,7 +227,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client.__DST_PopulateTableOBS_GetMea fdw_server=plpy.quote_literal(server_name))) return True -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_ConnectUserTable( username text, @@ -239,7 +239,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_ConnectUserTable( )RETURNS cdb_dataservices_client.ds_fdw_metadata AS $$ CONNECT cdb_dataservices_client._server_conn_str(); TARGET cdb_dataservices_server._DST_ConnectUserTable; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_GetReturnMetadata( username text, @@ -249,7 +249,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_GetReturnMetadata( ) RETURNS cdb_dataservices_client.ds_return_metadata AS $$ CONNECT cdb_dataservices_client._server_conn_str(); TARGET cdb_dataservices_server._DST_GetReturnMetadata; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_FetchJoinFdwTableData( username text, @@ -261,7 +261,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_FetchJoinFdwTableData( ) RETURNS SETOF record AS $$ CONNECT cdb_dataservices_client._server_conn_str(); TARGET cdb_dataservices_server._DST_FetchJoinFdwTableData; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_DisconnectUserTable( username text, @@ -272,4 +272,4 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_client._DST_DisconnectUserTable( ) RETURNS boolean AS $$ CONNECT cdb_dataservices_client._server_conn_str(); TARGET cdb_dataservices_server._DST_DisconnectUserTable; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; diff --git a/client/sql/35_precheck_functions.sql b/client/sql/35_precheck_functions.sql index c238a6a..92f4520 100644 --- a/client/sql/35_precheck_functions.sql +++ b/client/sql/35_precheck_functions.sql @@ -51,4 +51,4 @@ BEGIN RETURN TRUE; END; -$$ LANGUAGE 'plpgsql'; +$$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE; From 80fc32e1ea4fcf29412b6721733d66758e6146fc Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Tue, 7 Nov 2017 11:45:07 +0100 Subject: [PATCH 2/6] Categorize renderer template functions --- client/renderer/templates/20_public_functions.erb | 2 +- .../renderer/templates/25_exception_safe_private_functions.erb | 2 +- client/renderer/templates/30_plproxy_functions.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/renderer/templates/20_public_functions.erb b/client/renderer/templates/20_public_functions.erb index 2282bbc..5ce9311 100644 --- a/client/renderer/templates/20_public_functions.erb +++ b/client/renderer/templates/20_public_functions.erb @@ -21,4 +21,4 @@ BEGIN <% return_statement do %><%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= params(_with_user_org=true).join(', ') %>)<% end %> END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE; diff --git a/client/renderer/templates/25_exception_safe_private_functions.erb b/client/renderer/templates/25_exception_safe_private_functions.erb index 824577e..863bbf4 100644 --- a/client/renderer/templates/25_exception_safe_private_functions.erb +++ b/client/renderer/templates/25_exception_safe_private_functions.erb @@ -32,4 +32,4 @@ BEGIN <%= return_statement %> END; END; -$$ LANGUAGE 'plpgsql' SECURITY DEFINER; +$$ LANGUAGE 'plpgsql' SECURITY DEFINER STABLE PARALLEL UNSAFE; diff --git a/client/renderer/templates/30_plproxy_functions.erb b/client/renderer/templates/30_plproxy_functions.erb index 7a7a230..09f2620 100644 --- a/client/renderer/templates/30_plproxy_functions.erb +++ b/client/renderer/templates/30_plproxy_functions.erb @@ -6,4 +6,4 @@ RETURNS <%= return_type %> AS $$ <% else %> SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= params(_with_user_org=true).join(', ') %>); <% end %> -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; From a69da0084b2904afe9acaf3212be037deb8db9b9 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Tue, 7 Nov 2017 15:31:44 +0100 Subject: [PATCH 3/6] Server: Add PARALLEL support --- server/extension/Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/extension/Makefile b/server/extension/Makefile index 090210f..70435af 100644 --- a/server/extension/Makefile +++ b/server/extension/Makefile @@ -7,6 +7,11 @@ SED = sed ERB = erb REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g' NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql +AWK = awk + +# Parallel support macros +PG_CONFIG = pg_config +PG_PARALLEL := $(shell $(PG_CONFIG) --version | ($(AWK) '{$$2*=1000; if ($$2 >= 9600) print 1; else print 0;}' 2> /dev/null || echo 0)) REGRESS = $(notdir $(basename $(sort $(wildcard test/sql/*test.sql)))) TEST_DIR = test/ @@ -31,6 +36,13 @@ include $(PGXS) $(NEW_EXTENSION_ARTIFACT): $(SOURCES_DATA) rm -f $@ cat $(SOURCES_DATA_DIR)/*.sql >> $@ +ifeq ($(PG_PARALLEL), 0) +# Remove PARALLEL in aggregates and functions + $(eval TMPFILE := $(shell mktemp /tmp/$(basename $0).XXXXXXXX)) + $(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' \ + -e 's/PARALLEL [A-Z]*/''/g' $@ > $(TMPFILE) + mv $(TMPFILE) $@ +endif .PHONY: all all: $(DATA) @@ -41,6 +53,13 @@ release: $(EXTENSION).control $(SOURCES_DATA) git mv *.sql old_versions $(SED) $(REPLACEMENTS) $(EXTENSION).control cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql +ifeq ($(PG_PARALLEL), 0) +# Remove PARALLEL in aggregates and functions + $(eval TMPFILE := $(shell mktemp /tmp/$(basename $0).XXXXXXXX)) + $(SED) -e 's/PARALLEL \= [A-Z]*,/''/g' \ + -e 's/PARALLEL [A-Z]*/''/g' $@ > $(TMPFILE) + mv $(TMPFILE) $@ +endif $(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql $(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql From 98206a32968fba9f986066d62593599a05035833 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Tue, 7 Nov 2017 15:32:07 +0100 Subject: [PATCH 4/6] Server: Mark all plproxy functions as VOLATILE PARALLEL UNSAFE --- .../sql/110_data_observatory_augmentation.sql | 28 +++++++++---------- .../sql/115_data_observatory_exploration.sql | 4 +-- .../sql/120_data_observatory_geometries.sql | 14 +++++----- .../125_data_observatory_table_augment.sql | 8 +++--- .../sql/130_data_observatory_helper.sql | 14 +++++----- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/server/extension/sql/110_data_observatory_augmentation.sql b/server/extension/sql/110_data_observatory_augmentation.sql index b8d7a5c..49d1ad2 100644 --- a/server/extension/sql/110_data_observatory_augmentation.sql +++ b/server/extension/sql/110_data_observatory_augmentation.sql @@ -25,7 +25,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshotJS RETURNS json AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetDemographicSnapshot(geom, time_span, geometry_level); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot( username TEXT, @@ -79,7 +79,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshot( RETURNS SETOF json AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetDemographicSnapshot(geom, time_span, geometry_level); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetDemographicSnapshot( username TEXT, @@ -135,7 +135,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshotJSON( RETURNS json AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot( username TEXT, @@ -187,7 +187,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot( RETURNS SETOF json AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetSegmentSnapshot(geom, geometry_level); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetSegmentSnapshot( username TEXT, @@ -245,7 +245,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasure( RETURNS NUMERIC AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetMeasure(geom, measure_id, normalize, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeasure( username TEXT, @@ -301,7 +301,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetCategory( RETURNS TEXT AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetCategory(geom, category_id, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetCategory( username TEXT, @@ -357,7 +357,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusMeasure( RETURNS NUMERIC AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetUSCensusMeasure(geom, name, normalize, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetUSCensusMeasure( username TEXT, @@ -413,7 +413,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusCategory( RETURNS TEXT AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetUSCensusCategory(geom, name, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetUSCensusCategory( username TEXT, @@ -468,7 +468,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPopulation( RETURNS NUMERIC AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetPopulation(geom, normalize, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPopulation( username TEXT, @@ -523,7 +523,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasureById( RETURNS NUMERIC AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetMeasureById(geom_ref, measure_id, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeasureById( username TEXT, @@ -580,7 +580,7 @@ RETURNS TABLE ( ) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetData(geomvals, params, merge); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetData( username TEXT, @@ -640,7 +640,7 @@ RETURNS TABLE ( ) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetData(geomrefs, params); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetData( username TEXT, @@ -701,7 +701,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta( RETURNS JSON AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetMeta(geom, params, max_timespan_rank, max_score_rank, target_geoms); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeta( username TEXT, @@ -748,7 +748,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_MetadataValidation( RETURNS TABLE(valid boolean, errors text[]) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_MetadataValidation(geometry_extent, geometry_type, params, target_geoms); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_MetadataValidation( username TEXT, diff --git a/server/extension/sql/115_data_observatory_exploration.sql b/server/extension/sql/115_data_observatory_exploration.sql index 6c90dce..8158a43 100644 --- a/server/extension/sql/115_data_observatory_exploration.sql +++ b/server/extension/sql/115_data_observatory_exploration.sql @@ -6,7 +6,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_Search( RETURNS TABLE(id text, description text, name text, aggregate text, source text) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_Search(search_term, relevant_boundary); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_Search( username TEXT, @@ -65,7 +65,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetAvailableBoundaries( RETURNS TABLE(boundary_id text, description text, time_span text, tablename text) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetAvailableBoundaries(geom, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableBoundaries( username TEXT, diff --git a/server/extension/sql/120_data_observatory_geometries.sql b/server/extension/sql/120_data_observatory_geometries.sql index 0d5a09e..f1b8f62 100644 --- a/server/extension/sql/120_data_observatory_geometries.sql +++ b/server/extension/sql/120_data_observatory_geometries.sql @@ -7,7 +7,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundary( RETURNS geometry(Geometry, 4326) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetBoundary(geom, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundary( username TEXT, @@ -60,7 +60,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryId( RETURNS TEXT AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetBoundaryId(geom, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundaryId( username TEXT, @@ -113,7 +113,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryById( RETURNS geometry(Geometry, 4326) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.OBS_GetBoundaryById(geometry_id, boundary_id, time_span); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundaryById( username TEXT, @@ -167,7 +167,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByGeometry( RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetBoundariesByGeometry(geom, boundary_id, time_span, overlap_type); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundariesByGeometry( username TEXT, @@ -228,7 +228,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByPointAndR RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetBoundariesByPointAndRadius(geom, radius, boundary_id, time_span, overlap_type); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundariesByPointAndRadius( username TEXT, @@ -289,7 +289,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByGeometry( RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetPointsByGeometry(geom, boundary_id, time_span, overlap_type); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPointsByGeometry( username TEXT, @@ -350,7 +350,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByPointAndRadiu RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetPointsByPointAndRadius(geom, radius, boundary_id, time_span, overlap_type); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPointsByPointAndRadius( username TEXT, diff --git a/server/extension/sql/125_data_observatory_table_augment.sql b/server/extension/sql/125_data_observatory_table_augment.sql index ca44e13..d67f245 100644 --- a/server/extension/sql/125_data_observatory_table_augment.sql +++ b/server/extension/sql/125_data_observatory_table_augment.sql @@ -14,23 +14,23 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.__DST_ConnectUserTable(userna RETURNS cdb_dataservices_server.ds_fdw_metadata AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); TARGET cdb_observatory._OBS_ConnectUserTable; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_GetReturnMetadata(username text, orgname text, function_name text, params json) RETURNS cdb_dataservices_server.ds_return_metadata AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); TARGET cdb_observatory._OBS_GetReturnMetadata; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_FetchJoinFdwTableData(username text, orgname text, table_schema text, table_name text, function_name text, params json) RETURNS SETOF record AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); TARGET cdb_observatory._OBS_FetchJoinFdwTableData; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._DST_DisconnectUserTable(username text, orgname text, table_schema text, table_name text, servername text) RETURNS boolean AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); TARGET cdb_observatory._OBS_DisconnectUserTable; -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; diff --git a/server/extension/sql/130_data_observatory_helper.sql b/server/extension/sql/130_data_observatory_helper.sql index 917021b..9b72d3f 100644 --- a/server/extension/sql/130_data_observatory_helper.sql +++ b/server/extension/sql/130_data_observatory_helper.sql @@ -2,7 +2,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_dumpversion(username text RETURNS text AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT cdb_observatory.obs_dumpversion(); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; -- We could create a super type for the common data like id, name and so on but we need to parse inside the functions because the -- the return data tha comes from OBS is a TABLE() with them CREATE TYPE cdb_dataservices_server.obs_meta_numerator AS (numer_id text, numer_name text, numer_description text, numer_weight text, numer_license text, numer_source text, numer_type text, numer_aggregate text, numer_extra jsonb, numer_tags jsonb, valid_denom boolean, valid_geom boolean, valid_timespan boolean); @@ -18,7 +18,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableNumerators( RETURNS SETOF cdb_dataservices_server.obs_meta_numerator AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetAvailableNumerators(bounds, filter_tags, denom_id, geom_id, timespan); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetNumerators( username TEXT, @@ -35,7 +35,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetNumerators( RETURNS SETOF cdb_dataservices_server.obs_meta_numerator AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory._OBS_GetNumerators(bounds, section_tags, subsection_tags, other_tags, ids, name, denom_id, geom_id, timespan); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE TYPE cdb_dataservices_server.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean); @@ -50,7 +50,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableDenominators( RETURNS SETOF cdb_dataservices_server.obs_meta_denominator AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetAvailableDenominators(bounds, filter_tags, numer_id, geom_id, timespan); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE TYPE cdb_dataservices_server.obs_meta_geometry AS (geom_id text, geom_name text, geom_description text, geom_weight text, geom_aggregate text, geom_license text, geom_source text, valid_numer boolean, valid_denom boolean, valid_timespan boolean, score numeric, numtiles bigint, notnull_percent numeric, numgeoms numeric, percentfill numeric, estnumgeoms numeric, meanmediansize numeric, geom_type text, geom_extra jsonb, geom_tags jsonb); @@ -66,7 +66,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableGeometries( RETURNS SETOF cdb_dataservices_server.obs_meta_geometry AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan, number_geometries); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE TYPE cdb_dataservices_server.obs_meta_timespan AS (timespan_id text, timespan_name text, timespan_description text, timespan_weight text, timespan_aggregate text, timespan_license text, timespan_source text, valid_numer boolean, valid_denom boolean, valid_geom boolean, timespan_type text, timespan_extra jsonb, timespan_tags jsonb); @@ -81,7 +81,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableTimespans( RETURNS SETOF cdb_dataservices_server.obs_meta_timespan AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_GetAvailableTimespans(bounds, filter_tags, numer_id, denom_id, geom_id); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_LegacyBuilderMetadata( username TEXT, @@ -90,4 +90,4 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_LegacyBuilderMetadata( RETURNS TABLE(name TEXT, subsection JSON) AS $$ CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname); SELECT * FROM cdb_observatory.OBS_LegacyBuilderMetadata(aggregate_type); -$$ LANGUAGE plproxy; +$$ LANGUAGE plproxy VOLATILE PARALLEL UNSAFE; From ff71a406aeb133d60396c3f06f5bf33737ceb777 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Tue, 7 Nov 2017 17:23:05 +0100 Subject: [PATCH 5/6] Server: Categorize functions Redis/Service functions declared as STATIC to avoid unneded calls but it's really questionable if they trully are --- server/extension/sql/100_routing_helper.sql | 2 +- .../sql/105_route_between_points.sql | 4 +-- server/extension/sql/10_redis_helper.sql | 2 +- .../sql/110_data_observatory_augmentation.sql | 30 +++++++++---------- .../sql/115_data_observatory_exploration.sql | 4 +-- .../sql/120_data_observatory_geometries.sql | 14 ++++----- .../125_data_observatory_table_augment.sql | 2 +- server/extension/sql/15_config_helper.sql | 18 +++++------ server/extension/sql/200_quotas.sql | 4 +-- server/extension/sql/20_geocode_street.sql | 14 ++++----- server/extension/sql/210_rates.sql | 8 ++--- server/extension/sql/30_admin0.sql | 4 +-- server/extension/sql/40_admin1.sql | 8 ++--- server/extension/sql/50_namedplaces.sql | 16 +++++----- server/extension/sql/60_postalcodes.sql | 24 +++++++-------- server/extension/sql/70_ips.sql | 4 +-- server/extension/sql/80_isolines_helper.sql | 6 ++-- server/extension/sql/85_isodistance.sql | 6 ++-- server/extension/sql/90_isochrone.sql | 6 ++-- 19 files changed, 88 insertions(+), 88 deletions(-) diff --git a/server/extension/sql/100_routing_helper.sql b/server/extension/sql/100_routing_helper.sql index 681d240..9fd865d 100644 --- a/server/extension/sql/100_routing_helper.sql +++ b/server/extension/sql/100_routing_helper.sql @@ -63,4 +63,4 @@ RETURNS cdb_dataservices_server.simple_route AS $$ raise Exception('Error trying to calculate mapzen routing') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/105_route_between_points.sql b/server/extension/sql/105_route_between_points.sql index 217fc06..45a0c2e 100644 --- a/server/extension/sql/105_route_between_points.sql +++ b/server/extension/sql/105_route_between_points.sql @@ -22,7 +22,7 @@ RETURNS cdb_dataservices_server.simple_route AS $$ mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"]) result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units]) return [result[0]['shape'],result[0]['length'], result[0]['duration']] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_with_waypoints( @@ -47,4 +47,4 @@ RETURNS cdb_dataservices_server.simple_route AS $$ mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"]) result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units]) return [result[0]['shape'],result[0]['length'], result[0]['duration']] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/10_redis_helper.sql b/server/extension/sql/10_redis_helper.sql index e010088..1ba0ca4 100644 --- a/server/extension/sql/10_redis_helper.sql +++ b/server/extension/sql/10_redis_helper.sql @@ -15,4 +15,4 @@ RETURNS boolean AS $$ 'redis_metrics_connection': redis_metrics_connection, } return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/110_data_observatory_augmentation.sql b/server/extension/sql/110_data_observatory_augmentation.sql index 49d1ad2..5649769 100644 --- a/server/extension/sql/110_data_observatory_augmentation.sql +++ b/server/extension/sql/110_data_observatory_augmentation.sql @@ -14,7 +14,7 @@ RETURNS text AS $$ user_obs_config = GD["user_obs_snapshot_config_{0}".format(username)] return user_obs_config.connection_str -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshotJSON( username TEXT, @@ -68,7 +68,7 @@ RETURNS json AS $$ raise Exception('Error trying to obs_get_demographic_snapshot') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshot( username TEXT, @@ -125,7 +125,7 @@ RETURNS SETOF JSON AS $$ raise Exception('Error trying to obs_get_demographic_snapshot') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshotJSON( username TEXT, @@ -177,7 +177,7 @@ RETURNS json AS $$ raise Exception('Error trying to obs_get_segment_snapshot') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot( username TEXT, @@ -232,7 +232,7 @@ RETURNS SETOF JSON AS $$ raise Exception('Error trying to OBS_GetSegmentSnapshot') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasure( username TEXT, @@ -289,7 +289,7 @@ RETURNS NUMERIC AS $$ raise Exception('Error trying to OBS_GetMeasure') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetCategory( username TEXT, @@ -344,7 +344,7 @@ RETURNS TEXT AS $$ raise Exception('Error trying to OBS_GetCategory') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusMeasure( username TEXT, @@ -401,7 +401,7 @@ RETURNS NUMERIC AS $$ raise Exception('Error trying to OBS_GetUSCensusMeasure') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusCategory( username TEXT, @@ -456,7 +456,7 @@ RETURNS TEXT AS $$ raise Exception('Error trying to OBS_GetUSCensusCategory') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPopulation( username TEXT, @@ -511,7 +511,7 @@ RETURNS NUMERIC AS $$ raise Exception('Error trying to OBS_GetPopulation') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasureById( username TEXT, @@ -566,7 +566,7 @@ RETURNS NUMERIC AS $$ raise Exception('Error trying to OBS_GetMeasureById') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData( username TEXT, @@ -627,7 +627,7 @@ RETURNS TABLE ( raise Exception('Error trying to OBS_GetData') finally: quota_service.increment_total_service_use(len(geomvals)) -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData( username TEXT, @@ -688,7 +688,7 @@ RETURNS TABLE ( raise Exception('Error trying to OBS_GetData') finally: quota_service.increment_total_service_use(len(geomrefs)) -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta( username TEXT, @@ -736,7 +736,7 @@ RETURNS JSON AS $$ import sys logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetMeta') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_MetadataValidation( username TEXT, @@ -782,4 +782,4 @@ RETURNS TABLE(valid boolean, errors text[]) AS $$ import sys logger.error('Error trying to OBS_MetadataValidation', sys.exc_info(), data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_MetadataValidation') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/115_data_observatory_exploration.sql b/server/extension/sql/115_data_observatory_exploration.sql index 8158a43..fcdc743 100644 --- a/server/extension/sql/115_data_observatory_exploration.sql +++ b/server/extension/sql/115_data_observatory_exploration.sql @@ -55,7 +55,7 @@ RETURNS TABLE(id text, description text, name text, aggregate text, source text) raise Exception('Error trying to OBS_Search') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetAvailableBoundaries( username TEXT, @@ -113,4 +113,4 @@ RETURNS TABLE(boundary_id text, description text, time_span text, tablename text raise Exception('Error trying to OBS_GetMeasureById') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/120_data_observatory_geometries.sql b/server/extension/sql/120_data_observatory_geometries.sql index f1b8f62..c0b6290 100644 --- a/server/extension/sql/120_data_observatory_geometries.sql +++ b/server/extension/sql/120_data_observatory_geometries.sql @@ -49,7 +49,7 @@ RETURNS geometry(Geometry, 4326) AS $$ raise Exception('Error trying to OBS_GetBoundary') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryId( username TEXT, @@ -102,7 +102,7 @@ RETURNS TEXT AS $$ raise Exception('Error trying to OBS_GetBoundaryId') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryById( username TEXT, @@ -155,7 +155,7 @@ RETURNS geometry(Geometry, 4326) AS $$ raise Exception('Error trying to OBS_GetBoundaryById') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByGeometry( username TEXT, @@ -215,7 +215,7 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ raise Exception('Error trying to OBS_GetBoundariesByGeometry') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius( username TEXT, @@ -277,7 +277,7 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ raise Exception('Error trying to OBS_GetBoundariesByPointAndRadius') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByGeometry( username TEXT, @@ -337,7 +337,7 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ raise Exception('Error trying to OBS_GetPointsByGeometry') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByPointAndRadius( username TEXT, @@ -399,4 +399,4 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$ raise Exception('Error trying to OBS_GetPointsByPointAndRadius') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/125_data_observatory_table_augment.sql b/server/extension/sql/125_data_observatory_table_augment.sql index d67f245..e64121e 100644 --- a/server/extension/sql/125_data_observatory_table_augment.sql +++ b/server/extension/sql/125_data_observatory_table_augment.sql @@ -8,7 +8,7 @@ RETURNS cdb_dataservices_server.ds_fdw_metadata AS $$ return plpy.execute("SELECT * FROM cdb_dataservices_server.__DST_ConnectUserTable({username}::text, {orgname}::text, {user_db_role}::text, {schema}::text, {dbname}::text, {host_addr}::text, {table_name}::text)" .format(username=plpy.quote_nullable(username), orgname=plpy.quote_nullable(orgname), user_db_role=plpy.quote_literal(user_db_role), schema=plpy.quote_literal(input_schema), dbname=plpy.quote_literal(dbname), table_name=plpy.quote_literal(table_name), host_addr=plpy.quote_literal(host_addr)) )[0] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.__DST_ConnectUserTable(username text, orgname text, user_db_role text, input_schema text, dbname text, host_addr text, table_name text) RETURNS cdb_dataservices_server.ds_fdw_metadata AS $$ diff --git a/server/extension/sql/15_config_helper.sql b/server/extension/sql/15_config_helper.sql index 86a2daa..31d3331 100644 --- a/server/extension/sql/15_config_helper.sql +++ b/server/extension/sql/15_config_helper.sql @@ -8,13 +8,13 @@ RETURNS boolean AS $$ logger_config = LoggerConfig(plpy) GD[cache_key] = logger_config return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; -- This is done in order to avoid an undesired depedency on cartodb extension CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_conf_getconf(input_key text) RETURNS JSON AS $$ SELECT VALUE FROM cartodb.cdb_conf WHERE key = input_key; -$$ LANGUAGE SQL STABLE SECURITY DEFINER; +$$ LANGUAGE SQL SECURITY DEFINER STABLE PARALLEL SAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.CDB_Conf_SetConf(key text, value JSON) @@ -23,7 +23,7 @@ BEGIN PERFORM cdb_dataservices_server.CDB_Conf_RemoveConf(key); EXECUTE 'INSERT INTO cartodb.CDB_CONF (KEY, VALUE) VALUES ($1, $2);' USING key, value; END -$$ LANGUAGE PLPGSQL VOLATILE SECURITY DEFINER; +$$ LANGUAGE PLPGSQL SECURITY DEFINER VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.CDB_Conf_RemoveConf(key text) @@ -31,7 +31,7 @@ FUNCTION cdb_dataservices_server.CDB_Conf_RemoveConf(key text) BEGIN EXECUTE 'DELETE FROM cartodb.CDB_CONF WHERE KEY = $1;' USING key; END -$$ LANGUAGE PLPGSQL VOLATILE SECURITY DEFINER; +$$ LANGUAGE PLPGSQL SECURITY DEFINER VOLATILE PARALLEL UNSAFE ; CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_geocoder_config(username text, orgname text, provider text DEFAULT NULL) @@ -46,7 +46,7 @@ RETURNS boolean AS $$ geocoder_config = GeocoderConfig(redis_conn, plpy, username, orgname, provider) GD[cache_key] = geocoder_config return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_internal_geocoder_config(username text, orgname text) RETURNS boolean AS $$ @@ -60,7 +60,7 @@ RETURNS boolean AS $$ geocoder_config = InternalGeocoderConfig(redis_conn, plpy, username, orgname) GD[cache_key] = geocoder_config return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_isolines_routing_config(username text, orgname text) RETURNS boolean AS $$ @@ -74,7 +74,7 @@ RETURNS boolean AS $$ isolines_routing_config = IsolinesRoutingConfig(redis_conn, plpy, username, orgname) GD[cache_key] = isolines_routing_config return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_routing_config(username text, orgname text) RETURNS boolean AS $$ @@ -102,7 +102,7 @@ RETURNS boolean AS $$ obs_snapshot_config = ObservatorySnapshotConfig(redis_conn, plpy, username, orgname) GD[cache_key] = obs_snapshot_config return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._get_obs_config(username text, orgname text) RETURNS boolean AS $$ @@ -116,4 +116,4 @@ RETURNS boolean AS $$ obs_config = ObservatoryConfig(redis_conn, plpy, username, orgname) GD[cache_key] = obs_config return True -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/200_quotas.sql b/server/extension/sql/200_quotas.sql index 48b84c2..7030159 100644 --- a/server/extension/sql/200_quotas.sql +++ b/server/extension/sql/200_quotas.sql @@ -85,7 +85,7 @@ RETURNS SETOF cdb_dataservices_server.service_quota_info AS $$ ret += [[service, monthly_quota, used_quota, soft_limit, provider]] return ret -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_enough_quota( @@ -102,4 +102,4 @@ returns BOOLEAN AS $$ WHERE p.service = service_::cdb_dataservices_server.service_type; RETURN params.soft_limit OR ((params.used_quota + input_size) <= params.monthly_quota); END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/20_geocode_street.sql b/server/extension/sql/20_geocode_street.sql index 7f8856a..388bac9 100644 --- a/server/extension/sql/20_geocode_street.sql +++ b/server/extension/sql/20_geocode_street.sql @@ -24,7 +24,7 @@ RETURNS Geometry AS $$ else: raise Exception('Requested geocoder is not available') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) @@ -40,7 +40,7 @@ RETURNS Geometry AS $$ else: raise Exception('Here geocoder is not available for your account.') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ @@ -55,7 +55,7 @@ RETURNS Geometry AS $$ else: raise Exception('Google geocoder is not available for your account.') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_mapzen_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ @@ -68,7 +68,7 @@ RETURNS Geometry AS $$ mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"]) return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point'] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_here_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ @@ -97,7 +97,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode street point using here maps') finally: service_manager.quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_google_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ @@ -126,7 +126,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode street point using google maps') finally: service_manager.quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ @@ -164,4 +164,4 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode street point using mapzen') finally: service_manager.quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/210_rates.sql b/server/extension/sql/210_rates.sql index 058c766..6fa97d7 100644 --- a/server/extension/sql/210_rates.sql +++ b/server/extension/sql/210_rates.sql @@ -16,7 +16,7 @@ RETURNS JSON AS $$ return json.dumps({'limit': rate_limit_config.limit, 'period': rate_limit_config.period}) else: return None -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_set_user_rate_limit( username TEXT, @@ -40,7 +40,7 @@ RETURNS VOID AS $$ period = None config = RateLimitsConfig(service=service, username=username, limit=limit, period=period) config_setter.set_user_rate_limits(config) -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_set_org_rate_limit( username TEXT, @@ -64,7 +64,7 @@ RETURNS VOID AS $$ period = None config = RateLimitsConfig(service=service, username=username, limit=limit, period=period) config_setter.set_org_rate_limits(config) -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_set_server_rate_limit( username TEXT, @@ -88,4 +88,4 @@ RETURNS VOID AS $$ period = None config = RateLimitsConfig(service=service, username=username, limit=limit, period=period) config_setter.set_server_rate_limits(config) -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE; diff --git a/server/extension/sql/30_admin0.sql b/server/extension/sql/30_admin0.sql index 593063a..7545802 100644 --- a/server/extension/sql/30_admin0.sql +++ b/server/extension/sql/30_admin0.sql @@ -32,7 +32,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode admin0 polygon') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -------------------------------------------------------------------------------- @@ -52,4 +52,4 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; diff --git a/server/extension/sql/40_admin1.sql b/server/extension/sql/40_admin1.sql index d883e22..f5c3a71 100644 --- a/server/extension/sql/40_admin1.sql +++ b/server/extension/sql/40_admin1.sql @@ -34,7 +34,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode admin1 polygon') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; ---- cdb_geocode_admin1_polygon(admin1_name text, country_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text) @@ -72,7 +72,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode admin1 polygon') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -------------------------------------------------------------------------------- @@ -101,7 +101,7 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; ---- cdb_geocode_admin1_polygon(admin1_name text, country_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_admin1_polygon(admin1_name text, country_name text) @@ -125,5 +125,5 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; diff --git a/server/extension/sql/50_namedplaces.sql b/server/extension/sql/50_namedplaces.sql index ca9196e..e876bdd 100644 --- a/server/extension/sql/50_namedplaces.sql +++ b/server/extension/sql/50_namedplaces.sql @@ -8,7 +8,7 @@ RETURNS Geometry AS $$ except spiexceptions.ExternalRoutineException as e: internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3) as point;", ["text", "text", "text"]) return plpy.execute(internal_plan, [username, orgname, city_name])[0]['point'] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; ---- cdb_geocode_namedplace_point(city_name text, country_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, country_name text) @@ -20,7 +20,7 @@ RETURNS Geometry AS $$ except spiexceptions.ExternalRoutineException as e: internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, NULL, $4) as point;", ["text", "text", "text", "text"]) return plpy.execute(internal_plan, [username, orgname, city_name, country_name])[0]['point'] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; ---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_namedplace_point(username text, orgname text, city_name text, admin1_name text, country_name text) @@ -32,7 +32,7 @@ RETURNS Geometry AS $$ except spiexceptions.ExternalRoutineException as e: internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, $4, $5) as point;", ["text", "text", "text", "text", "text"]) return plpy.execute(internal_plan, [username, orgname, city_name, admin1_name, country_name])[0]['point'] -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_geocode_namedplace(username text, orgname text, city_name text, admin1_name text DEFAULT NULL, country_name text DEFAULT NULL) RETURNS Geometry AS $$ @@ -77,7 +77,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode city point using mapzen') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_internal_geocode_namedplace(username text, orgname text, city_name text, admin1_name text DEFAULT NULL, country_name text DEFAULT NULL) RETURNS Geometry AS $$ @@ -120,7 +120,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode namedplace point') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -------------------------------------------------------------------------------- @@ -144,7 +144,7 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; ---- cdb_geocode_namedplace_point(city_name text, country_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, country_name text) @@ -164,7 +164,7 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; ---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) @@ -188,5 +188,5 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; diff --git a/server/extension/sql/60_postalcodes.sql b/server/extension/sql/60_postalcodes.sql index d5d6b9b..6fc27c3 100644 --- a/server/extension/sql/60_postalcodes.sql +++ b/server/extension/sql/60_postalcodes.sql @@ -32,12 +32,12 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode postal code point') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code double precision) RETURNS Geometry AS $$ SELECT cdb_dataservices_server.cdb_geocode_postalcode_point(username, orgname, code::text); -$$ LANGUAGE SQL; +$$ LANGUAGE SQL STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text) @@ -74,12 +74,12 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode postal code point') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code double precision, country text) RETURNS Geometry AS $$ SELECT cdb_dataservices_server.cdb_geocode_postalcode_point(username, orgname, code::text, country); -$$ LANGUAGE SQL; +$$ LANGUAGE SQL STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text) @@ -116,12 +116,12 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode postal code polygon') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code double precision) RETURNS Geometry AS $$ SELECT cdb_dataservices_server.cdb_geocode_postalcode_polygon(username, orgname, code::text) -$$ LANGUAGE SQL; +$$ LANGUAGE SQL STABLE PARALLEL RESTRICTED; @@ -159,12 +159,12 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode postal code polygon') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code double precision, country text) RETURNS Geometry AS $$ SELECT cdb_dataservices_server.cdb_geocode_postalcode_polygon(username, orgname, code::text, country); -$$ LANGUAGE SQL; +$$ LANGUAGE SQL STABLE PARALLEL RESTRICTED; -------------------------------------------------------------------------------- @@ -189,7 +189,7 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_point(code text, country text) RETURNS Geometry AS $$ @@ -214,7 +214,7 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text) RETURNS Geometry AS $$ @@ -235,7 +235,7 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_geocode_postalcode_polygon(code text, country text) RETURNS Geometry AS $$ @@ -260,4 +260,4 @@ RETURNS Geometry AS $$ RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; diff --git a/server/extension/sql/70_ips.sql b/server/extension/sql/70_ips.sql index 2b452aa..6b361c1 100644 --- a/server/extension/sql/70_ips.sql +++ b/server/extension/sql/70_ips.sql @@ -32,7 +32,7 @@ RETURNS Geometry AS $$ raise Exception('Error trying to geocode postal code polygon') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -------------------------------------------------------------------------------- @@ -63,4 +63,4 @@ RETURNS Geometry AS $$ FROM matches; RETURN ret; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql STABLE PARALLEL SAFE; diff --git a/server/extension/sql/80_isolines_helper.sql b/server/extension/sql/80_isolines_helper.sql index 2e1bfb2..1694936 100644 --- a/server/extension/sql/80_isolines_helper.sql +++ b/server/extension/sql/80_isolines_helper.sql @@ -55,7 +55,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ raise Exception('Error trying to get mapzen isolines') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_isodistance( username TEXT, @@ -121,7 +121,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ raise Exception('Error trying to get mapzen isolines') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_isochrones( @@ -185,4 +185,4 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ raise Exception('Error trying to get mapzen isochrones') finally: quota_service.increment_total_service_use() -$$ LANGUAGE plpythonu SECURITY DEFINER; +$$ LANGUAGE plpythonu SECURITY DEFINER STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/85_isodistance.sql b/server/extension/sql/85_isodistance.sql index 44d8e08..fe602c4 100644 --- a/server/extension/sql/85_isodistance.sql +++ b/server/extension/sql/85_isodistance.sql @@ -23,7 +23,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ return plpy.execute(mapzen_plan, [username, orgname, source, mode, range, options]) else: raise Exception('Requested isolines provider is not available') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -- heremaps isodistance CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_here_isodistance(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) @@ -38,7 +38,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) return result -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -- mapzen isodistance CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_mapzen_isodistance(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) @@ -52,4 +52,4 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ result = plpy.execute(mapzen_plan, [username, orgname, source, mode, range, options]) return result -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; diff --git a/server/extension/sql/90_isochrone.sql b/server/extension/sql/90_isochrone.sql index 02e5b0e..6c88bca 100644 --- a/server/extension/sql/90_isochrone.sql +++ b/server/extension/sql/90_isochrone.sql @@ -23,7 +23,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ return plpy.execute(mapzen_plan, [username, orgname, source, mode, range, options]) else: raise Exception('Requested isolines provider is not available') -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -- heremaps isochrone CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_here_isochrone(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) @@ -38,7 +38,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) return result -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; -- mapzen isochrone CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_mapzen_isochrone(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) @@ -51,4 +51,4 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_isochrones($1, $2, $3, $4, $5, $6) as isoline; ", ["text", "text", "geometry(geometry, 4326)", "text", "integer[]", "text[]"]) result = plpy.execute(mapzen_plan, [username, orgname, source, mode, range, options]) return result -$$ LANGUAGE plpythonu; +$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; From 5086ee908d7582c3eb71ed4c77f064841f8fb07b Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Mon, 13 Nov 2017 09:49:09 +0100 Subject: [PATCH 6/6] Update CONTRIBUTING with information about SQL function labels --- CONTRIBUTING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8adc290..cc8b841 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,6 +5,23 @@ The issue tracker is at [github.com/CartoDB/dataservices-api](https://github.com We love pull requests from everyone, see [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/#contributing). +## PostgreSQL +When adding or modifying PostgreSQL functions make sure that the +[VOLATILITY](https://www.postgresql.org/docs/current/static/xfunc-volatility.html) and [PARALLEL](https://www.postgresql.org/docs/9.6/static/parallel-safety.html) categories are updated accordingly. + +Please mark public [client functions](client/sql) or [templates](client/renderer/templates) +as STABLE even if the internals are VOLATILE to allow the planner to cache +results inside a query. For example, in this query we need `cdb_geocode_admin1_polygon` +to be STABLE so it gets called only once (instead of once per row): +```sql +SELECT * japank WHERE NOT (the_geom && cdb_geocode_admin1_polygon('Madrid', 'Spain')); +``` + +As PARALLEL labels need to be stripped for incompatible PostgreSQL versions, +please use _PARALLEL SAFE/RESTRICTED/UNSAFE_ in uppercase so it's handled +automatically. + + ## Submitting Contributions