From ff71a406aeb133d60396c3f06f5bf33737ceb777 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Tue, 7 Nov 2017 17:23:05 +0100 Subject: [PATCH] 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;