Add PARALLEL parameter to functions

This commit is contained in:
Raul Marin 2017-10-24 14:16:56 +02:00 committed by Raúl Marín
parent f24d15f6ca
commit 0abc2ba250
41 changed files with 165 additions and 162 deletions

View File

@ -1,3 +1,6 @@
Dev (In progress)
* Added VOLATILITY and PARALLEL categories to all functions
0.19.2 (2017-06-30) 0.19.2 (2017-06-30)
* Improved functions to generate unique identifiers #305 * Improved functions to generate unique identifiers #305

View File

@ -7,7 +7,7 @@ BEGIN
RETURN CDB_Conf_GetConf('analysis_quota_factor')::text::float8; RETURN CDB_Conf_GetConf('analysis_quota_factor')::text::float8;
END; END;
$$ $$
LANGUAGE 'plpgsql' STABLE SECURITY DEFINER; LANGUAGE 'plpgsql' STABLE PARALLEL SAFE SECURITY DEFINER;
-- Get the factor (fraction of the quota) for Camshaft cached analysis tables -- Get the factor (fraction of the quota) for Camshaft cached analysis tables
@ -26,7 +26,7 @@ BEGIN
RETURN factor; RETURN factor;
END; END;
$$ $$
LANGUAGE 'plpgsql' STABLE; LANGUAGE 'plpgsql' STABLE PARALLEL SAFE;
-- This checks the space used up by Camshaft cached analysis tables. -- This checks the space used up by Camshaft cached analysis tables.
-- An exception will be raised if the limits are exceeded. -- An exception will be raised if the limits are exceeded.
@ -59,4 +59,4 @@ BEGIN
RAISE EXCEPTION 'Analysis cache space limits exceeded'; RAISE EXCEPTION 'Analysis cache space limits exceeded';
END IF; END IF;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;

View File

@ -8,7 +8,7 @@ AS $$
BEGIN BEGIN
RETURN table_name SIMILAR TO '\Aanalysis_[0-9a-f]{10}_[0-9a-f]{40}\Z'; RETURN table_name SIMILAR TO '\Aanalysis_[0-9a-f]{10}_[0-9a-f]{40}\Z';
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- This function returns a relation of Camshaft cached analysis tables in the given schema. -- This function returns a relation of Camshaft cached analysis tables in the given schema.
-- If the schema name parameter is NULL, then tables from all schemas -- If the schema name parameter is NULL, then tables from all schemas
@ -19,7 +19,7 @@ CREATE OR REPLACE FUNCTION _CDB_AnalysisTablesInSchema(schema_name text DEFAULT
RETURNS TABLE(table_regclass REGCLASS, schema_name TEXT, table_name TEXT) RETURNS TABLE(table_regclass REGCLASS, schema_name TEXT, table_name TEXT)
AS $$ AS $$
SELECT * FROM _CDB_UserTablesInSchema(schema_name) WHERE _CDB_IsAnalysisTableName(table_name); SELECT * FROM _CDB_UserTablesInSchema(schema_name) WHERE _CDB_IsAnalysisTableName(table_name);
$$ LANGUAGE 'sql'; $$ LANGUAGE 'sql' STABLE PARALLEL SAFE;
-- This function returns a relation user tables excluding analysis tables -- This function returns a relation user tables excluding analysis tables
-- If the schema name parameter is NULL, then tables from all schemas -- If the schema name parameter is NULL, then tables from all schemas
@ -30,7 +30,7 @@ CREATE OR REPLACE FUNCTION _CDB_NonAnalysisTablesInSchema(schema_name text DEFAU
RETURNS TABLE(table_regclass REGCLASS, schema_name TEXT, table_name TEXT) RETURNS TABLE(table_regclass REGCLASS, schema_name TEXT, table_name TEXT)
AS $$ AS $$
SELECT * FROM _CDB_UserTablesInSchema(schema_name) WHERE Not _CDB_IsAnalysisTableName(table_name); SELECT * FROM _CDB_UserTablesInSchema(schema_name) WHERE Not _CDB_IsAnalysisTableName(table_name);
$$ LANGUAGE 'sql'; $$ LANGUAGE 'sql' STABLE PARALLEL SAFE;
-- Total spaced used up by Camshaft cached analysis tables in the given schema. -- Total spaced used up by Camshaft cached analysis tables in the given schema.
-- Scope: private. -- Scope: private.
@ -52,4 +52,4 @@ BEGIN
END IF; END IF;
END; END;
$$ $$
LANGUAGE 'plpgsql' VOLATILE; LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;

View File

@ -26,7 +26,7 @@ BEGIN
RAISE EXCEPTION 'Please set user quota before cartodbfying tables.'; RAISE EXCEPTION 'Please set user quota before cartodbfying tables.';
END; END;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Drop cartodb triggers (might prevent changing columns) -- Drop cartodb triggers (might prevent changing columns)
CREATE OR REPLACE FUNCTION _CDB_drop_triggers(reloid REGCLASS) CREATE OR REPLACE FUNCTION _CDB_drop_triggers(reloid REGCLASS)
@ -49,7 +49,7 @@ BEGIN
sql := Format('DROP TRIGGER IF EXISTS test_quota_per_row ON %s', reloid::text); sql := Format('DROP TRIGGER IF EXISTS test_quota_per_row ON %s', reloid::text);
EXECUTE sql; EXECUTE sql;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Cartodb_id creation & validation or renaming if invalid -- Cartodb_id creation & validation or renaming if invalid
@ -195,7 +195,7 @@ BEGIN
END; END;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Create all triggers -- Create all triggers
@ -235,7 +235,7 @@ BEGIN
|| ''')'; || ''')';
EXECUTE sql; EXECUTE sql;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- 8.b) Create all raster triggers -- 8.b) Create all raster triggers
-- NOTE: drop/create has the side-effect of re-enabling disabled triggers -- NOTE: drop/create has the side-effect of re-enabling disabled triggers
@ -267,7 +267,7 @@ BEGIN
|| ''')'; || ''')';
EXECUTE sql; EXECUTE sql;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
@ -279,7 +279,7 @@ BEGIN
NEW.the_geom_webmercator := public.CDB_TransformToWebmercator(NEW.the_geom); NEW.the_geom_webmercator := public.CDB_TransformToWebmercator(NEW.the_geom);
RETURN NEW; RETURN NEW;
END; END;
$$ LANGUAGE plpgsql VOLATILE; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
--- Trigger to update the updated_at column. No longer added by default --- Trigger to update the updated_at column. No longer added by default
--- but kept here for compatibility with old tables which still have this behavior --- but kept here for compatibility with old tables which still have this behavior
@ -322,7 +322,7 @@ BEGIN
RETURN is_raster; RETURN is_raster;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL STABLE PARALLEL UNSAFE;
@ -398,7 +398,7 @@ geomcol := 'the_geom';
mercgeomcol := 'the_geom_webmercator'; mercgeomcol := 'the_geom_webmercator';
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' IMMUTABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION _CDB_Error(message TEXT, funcname TEXT DEFAULT '_CDB_Error') CREATE OR REPLACE FUNCTION _CDB_Error(message TEXT, funcname TEXT DEFAULT '_CDB_Error')
@ -409,7 +409,7 @@ BEGIN
RAISE EXCEPTION 'CDB(%): %', funcname, message; RAISE EXCEPTION 'CDB(%): %', funcname, message;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION _CDB_SQL(sql TEXT, funcname TEXT DEFAULT '_CDB_SQL') CREATE OR REPLACE FUNCTION _CDB_SQL(sql TEXT, funcname TEXT DEFAULT '_CDB_SQL')
@ -425,7 +425,7 @@ BEGIN
RAISE EXCEPTION 'CDB(%:%:%): %', funcname, SQLSTATE, SQLERRM, sql; RAISE EXCEPTION 'CDB(%:%:%): %', funcname, SQLSTATE, SQLERRM, sql;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
-- DEPRECATED: Use _CDB_Unique_Identifier since it's UTF8 Safe and length -- DEPRECATED: Use _CDB_Unique_Identifier since it's UTF8 Safe and length
@ -444,7 +444,7 @@ BEGIN
RAISE EXCEPTION '_CDB_Unique_Relation_Name is DEPRECATED. Use _CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)'; RAISE EXCEPTION '_CDB_Unique_Relation_Name is DEPRECATED. Use _CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)';
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL SAFE;
-- DEPRECATED: Use _CDB_Unique_Column_Identifier since it's UTF8 Safe and length -- DEPRECATED: Use _CDB_Unique_Column_Identifier since it's UTF8 Safe and length
@ -463,7 +463,7 @@ BEGIN
RAISE EXCEPTION '_CDB_Unique_Column_Name is DEPRECATED. Use _CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)'; RAISE EXCEPTION '_CDB_Unique_Column_Name is DEPRECATED. Use _CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)';
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL SAFE;
-- Find out if the table already has a usable primary key -- Find out if the table already has a usable primary key
@ -583,7 +583,7 @@ BEGIN
-- Didn't find re-usable key, so return FALSE -- Didn't find re-usable key, so return FALSE
RETURN false; RETURN false;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION _CDB_Has_Usable_PK_Sequence(reloid REGCLASS) CREATE OR REPLACE FUNCTION _CDB_Has_Usable_PK_Sequence(reloid REGCLASS)
@ -603,7 +603,7 @@ BEGIN
RETURN has_sequence; RETURN has_sequence;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' STABLE PARALLEL SAFE;
-- Return a set of columns that can be candidates to be the_geom[webmercator] -- Return a set of columns that can be candidates to be the_geom[webmercator]
-- with some extra information to analyze them. -- with some extra information to analyze them.
@ -632,7 +632,7 @@ BEGIN
AND postgis_typmod_srid(a.atttypmod) IN (4326, 3857, 0) AND postgis_typmod_srid(a.atttypmod) IN (4326, 3857, 0)
ORDER BY t.oid ASC; ORDER BY t.oid ASC;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' STABLE PARALLEL SAFE;
DO $$ DO $$
BEGIN BEGIN
@ -776,7 +776,7 @@ BEGIN
RETURN rv; RETURN rv;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
-- Create a copy of the table. Assumes that the "Has usable" functions -- Create a copy of the table. Assumes that the "Has usable" functions
@ -1127,7 +1127,7 @@ BEGIN
RETURN true; RETURN true;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
-- Assumes the table already has the right metadata columns -- Assumes the table already has the right metadata columns
@ -1229,7 +1229,7 @@ BEGIN
RETURN true; RETURN true;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
DROP FUNCTION IF EXISTS CDB_CartodbfyTable(destschema TEXT, reloid REGCLASS); DROP FUNCTION IF EXISTS CDB_CartodbfyTable(destschema TEXT, reloid REGCLASS);
CREATE OR REPLACE FUNCTION CDB_CartodbfyTable(destschema TEXT, reloid REGCLASS) CREATE OR REPLACE FUNCTION CDB_CartodbfyTable(destschema TEXT, reloid REGCLASS)
@ -1299,4 +1299,4 @@ BEGIN
RETURN (destschema || '.' || destname)::regclass; RETURN (destschema || '.' || destname)::regclass;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;

View File

@ -9,7 +9,7 @@ AS $$
WHERE c.oid = $1::oid WHERE c.oid = $1::oid
AND a.attstattarget < 0 -- exclude system columns AND a.attstattarget < 0 -- exclude system columns
ORDER BY a.attnum; ORDER BY a.attnum;
$$ LANGUAGE SQL; $$ LANGUAGE SQL STABLE PARALLEL SAFE;
-- This is to migrate from pre-0.2.0 version -- This is to migrate from pre-0.2.0 version
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36 -- See http://github.com/CartoDB/cartodb-postgresql/issues/36

View File

@ -9,7 +9,7 @@ AS $$
WHERE c.oid = $1::oid WHERE c.oid = $1::oid
AND a.attname = $2 AND a.attname = $2
AND a.attstattarget < 0; -- exclude system columns AND a.attstattarget < 0; -- exclude system columns
$$ LANGUAGE SQL; $$ LANGUAGE SQL STABLE PARALLEL SAFE;
-- This is to migrate from pre-0.2.0 version -- This is to migrate from pre-0.2.0 version
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36 -- See http://github.com/CartoDB/cartodb-postgresql/issues/36

View File

@ -26,7 +26,7 @@ BEGIN
PERFORM cartodb.CDB_Conf_RemoveConf(key); PERFORM cartodb.CDB_Conf_RemoveConf(key);
EXECUTE 'INSERT INTO cartodb.CDB_CONF (KEY, VALUE) VALUES ($1, $2);' USING key, value; EXECUTE 'INSERT INTO cartodb.CDB_CONF (KEY, VALUE) VALUES ($1, $2);' USING key, value;
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Conf_RemoveConf(key text) FUNCTION cartodb.CDB_Conf_RemoveConf(key text)
@ -34,7 +34,7 @@ FUNCTION cartodb.CDB_Conf_RemoveConf(key text)
BEGIN BEGIN
EXECUTE 'DELETE FROM cartodb.CDB_CONF WHERE KEY = $1;' USING key; EXECUTE 'DELETE FROM cartodb.CDB_CONF WHERE KEY = $1;' USING key;
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Conf_GetConf(key text) FUNCTION cartodb.CDB_Conf_GetConf(key text)
@ -45,4 +45,4 @@ BEGIN
EXECUTE 'SELECT VALUE FROM cartodb.CDB_CONF WHERE KEY = $1;' INTO value USING key; EXECUTE 'SELECT VALUE FROM cartodb.CDB_CONF WHERE KEY = $1;' INTO value USING key;
RETURN value; RETURN value;
END END
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;

View File

@ -12,7 +12,7 @@ BEGIN
RETURN output; RETURN output;
END; END;
$$ $$
LANGUAGE 'plpgsql' STABLE STRICT; LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;
-- Convert timestamp with time zone to double precision -- Convert timestamp with time zone to double precision
-- --
@ -28,4 +28,4 @@ BEGIN
RETURN output; RETURN output;
END; END;
$$ $$
LANGUAGE 'plpgsql' STABLE STRICT; LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;

View File

@ -50,4 +50,4 @@ BEGIN
END END
$$ $$
LANGUAGE 'plpgsql' STABLE STRICT; LANGUAGE 'plpgsql' STABLE STRICT PARALLEL SAFE;

View File

@ -65,7 +65,7 @@ BEGIN
RETURN signature; RETURN signature;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE STRICT PARALLEL SAFE;
-- Classify data into AJUSFL -- Classify data into AJUSFL
@ -119,4 +119,4 @@ BEGIN
RETURN type; RETURN type;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE STRICT PARALLEL SAFE;

View File

@ -43,4 +43,4 @@ BEGIN
RETURN passes; RETURN passes;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE PARALLEL SAFE;

View File

@ -19,6 +19,6 @@ SELECT array_agg(bins)
FROM ( FROM (
SELECT min + generate_series(1,breaks)*del AS bins SELECT min + generate_series(1,breaks)*del AS bins
FROM stats) q; FROM stats) q;
$$ LANGUAGE SQL IMMUTABLE; $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE;
DROP FUNCTION IF EXISTS CDB_EqualIntervalBins( numeric[], integer); DROP FUNCTION IF EXISTS CDB_EqualIntervalBins( numeric[], integer);

View File

@ -12,7 +12,7 @@ BEGIN
EXECUTE Format('ANALYZE %s;', reloid); EXECUTE Format('ANALYZE %s;', reloid);
END IF; END IF;
END END
$$ LANGUAGE 'plpgsql' VOLATILE STRICT SECURITY DEFINER; $$ LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL RESTRICTED SECURITY DEFINER;
-- Return a row count estimate of the result of a query using statistics -- Return a row count estimate of the result of a query using statistics
CREATE OR REPLACE FUNCTION CDB_EstimateRowCount(query text) CREATE OR REPLACE FUNCTION CDB_EstimateRowCount(query text)
@ -28,4 +28,4 @@ BEGIN
EXECUTE 'EXPLAIN (FORMAT JSON) ' || query INTO STRICT plan; EXECUTE 'EXPLAIN (FORMAT JSON) ' || query INTO STRICT plan;
RETURN plan->0->'Plan'->'Plan Rows'; RETURN plan->0->'Plan'->'Plan Rows';
END END
$$ LANGUAGE 'plpgsql' VOLATILE STRICT; $$ LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL RESTRICTED;

View File

@ -10,11 +10,11 @@ BEGIN
sql := 'ALTER EXTENSION cartodb UPDATE TO ''' || ver || ''''; sql := 'ALTER EXTENSION cartodb UPDATE TO ''' || ver || '''';
EXECUTE sql; EXECUTE sql;
END; END;
$$ language 'plpgsql' VOLATILE; $$ language 'plpgsql' VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cartodb.schema_exists(schema_name text) CREATE OR REPLACE FUNCTION cartodb.schema_exists(schema_name text)
RETURNS boolean AS RETURNS boolean AS
$$ $$
SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = schema_name::text); SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = schema_name::text);
$$ $$
language sql VOLATILE; language sql STABLE PARALLEL SAFE;

View File

@ -69,7 +69,7 @@ BEGIN
END END
$$ $$
LANGUAGE PLPGSQL; LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cartodb._CDB_Setup_FDWS() CREATE OR REPLACE FUNCTION cartodb._CDB_Setup_FDWS()
RETURNS VOID AS RETURNS VOID AS
@ -82,7 +82,7 @@ BEGIN
END LOOP; END LOOP;
END END
$$ $$
LANGUAGE PLPGSQL; LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cartodb._CDB_Setup_FDW(fdw_name text) CREATE OR REPLACE FUNCTION cartodb._CDB_Setup_FDW(fdw_name text)
@ -95,7 +95,7 @@ BEGIN
EXECUTE 'SELECT cartodb._CDB_Setup_FDW($1, $2)' USING fdw_name, config; EXECUTE 'SELECT cartodb._CDB_Setup_FDW($1, $2)' USING fdw_name, config;
END END
$BODY$ $BODY$
LANGUAGE plpgsql VOLATILE; LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cartodb.CDB_Add_Remote_Table(source text, table_name text) CREATE OR REPLACE FUNCTION cartodb.CDB_Add_Remote_Table(source text, table_name text)
RETURNS void AS RETURNS void AS
@ -107,7 +107,7 @@ BEGIN
EXECUTE FORMAT ('GRANT SELECT ON %I.%I TO publicuser;', source, table_name); EXECUTE FORMAT ('GRANT SELECT ON %I.%I TO publicuser;', source, table_name);
END END
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cartodb.CDB_Get_Foreign_Updated_At(foreign_table regclass) CREATE OR REPLACE FUNCTION cartodb.CDB_Get_Foreign_Updated_At(foreign_table regclass)
RETURNS timestamp with time zone AS RETURNS timestamp with time zone AS
@ -129,7 +129,7 @@ BEGIN
RETURN time; RETURN time;
END END
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION cartodb._cdb_dbname_of_foreign_table(reloid oid) CREATE OR REPLACE FUNCTION cartodb._cdb_dbname_of_foreign_table(reloid oid)
@ -142,7 +142,7 @@ RETURNS TEXT AS $$
WHERE ft.ftrelid = reloid WHERE ft.ftrelid = reloid
)) WHERE option_name='dbname'; )) WHERE option_name='dbname';
$$ LANGUAGE SQL; $$ LANGUAGE SQL VOLATILE PARALLEL UNSAFE;
-- Return a set of (dbname, schema_name, table_name, updated_at) -- Return a set of (dbname, schema_name, table_name, updated_at)
@ -176,7 +176,7 @@ AS $$
ELSE (SELECT md.updated_at FROM CDB_TableMetadata md WHERE md.tabname = reloid) ELSE (SELECT md.updated_at FROM CDB_TableMetadata md WHERE md.tabname = reloid)
END) AS updated_at END) AS updated_at
FROM fqtn; FROM fqtn;
$$ LANGUAGE SQL; $$ LANGUAGE SQL VOLATILE PARALLEL UNSAFE;
-- Return the last updated time of a set of tables -- Return the last updated time of a set of tables
@ -196,4 +196,4 @@ RETURNS timestamptz AS $$
FROM t_oid FROM t_oid
LEFT JOIN pg_catalog.pg_class c ON c.oid = reloid LEFT JOIN pg_catalog.pg_class c ON c.oid = reloid
) SELECT max(updated_at) FROM t_updated_at; ) SELECT max(updated_at) FROM t_updated_at;
$$ LANGUAGE SQL; $$ LANGUAGE SQL VOLATILE PARALLEL UNSAFE;

View File

@ -23,4 +23,4 @@ BEGIN
RETURN line; RETURN line;
END; END;
$$ $$
LANGUAGE 'plpgsql'; LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL SAFE;

View File

@ -15,7 +15,7 @@ BEGIN
EXECUTE format('CREATE ROLE %I NOLOGIN;', group_role); EXECUTE format('CREATE ROLE %I NOLOGIN;', group_role);
PERFORM cartodb._CDB_Group_CreateGroup_API(group_name, group_role); PERFORM cartodb._CDB_Group_CreateGroup_API(group_name, group_role);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Drops group and everything that role owns -- Drops group and everything that role owns
-- TODO: LIMITATION: in order to drop a role all its owned objects must be dropped before. -- TODO: LIMITATION: in order to drop a role all its owned objects must be dropped before.
@ -33,7 +33,7 @@ BEGIN
EXECUTE format('DROP ROLE IF EXISTS %I', group_role); EXECUTE format('DROP ROLE IF EXISTS %I', group_role);
PERFORM cartodb._CDB_Group_DropGroup_API(group_name); PERFORM cartodb._CDB_Group_DropGroup_API(group_name);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Renames a group -- Renames a group
CREATE OR REPLACE CREATE OR REPLACE
@ -48,7 +48,7 @@ BEGIN
EXECUTE format('ALTER ROLE %I RENAME TO %I', old_group_role, new_group_role); EXECUTE format('ALTER ROLE %I RENAME TO %I', old_group_role, new_group_role);
PERFORM cartodb._CDB_Group_RenameGroup_API(old_group_name, new_group_name, new_group_role); PERFORM cartodb._CDB_Group_RenameGroup_API(old_group_name, new_group_name, new_group_role);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Adds users to a group -- Adds users to a group
CREATE OR REPLACE CREATE OR REPLACE
@ -71,7 +71,7 @@ BEGIN
end loop; end loop;
PERFORM cartodb._CDB_Group_AddUsers_API(group_name, usernames); PERFORM cartodb._CDB_Group_AddUsers_API(group_name, usernames);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Removes users from a group -- Removes users from a group
CREATE OR REPLACE CREATE OR REPLACE
@ -90,7 +90,7 @@ BEGIN
end loop; end loop;
PERFORM cartodb._CDB_Group_RemoveUsers_API(group_name, usernames); PERFORM cartodb._CDB_Group_RemoveUsers_API(group_name, usernames);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
---------------------------------- ----------------------------------
-- TABLE MANAGEMENT FUNCTIONS -- TABLE MANAGEMENT FUNCTIONS
@ -107,7 +107,7 @@ DECLARE
BEGIN BEGIN
PERFORM cartodb._CDB_Group_Table_GrantRead(group_name, username, table_name, true); PERFORM cartodb._CDB_Group_Table_GrantRead(group_name, username, table_name, true);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_Table_GrantRead(group_name text, username text, table_name text, sync boolean) FUNCTION cartodb._CDB_Group_Table_GrantRead(group_name text, username text, table_name text, sync boolean)
@ -122,7 +122,7 @@ BEGIN
PERFORM cartodb._CDB_Group_Table_GrantPermission_API(group_name, username, table_name, 'r'); PERFORM cartodb._CDB_Group_Table_GrantPermission_API(group_name, username, table_name, 'r');
END IF; END IF;
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Grants table write permission to a group -- Grants table write permission to a group
CREATE OR REPLACE CREATE OR REPLACE
@ -133,7 +133,7 @@ DECLARE
BEGIN BEGIN
PERFORM cartodb._CDB_Group_Table_GrantReadWrite(group_name, username, table_name, true); PERFORM cartodb._CDB_Group_Table_GrantReadWrite(group_name, username, table_name, true);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_Table_GrantReadWrite(group_name text, username text, table_name text, sync boolean) FUNCTION cartodb._CDB_Group_Table_GrantReadWrite(group_name text, username text, table_name text, sync boolean)
@ -149,7 +149,7 @@ BEGIN
PERFORM cartodb._CDB_Group_Table_GrantPermission_API(group_name, username, table_name, 'w'); PERFORM cartodb._CDB_Group_Table_GrantPermission_API(group_name, username, table_name, 'w');
END IF; END IF;
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Granting and revoking permissions on sequences -- Granting and revoking permissions on sequences
CREATE OR REPLACE CREATE OR REPLACE
@ -175,7 +175,7 @@ BEGIN
END LOOP; END LOOP;
RETURN; RETURN;
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Revokes all permissions on a table from a group -- Revokes all permissions on a table from a group
CREATE OR REPLACE CREATE OR REPLACE
@ -186,7 +186,7 @@ DECLARE
BEGIN BEGIN
PERFORM cartodb._CDB_Group_Table_RevokeAll(group_name, username, table_name, true); PERFORM cartodb._CDB_Group_Table_RevokeAll(group_name, username, table_name, true);
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_Table_RevokeAll(group_name text, username text, table_name text, sync boolean) FUNCTION cartodb._CDB_Group_Table_RevokeAll(group_name text, username text, table_name text, sync boolean)
@ -201,7 +201,7 @@ BEGIN
PERFORM cartodb._CDB_Group_Table_RevokeAllPermission_API(group_name, username, table_name); PERFORM cartodb._CDB_Group_Table_RevokeAllPermission_API(group_name, username, table_name);
END IF; END IF;
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
----------------------- -----------------------
-- Helper functions -- Helper functions
@ -223,7 +223,7 @@ BEGIN
END IF; END IF;
RETURN group_role; RETURN group_role;
END END
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;
-- Returns the first owner of the schema matching username. Organization user schemas must have one only owner. -- Returns the first owner of the schema matching username. Organization user schemas must have one only owner.
CREATE OR REPLACE CREATE OR REPLACE
@ -237,7 +237,7 @@ BEGIN
SELECT pg_get_userbyid(nspowner) FROM pg_namespace WHERE nspname = username INTO user_role; SELECT pg_get_userbyid(nspowner) FROM pg_namespace WHERE nspname = username INTO user_role;
RETURN user_role; RETURN user_role;
END END
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;
-- Database names are too long, we need a shorter version for composing role names -- Database names are too long, we need a shorter version for composing role names
CREATE OR REPLACE CREATE OR REPLACE
@ -249,4 +249,4 @@ BEGIN
SELECT md5(current_database()) INTO short_database_name; SELECT md5(current_database()) INTO short_database_name;
RETURN short_database_name; RETURN short_database_name;
END END
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;

View File

@ -22,7 +22,7 @@ $$
body = '{ "name": "%s", "database_role": "%s" }' % (group_name, group_role) body = '{ "name": "%s", "database_role": "%s" }' % (group_name, group_role)
query = "select cartodb._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body) query = "select cartodb._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
plpy.execute(query) plpy.execute(query)
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_DropGroup_API(group_name text) FUNCTION cartodb._CDB_Group_DropGroup_API(group_name text)
@ -35,7 +35,7 @@ $$
query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '', '{204, 404}') as response_status" % url query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '', '{204, 404}') as response_status" % url
plpy.execute(query) plpy.execute(query)
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_RenameGroup_API(old_group_name text, new_group_name text, new_group_role text) FUNCTION cartodb._CDB_Group_RenameGroup_API(old_group_name text, new_group_name text, new_group_role text)
@ -48,7 +48,7 @@ $$
body = '{ "name": "%s", "database_role": "%s" }' % (new_group_name, new_group_role) body = '{ "name": "%s", "database_role": "%s" }' % (new_group_name, new_group_role)
query = "select cartodb._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body) query = "select cartodb._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body)
plpy.execute(query) plpy.execute(query)
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_AddUsers_API(group_name text, usernames text[]) FUNCTION cartodb._CDB_Group_AddUsers_API(group_name text, usernames text[])
@ -74,7 +74,7 @@ $$
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames) body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '%s', '{200, 404}') as response_status" % (url, body) query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '%s', '{200, 404}') as response_status" % (url, body)
plpy.execute(query) plpy.execute(query)
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
DO LANGUAGE 'plpgsql' $$ DO LANGUAGE 'plpgsql' $$
BEGIN BEGIN
@ -95,7 +95,7 @@ $$
body = '{ "access": "%s" }' % access body = '{ "access": "%s" }' % access
query = "select cartodb._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body) query = "select cartodb._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body)
plpy.execute(query) plpy.execute(query)
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
DO LANGUAGE 'plpgsql' $$ DO LANGUAGE 'plpgsql' $$
BEGIN BEGIN
@ -115,7 +115,7 @@ $$
url = '/api/v1/databases/{0}/groups/%s/permission/%s/tables/%s' % (urllib.pathname2url(group_name), username, table_name) url = '/api/v1/databases/{0}/groups/%s/permission/%s/tables/%s' % (urllib.pathname2url(group_name), username, table_name)
query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '', '{200, 404}') as response_status" % url query = "select cartodb._CDB_Group_API_Request('DELETE', '%s', '', '{200, 404}') as response_status" % url
plpy.execute(query) plpy.execute(query)
$$ LANGUAGE 'plpythonu' VOLATILE SECURITY DEFINER; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
DO LANGUAGE 'plpgsql' $$ DO LANGUAGE 'plpgsql' $$
BEGIN BEGIN
@ -146,7 +146,7 @@ $$
params = json.loads(conf) params = json.loads(conf)
auth = 'Basic %s' % plpy.execute("SELECT cartodb._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth'] auth = 'Basic %s' % plpy.execute("SELECT cartodb._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth']
return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'auth': auth } return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'auth': auth }
$$ LANGUAGE 'plpythonu' VOLATILE; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb._CDB_Group_API_Auth(username text, password text) FUNCTION cartodb._CDB_Group_API_Auth(username text, password text)
@ -154,7 +154,7 @@ FUNCTION cartodb._CDB_Group_API_Auth(username text, password text)
$$ $$
import base64 import base64
return base64.encodestring('%s:%s' % (username, password)).replace('\n', '') return base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
$$ LANGUAGE 'plpythonu' VOLATILE; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
-- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons. -- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons.
CREATE OR REPLACE CREATE OR REPLACE
@ -191,5 +191,5 @@ $$
raise last_err raise last_err
return None return None
$$ LANGUAGE 'plpythonu' VOLATILE; $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
revoke all on function cartodb._CDB_Group_API_Request(text, text, text, int[]) from public; revoke all on function cartodb._CDB_Group_API_Request(text, text, text, int[]) from public;

View File

@ -43,4 +43,4 @@ BEGIN
END LOOP; END LOOP;
RETURN reply; RETURN reply;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE PARALLEL SAFE;

View File

@ -61,7 +61,7 @@ BEGIN
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Identifier'); PERFORM _CDB_Error('looping too far', '_CDB_Unique_Identifier');
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
-- UTF8 safe and length aware. Find a unique identifier for a column with a given prefix -- UTF8 safe and length aware. Find a unique identifier for a column with a given prefix
@ -116,7 +116,7 @@ BEGIN
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Column_Identifier'); PERFORM _CDB_Error('looping too far', '_CDB_Unique_Column_Identifier');
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' VOLATILE PARALLEL SAFE;
-- Truncates a given string to a max_octets octets taking care -- Truncates a given string to a max_octets octets taking care
@ -157,4 +157,4 @@ BEGIN
RETURN left(string, (i - 1)); RETURN left(string, (i - 1));
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql' IMMUTABLE PARALLEL SAFE;

View File

@ -8,7 +8,7 @@ AS $$
SELECT (ST_DumpPoints(ST_ExteriorRing(ST_Buffer($1, $2, 3)))).* SELECT (ST_DumpPoints(ST_ExteriorRing(ST_Buffer($1, $2, 3)))).*
) as points ) as points
WHERE path[1] % 2 != 0 WHERE path[1] % 2 != 0
$$ LANGUAGE 'sql' IMMUTABLE STRICT; $$ LANGUAGE 'sql' IMMUTABLE STRICT PARALLEL SAFE;
-- --
-- Fill given extent with an hexagonal coverage -- Fill given extent with an hexagonal coverage
@ -132,4 +132,4 @@ BEGIN
RETURN; RETURN;
END END
$$ LANGUAGE 'plpgsql' IMMUTABLE; $$ LANGUAGE 'plpgsql' IMMUTABLE PARALLEL SAFE;

View File

@ -117,7 +117,7 @@ BEGIN
RETURN (best_result)[2:array_upper(best_result, 1)]; RETURN (best_result)[2:array_upper(best_result, 1)];
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE PARALLEL RESTRICTED;
@ -217,5 +217,5 @@ BEGIN
RETURN array_prepend(gvf, reply); RETURN array_prepend(gvf, reply);
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE PARALLEL SAFE;

View File

@ -10,10 +10,10 @@
CREATE OR REPLACE FUNCTION CDB_LatLng (lat NUMERIC, lng NUMERIC) RETURNS geometry as $$ CREATE OR REPLACE FUNCTION CDB_LatLng (lat NUMERIC, lng NUMERIC) RETURNS geometry as $$
-- this function is silly -- this function is silly
SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326); SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326);
$$ language SQL IMMUTABLE; $$ language SQL IMMUTABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION CDB_LatLng (lat FLOAT8, lng FLOAT8) RETURNS geometry as $$ CREATE OR REPLACE FUNCTION CDB_LatLng (lat FLOAT8, lng FLOAT8) RETURNS geometry as $$
-- this function is silly -- this function is silly
SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326); SELECT ST_SetSRID(ST_MakePoint(lng,lat),4326);
$$ language SQL IMMUTABLE; $$ language SQL IMMUTABLE PARALLEL SAFE;

View File

@ -13,7 +13,7 @@ $BODY$
ORDER BY COUNT(1) DESC, 1 ORDER BY COUNT(1) DESC, 1
LIMIT 1; LIMIT 1;
$BODY$ $BODY$
LANGUAGE 'sql' IMMUTABLE; LANGUAGE 'sql' IMMUTABLE PARALLEL SAFE;
DROP AGGREGATE IF EXISTS cartodb.CDB_Math_Mode(anyelement); DROP AGGREGATE IF EXISTS cartodb.CDB_Math_Mode(anyelement);
@ -21,6 +21,7 @@ CREATE AGGREGATE cartodb.CDB_Math_Mode(anyelement) (
SFUNC=array_append, SFUNC=array_append,
STYPE=anyarray, STYPE=anyarray,
FINALFUNC=_CDB_Math_final_mode, FINALFUNC=_CDB_Math_final_mode,
INITCOND='{}' INITCOND='{}',
PARALLEL = SAFE
); );

View File

@ -4,7 +4,7 @@ FUNCTION cartodb.CDB_Organization_Member_Group_Role_Member_Name()
AS $$ AS $$
SELECT 'cdb_org_member'::text || '_' || md5(current_database()); SELECT 'cdb_org_member'::text || '_' || md5(current_database());
$$ $$
LANGUAGE SQL IMMUTABLE; LANGUAGE SQL STABLE PARALLEL SAFE;
DO LANGUAGE 'plpgsql' $$ DO LANGUAGE 'plpgsql' $$
DECLARE DECLARE
@ -25,7 +25,7 @@ AS $$
BEGIN BEGIN
EXECUTE 'GRANT "' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || '" TO "' || role_name || '"'; EXECUTE 'GRANT "' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || '" TO "' || role_name || '"';
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Administrator -- Administrator
@ -36,7 +36,7 @@ FUNCTION cartodb._CDB_Organization_Admin_Role_Name()
AS $$ AS $$
SELECT current_database() || '_a'::text; SELECT current_database() || '_a'::text;
$$ $$
LANGUAGE SQL IMMUTABLE; LANGUAGE SQL STABLE PARALLEL SAFE;
-- Administrator role creation on extension install -- Administrator role creation on extension install
DO LANGUAGE 'plpgsql' $$ DO LANGUAGE 'plpgsql' $$
@ -65,7 +65,7 @@ BEGIN
-- CREATEROLE is not inherited, and is needed for user creation -- CREATEROLE is not inherited, and is needed for user creation
EXECUTE format('ALTER ROLE %I CREATEROLE', cdb_user_role); EXECUTE format('ALTER ROLE %I CREATEROLE', cdb_user_role);
END END
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Organization_RemoveAdmin(username text) FUNCTION cartodb.CDB_Organization_RemoveAdmin(username text)
@ -80,7 +80,7 @@ BEGIN
EXECUTE format('ALTER ROLE %I NOCREATEROLE', cdb_user_role); EXECUTE format('ALTER ROLE %I NOCREATEROLE', cdb_user_role);
EXECUTE format('REVOKE %I FROM %I', cdb_admin_role, cdb_user_role); EXECUTE format('REVOKE %I FROM %I', cdb_admin_role, cdb_user_role);
END END
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Sharing tables -- Sharing tables
@ -93,7 +93,7 @@ BEGIN
EXECUTE 'GRANT USAGE ON SCHEMA "' || from_schema || '" TO "' || to_role_name || '"'; EXECUTE 'GRANT USAGE ON SCHEMA "' || from_schema || '" TO "' || to_role_name || '"';
EXECUTE 'GRANT SELECT ON "' || from_schema || '"."' || table_name || '" TO "' || to_role_name || '"'; EXECUTE 'GRANT SELECT ON "' || from_schema || '"."' || table_name || '" TO "' || to_role_name || '"';
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Organization_Add_Table_Organization_Read_Permission(from_schema text, table_name text) FUNCTION cartodb.CDB_Organization_Add_Table_Organization_Read_Permission(from_schema text, table_name text)
@ -102,7 +102,7 @@ AS $$
BEGIN BEGIN
EXECUTE 'SELECT cartodb.CDB_Organization_Add_Table_Read_Permission(''' || from_schema || ''', ''' || table_name || ''', ''' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || ''');'; EXECUTE 'SELECT cartodb.CDB_Organization_Add_Table_Read_Permission(''' || from_schema || ''', ''' || table_name || ''', ''' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || ''');';
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Organization_Add_Table_Read_Write_Permission(from_schema text, table_name text, to_role_name text) FUNCTION cartodb.CDB_Organization_Add_Table_Read_Write_Permission(from_schema text, table_name text, to_role_name text)
@ -112,7 +112,7 @@ BEGIN
EXECUTE 'GRANT USAGE ON SCHEMA "' || from_schema || '" TO "' || to_role_name || '"'; EXECUTE 'GRANT USAGE ON SCHEMA "' || from_schema || '" TO "' || to_role_name || '"';
EXECUTE 'GRANT SELECT, INSERT, UPDATE, DELETE ON "' || from_schema || '"."' || table_name || '" TO "' || to_role_name || '"'; EXECUTE 'GRANT SELECT, INSERT, UPDATE, DELETE ON "' || from_schema || '"."' || table_name || '" TO "' || to_role_name || '"';
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Organization_Add_Table_Organization_Read_Write_Permission(from_schema text, table_name text) FUNCTION cartodb.CDB_Organization_Add_Table_Organization_Read_Write_Permission(from_schema text, table_name text)
@ -121,7 +121,7 @@ AS $$
BEGIN BEGIN
EXECUTE 'SELECT cartodb.CDB_Organization_Add_Table_Read_Write_Permission(''' || from_schema || ''', ''' || table_name || ''', ''' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || ''');'; EXECUTE 'SELECT cartodb.CDB_Organization_Add_Table_Read_Write_Permission(''' || from_schema || ''', ''' || table_name || ''', ''' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || ''');';
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
@ -134,7 +134,7 @@ BEGIN
-- We need to revoke usage on schema only if we are revoking privileges from the last table where to_role_name has -- We need to revoke usage on schema only if we are revoking privileges from the last table where to_role_name has
-- any permission granted within the schema from_schema -- any permission granted within the schema from_schema
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE CREATE OR REPLACE
FUNCTION cartodb.CDB_Organization_Remove_Organization_Access_Permission(from_schema text, table_name text) FUNCTION cartodb.CDB_Organization_Remove_Organization_Access_Permission(from_schema text, table_name text)
@ -143,4 +143,4 @@ AS $$
BEGIN BEGIN
EXECUTE 'SELECT cartodb.CDB_Organization_Remove_Access_Permission(''' || from_schema || ''', ''' || table_name || ''', ''' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || ''');'; EXECUTE 'SELECT cartodb.CDB_Organization_Remove_Access_Permission(''' || from_schema || ''', ''' || table_name || ''', ''' || cartodb.CDB_Organization_Member_Group_Role_Member_Name() || ''');';
END END
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;

View File

@ -18,7 +18,7 @@ BEGIN
RAISE NOTICE 'Dropped overview for level %: %', row.z, row.overview_table; RAISE NOTICE 'Dropped overview for level %: %', row.z, row.overview_table;
END LOOP; END LOOP;
END; END;
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
@ -45,7 +45,7 @@ AS $$
WHERE _CDB_IsOverviewTableOf((SELECT relname FROM pg_class WHERE oid=reloid), table_name) WHERE _CDB_IsOverviewTableOf((SELECT relname FROM pg_class WHERE oid=reloid), table_name)
ORDER BY z; ORDER BY z;
END END
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL STABLE PARALLEL RESTRICTED;
-- Return existing overviews (if any) for multiple dataset tables. -- Return existing overviews (if any) for multiple dataset tables.
-- Scope: public -- Scope: public
@ -69,7 +69,7 @@ AS $$
schema_name = _cdb_schema_name(base_table) schema_name = _cdb_schema_name(base_table)
AND _CDB_IsOverviewTableOf((SELECT relname FROM pg_class WHERE oid=base_table), table_name) AND _CDB_IsOverviewTableOf((SELECT relname FROM pg_class WHERE oid=base_table), table_name)
ORDER BY base_table, z; ORDER BY base_table, z;
$$ LANGUAGE SQL; $$ LANGUAGE SQL STABLE PARALLEL SAFE;
-- Calculate the estimated extent of a cartodbfy'ed table. -- Calculate the estimated extent of a cartodbfy'ed table.
-- Scope: private. -- Scope: private.
@ -111,7 +111,7 @@ AS $$
RETURN ext; RETURN ext;
END; END;
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Determine the max feature density of a given dataset. -- Determine the max feature density of a given dataset.
-- Scope: private. -- Scope: private.
@ -187,7 +187,7 @@ AS $$
INTO fd; INTO fd;
RETURN fd; RETURN fd;
END END
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Experimental default strategy to assign a reference base Z level -- Experimental default strategy to assign a reference base Z level
-- to a cartodbfied table. The resulting Z level represents the -- to a cartodbfied table. The resulting Z level represents the
@ -223,7 +223,7 @@ AS $$
SELECT CDB_XYZ_Resolution(-8) INTO c; SELECT CDB_XYZ_Resolution(-8) INTO c;
RETURN least(_CDB_MaxOverviewLevel()+1, ceil(log(2.0, (c*c*fd/lim)::numeric)/2)); RETURN least(_CDB_MaxOverviewLevel()+1, ceil(log(2.0, (c*c*fd/lim)::numeric)/2));
END; END;
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Overview table name for a given Z level and base dataset or overview table -- Overview table name for a given Z level and base dataset or overview table
-- Scope: private. -- Scope: private.
@ -247,7 +247,7 @@ AS $$
SELECT _CDB_OverviewBaseTableName(base) INTO base; SELECT _CDB_OverviewBaseTableName(base) INTO base;
RETURN _CDB_OverviewTableName(base, overview_z); RETURN _CDB_OverviewTableName(base, overview_z);
END END
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Sampling reduction method. -- Sampling reduction method.
-- Valid for any kind of geometry. -- Valid for any kind of geometry.
@ -310,7 +310,7 @@ AS $$
RETURN Format('%s', overview_table_name)::regclass; RETURN Format('%s', overview_table_name)::regclass;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Register new overview table (post-creation chores) -- Register new overview table (post-creation chores)
-- Scope: private -- Scope: private
@ -365,7 +365,7 @@ AS $$
-- it should be done here (CDB_Overviews would consume such metadata) -- it should be done here (CDB_Overviews would consume such metadata)
END IF; END IF;
END END
$$ LANGUAGE PLPGSQL SECURITY DEFINER; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- Dataset attributes (column names other than the -- Dataset attributes (column names other than the
-- CartoDB primary key and geometry columns) which should be aggregated -- CartoDB primary key and geometry columns) which should be aggregated
@ -381,7 +381,7 @@ AS $$
WHERE c NOT IN ( WHERE c NOT IN (
cdb.pkey, cdb.geomcol, cdb.mercgeomcol cdb.pkey, cdb.geomcol, cdb.mercgeomcol
) )
$$ LANGUAGE SQL STABLE; $$ LANGUAGE SQL STABLE PARALLEL SAFE;
-- List of dataset attributes to be aggregated in aggregated overview -- List of dataset attributes to be aggregated in aggregated overview
-- as a comma-separated SQL expression. -- as a comma-separated SQL expression.
@ -401,7 +401,7 @@ BEGIN
RETURN attr_list; RETURN attr_list;
END END
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;
-- Check if a column of a table is of an unlimited-length text type -- Check if a column of a table is of an unlimited-length text type
CREATE OR REPLACE FUNCTION _cdb_unlimited_text_column(reloid REGCLASS, col_name TEXT) CREATE OR REPLACE FUNCTION _cdb_unlimited_text_column(reloid REGCLASS, col_name TEXT)
@ -417,7 +417,7 @@ AS $$
AND format_type(a.atttypid, NULL) IN ('text', 'character varying', 'character') AND format_type(a.atttypid, NULL) IN ('text', 'character varying', 'character')
AND format_type(a.atttypid, NULL) = format_type(a.atttypid, a.atttypmod) AND format_type(a.atttypid, NULL) = format_type(a.atttypid, a.atttypmod)
); );
$$ LANGUAGE SQL STABLE; $$ LANGUAGE SQL STABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION _cdb_categorical_column(reloid REGCLASS, col_name TEXT) CREATE OR REPLACE FUNCTION _cdb_categorical_column(reloid REGCLASS, col_name TEXT)
RETURNS BOOLEAN RETURNS BOOLEAN
@ -446,7 +446,7 @@ BEGIN
INTO categorical; INTO categorical;
RETURN categorical; RETURN categorical;
END; END;
$$ LANGUAGE PLPGSQL VOLATILE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION _cdb_mode_of_array(anyarray) CREATE OR REPLACE FUNCTION _cdb_mode_of_array(anyarray)
RETURNS anyelement AS RETURNS anyelement AS
@ -457,14 +457,15 @@ $$
ORDER BY COUNT(1) DESC, 1 ORDER BY COUNT(1) DESC, 1
LIMIT 1; LIMIT 1;
$$ $$
LANGUAGE SQL IMMUTABLE; LANGUAGE SQL IMMUTABLE PARALLEL SAFE;
DROP AGGREGATE IF EXISTS _cdb_mode(anyelement); DROP AGGREGATE IF EXISTS _cdb_mode(anyelement);
CREATE AGGREGATE _cdb_mode(anyelement) ( CREATE AGGREGATE _cdb_mode(anyelement) (
SFUNC=array_append, SFUNC=array_append,
STYPE=anyarray, STYPE=anyarray,
FINALFUNC=_cdb_mode_of_array, FINALFUNC=_cdb_mode_of_array,
INITCOND='{}' INITCOND='{}',
PARALLEL = SAFE
); );
-- SQL Aggregation expression for a datase attribute -- SQL Aggregation expression for a datase attribute
@ -536,7 +537,7 @@ BEGIN
RETURN 'CASE count(*) WHEN 1 THEN MIN(' || qualified_column || ') ELSE NULL END::' || column_type; RETURN 'CASE count(*) WHEN 1 THEN MIN(' || qualified_column || ') ELSE NULL END::' || column_type;
END CASE; END CASE;
END END
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL RESTRICTED;
-- List of dataset aggregated attributes as a comma-separated SQL expression. -- List of dataset aggregated attributes as a comma-separated SQL expression.
-- Scope: private. -- Scope: private.
@ -557,7 +558,7 @@ BEGIN
RETURN attr_list; RETURN attr_list;
END END
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL RESTRICTED;
-- Array of geometry types detected in a cartodbfied table -- Array of geometry types detected in a cartodbfied table
-- For effciency only look at a limited number of rwos. -- For effciency only look at a limited number of rwos.
@ -579,7 +580,7 @@ BEGIN
INTO gtypes; INTO gtypes;
RETURN gtypes; RETURN gtypes;
END END
$$ LANGUAGE PLPGSQL STABLE; $$ LANGUAGE PLPGSQL STABLE PARALLEL SAFE;
-- Experimental Overview reduction method for point datasets. -- Experimental Overview reduction method for point datasets.
-- It clusters the points using a grid, then aggregates the point in each -- It clusters the points using a grid, then aggregates the point in each
@ -715,7 +716,7 @@ AS $$
RETURN Format('%s', overview_table_name)::regclass; RETURN Format('%s', overview_table_name)::regclass;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- This strategy places the aggregation of each cluster at the centroid of the cluster members. -- This strategy places the aggregation of each cluster at the centroid of the cluster members.
CREATE OR REPLACE FUNCTION _CDB_GridClusterCentroid_Reduce_Strategy(reloid REGCLASS, ref_z INTEGER, overview_z INTEGER, grid_px FLOAT8 DEFAULT NULL, has_overview_created BOOLEAN DEFAULT FALSE) CREATE OR REPLACE FUNCTION _CDB_GridClusterCentroid_Reduce_Strategy(reloid REGCLASS, ref_z INTEGER, overview_z INTEGER, grid_px FLOAT8 DEFAULT NULL, has_overview_created BOOLEAN DEFAULT FALSE)
@ -843,7 +844,7 @@ AS $$
RETURN Format('%s', overview_table_name)::regclass; RETURN Format('%s', overview_table_name)::regclass;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- This strategy places the aggregation of each cluster at the position of one of the cluster members. -- This strategy places the aggregation of each cluster at the position of one of the cluster members.
CREATE OR REPLACE FUNCTION _CDB_GridClusterSample_Reduce_Strategy(reloid REGCLASS, ref_z INTEGER, overview_z INTEGER, grid_px FLOAT8 DEFAULT NULL, has_overview_created BOOLEAN DEFAULT FALSE) CREATE OR REPLACE FUNCTION _CDB_GridClusterSample_Reduce_Strategy(reloid REGCLASS, ref_z INTEGER, overview_z INTEGER, grid_px FLOAT8 DEFAULT NULL, has_overview_created BOOLEAN DEFAULT FALSE)
@ -969,7 +970,7 @@ AS $$
RETURN Format('%s', overview_table_name)::regclass; RETURN Format('%s', overview_table_name)::regclass;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Create overview tables for a dataset. -- Create overview tables for a dataset.
-- Scope: public -- Scope: public
@ -992,7 +993,7 @@ BEGIN
tolerance_px := 1.0; tolerance_px := 1.0;
RETURN CDB_CreateOverviewsWithToleranceInPixels(reloid, tolerance_px, refscale_strategy, reduce_strategy); RETURN CDB_CreateOverviewsWithToleranceInPixels(reloid, tolerance_px, refscale_strategy, reduce_strategy);
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Create overviews with additional parameter to define the desired detail/tolerance in pixels -- Create overviews with additional parameter to define the desired detail/tolerance in pixels
CREATE OR REPLACE FUNCTION CDB_CreateOverviewsWithToleranceInPixels(reloid REGCLASS, tolerance_px FLOAT8, refscale_strategy regproc DEFAULT '_CDB_Feature_Density_Ref_Z_Strategy(REGCLASS,FLOAT8)'::regprocedure, reduce_strategy regproc DEFAULT '_CDB_GridCluster_Reduce_Strategy(REGCLASS,INTEGER,INTEGER,FLOAT8,BOOLEAN)'::regprocedure) CREATE OR REPLACE FUNCTION CDB_CreateOverviewsWithToleranceInPixels(reloid REGCLASS, tolerance_px FLOAT8, refscale_strategy regproc DEFAULT '_CDB_Feature_Density_Ref_Z_Strategy(REGCLASS,FLOAT8)'::regprocedure, reduce_strategy regproc DEFAULT '_CDB_GridCluster_Reduce_Strategy(REGCLASS,INTEGER,INTEGER,FLOAT8,BOOLEAN)'::regprocedure)
@ -1058,7 +1059,7 @@ BEGIN
RETURN overview_tables; RETURN overview_tables;
END; END;
$$ LANGUAGE PLPGSQL; $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
-- Here are some older signatures of these functions, no longer in use. -- Here are some older signatures of these functions, no longer in use.
-- They must be droped here, after the (new) definition of the function `CDB_CreateOverviews` -- They must be droped here, after the (new) definition of the function `CDB_CreateOverviews`

View File

@ -15,7 +15,7 @@ AS $$
-- (gridding), so we'll limit Z to a maximum of 31 - 8 -- (gridding), so we'll limit Z to a maximum of 31 - 8
RETURN 23; RETURN 23;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Maximum zoom level usable with integer coordinates -- Maximum zoom level usable with integer coordinates
CREATE OR REPLACE FUNCTION _CDB_MaxZoomLevel() CREATE OR REPLACE FUNCTION _CDB_MaxZoomLevel()
@ -24,7 +24,7 @@ AS $$
BEGIN BEGIN
RETURN 31; RETURN 31;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Information about tables in a schema. -- Information about tables in a schema.
-- If the schema name parameter is NULL, then tables from all schemas -- If the schema name parameter is NULL, then tables from all schemas
@ -46,7 +46,7 @@ AS $$
THEN n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb') THEN n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb')
ELSE n.nspname = schema_name ELSE n.nspname = schema_name
END; END;
$$ LANGUAGE 'sql'; $$ LANGUAGE 'sql' STABLE PARALLEL SAFE;
-- Pattern that can be used to detect overview tables and Extract -- Pattern that can be used to detect overview tables and Extract
-- the intended zoom level from the table name. -- the intended zoom level from the table name.
@ -57,7 +57,7 @@ AS $$
BEGIN BEGIN
RETURN '\A_vovw_(\d+)_'; RETURN '\A_vovw_(\d+)_';
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- substring(tablename from _CDB_OverviewTableDiscriminator()) -- substring(tablename from _CDB_OverviewTableDiscriminator())
@ -69,7 +69,7 @@ AS $$
BEGIN BEGIN
RETURN _CDB_OverviewTableDiscriminator() || base_table; RETURN _CDB_OverviewTableDiscriminator() || base_table;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- tablename SIMILAR TO _CDB_OverviewTablePattern(base_table) -- tablename SIMILAR TO _CDB_OverviewTablePattern(base_table)
-- Name of an overview table, given the base table name and the Z level -- Name of an overview table, given the base table name and the Z level
@ -80,7 +80,7 @@ AS $$
BEGIN BEGIN
RETURN '_vovw_' || z::text || '_' || base_table; RETURN '_vovw_' || z::text || '_' || base_table;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Condition to check if a tabla is an overview table of some base table -- Condition to check if a tabla is an overview table of some base table
-- Scope: private. -- Scope: private.
@ -90,7 +90,7 @@ AS $$
BEGIN BEGIN
RETURN otable SIMILAR TO _CDB_OverviewTablePattern(base_table); RETURN otable SIMILAR TO _CDB_OverviewTablePattern(base_table);
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Extract the Z level from an overview table name -- Extract the Z level from an overview table name
-- Scope: private. -- Scope: private.
@ -100,7 +100,7 @@ AS $$
BEGIN BEGIN
RETURN substring(otable from _CDB_OverviewTableDiscriminator())::integer; RETURN substring(otable from _CDB_OverviewTableDiscriminator())::integer;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Name of the base table corresponding to an overview table -- Name of the base table corresponding to an overview table
-- Scope: private. -- Scope: private.
@ -114,7 +114,7 @@ AS $$
RETURN regexp_replace(overview_table, _CDB_OverviewTableDiscriminator(), ''); RETURN regexp_replace(overview_table, _CDB_OverviewTableDiscriminator(), '');
END IF; END IF;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION _CDB_OverviewBaseTable(overview_table REGCLASS) CREATE OR REPLACE FUNCTION _CDB_OverviewBaseTable(overview_table REGCLASS)
RETURNS REGCLASS RETURNS REGCLASS
@ -134,7 +134,7 @@ AS $$
END IF; END IF;
RETURN base_table; RETURN base_table;
END; END;
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Schema and relation names of a table given its reloid -- Schema and relation names of a table given its reloid
-- Scope: private. -- Scope: private.
@ -150,7 +150,7 @@ AS $$
FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE c.oid = reloid; WHERE c.oid = reloid;
END END
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;
-- Schema and relation names of a table given its reloid -- Schema and relation names of a table given its reloid
-- Scope: private. -- Scope: private.
@ -170,4 +170,4 @@ AS $$
WHERE c.oid = reloid; WHERE c.oid = reloid;
RETURN schema_name; RETURN schema_name;
END END
$$ LANGUAGE PLPGSQL IMMUTABLE; $$ LANGUAGE PLPGSQL IMMUTABLE PARALLEL SAFE;

View File

@ -40,4 +40,4 @@ BEGIN
END LOOP; END LOOP;
RETURN reply; RETURN reply;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE STRICT PARALLEL SAFE;

View File

@ -11,4 +11,4 @@ RETURNS SETOF TEXT AS $$
cleaned = match[0].strip() cleaned = match[0].strip()
if ( cleaned ): if ( cleaned ):
yield cleaned yield cleaned
$$ language 'plpythonu' IMMUTABLE STRICT; $$ language 'plpythonu' IMMUTABLE STRICT PARALLEL SAFE;

View File

@ -64,7 +64,7 @@ BEGIN
return tables; return tables;
END END
$$ LANGUAGE 'plpgsql' VOLATILE STRICT; $$ LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL UNSAFE;
-- Keep CDB_QueryTables with same signature for backwards compatibility. -- Keep CDB_QueryTables with same signature for backwards compatibility.
@ -75,4 +75,4 @@ AS $$
BEGIN BEGIN
RETURN CDB_QueryTablesText(query)::name[]; RETURN CDB_QueryTablesText(query)::name[];
END END
$$ LANGUAGE 'plpgsql' VOLATILE STRICT; $$ LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL UNSAFE;

View File

@ -12,7 +12,7 @@ BEGIN
RETURN relation_size; RETURN relation_size;
END; END;
$$ $$
LANGUAGE 'plpgsql' VOLATILE; LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
-- Return the estimated size of user data. Used for quota checking. -- Return the estimated size of user data. Used for quota checking.
CREATE OR REPLACE FUNCTION CDB_UserDataSize(schema_name TEXT) CREATE OR REPLACE FUNCTION CDB_UserDataSize(schema_name TEXT)
@ -55,7 +55,7 @@ BEGIN
END IF; END IF;
END; END;
$$ $$
LANGUAGE 'plpgsql' VOLATILE; LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
-- Return the estimated size of user data. Used for quota checking. -- Return the estimated size of user data. Used for quota checking.
@ -65,7 +65,7 @@ RETURNS bigint AS
$$ $$
SELECT CDB_UserDataSize('public'); SELECT CDB_UserDataSize('public');
$$ $$
LANGUAGE 'sql' VOLATILE; LANGUAGE 'sql' VOLATILE PARALLEL UNSAFE;
-- Triggers cannot have declared arguments: pbfact float8, qmax int8, schema_name text -- Triggers cannot have declared arguments: pbfact float8, qmax int8, schema_name text
CREATE OR REPLACE FUNCTION CDB_CheckQuota() CREATE OR REPLACE FUNCTION CDB_CheckQuota()
@ -121,7 +121,7 @@ BEGIN
RETURN NEW; RETURN NEW;
END; END;
$$ $$
LANGUAGE 'plpgsql' VOLATILE; LANGUAGE 'plpgsql' VOLATILE PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION CDB_SetUserQuotaInBytes(schema_name text, bytes int8) CREATE OR REPLACE FUNCTION CDB_SetUserQuotaInBytes(schema_name text, bytes int8)
@ -142,7 +142,7 @@ BEGIN
return bytes; return bytes;
END END
$$ $$
LANGUAGE 'plpgsql' VOLATILE STRICT; LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL UNSAFE;
CREATE OR REPLACE FUNCTION CDB_SetUserQuotaInBytes(bytes int8) CREATE OR REPLACE FUNCTION CDB_SetUserQuotaInBytes(bytes int8)
@ -152,4 +152,4 @@ BEGIN
return public.CDB_SetUserQuotaInBytes('public', bytes); return public.CDB_SetUserQuotaInBytes('public', bytes);
END; END;
$$ $$
LANGUAGE 'plpgsql' VOLATILE STRICT; LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL UNSAFE;

View File

@ -64,6 +64,6 @@ BEGIN
RETURN tidlist; RETURN tidlist;
END END
$$ LANGUAGE 'plpgsql' STABLE STRICT; $$ LANGUAGE 'plpgsql' STABLE STRICT PARALLEL SAFE;
-- } -- }

View File

@ -6,7 +6,7 @@
-- be emitted. The returned hexagons will have the same SRID -- be emitted. The returned hexagons will have the same SRID
-- as this extent. -- as this extent.
-- --
-- @param width With of each rectangle -- @param width Width of each rectangle
-- --
-- @param height Height of each rectangle -- @param height Height of each rectangle
-- --
@ -93,4 +93,4 @@ BEGIN
RETURN; RETURN;
END END
$$ LANGUAGE 'plpgsql' IMMUTABLE; $$ LANGUAGE 'plpgsql' IMMUTABLE PARALLEL SAFE;

View File

@ -29,7 +29,7 @@ BEGIN
RETURN k; RETURN k;
END IF; END IF;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE STRICT PARALLEL SAFE;
-- Calculate skewness -- Calculate skewness
CREATE OR REPLACE FUNCTION CDB_Skewness ( in_array NUMERIC[] ) RETURNS NUMERIC as $$ CREATE OR REPLACE FUNCTION CDB_Skewness ( in_array NUMERIC[] ) RETURNS NUMERIC as $$
@ -50,4 +50,4 @@ BEGIN
RETURN sk; RETURN sk;
END IF; END IF;
END; END;
$$ language plpgsql IMMUTABLE; $$ language plpgsql IMMUTABLE STRICT PARALLEL SAFE;

View File

@ -17,4 +17,4 @@ BEGIN
RETURN output; RETURN output;
END; END;
$$ $$
LANGUAGE 'plpgsql' STABLE STRICT; LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;

View File

@ -20,7 +20,7 @@ AS $$
AND pg_class.relname=pg_indexes.indexname AND pg_class.relname=pg_indexes.indexname
; ;
$$ LANGUAGE SQL; $$ LANGUAGE SQL STABLE PARALLEL SAFE;
-- This is to migrate from pre-0.2.0 version -- This is to migrate from pre-0.2.0 version
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36 -- See http://github.com/CartoDB/cartodb-postgresql/issues/36

View File

@ -56,7 +56,7 @@ BEGIN
RETURN NULL; RETURN NULL;
END; END;
$$ $$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- --
-- Trigger invalidating varnish whenever CDB_TableMetadata -- Trigger invalidating varnish whenever CDB_TableMetadata
@ -117,7 +117,7 @@ BEGIN
RETURN NULL; RETURN NULL;
END; END;
$$ $$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER; LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
DROP TRIGGER IF EXISTS table_modified ON public.CDB_TableMetadata; DROP TRIGGER IF EXISTS table_modified ON public.CDB_TableMetadata;
-- NOTE: on DELETE we would be unable to convert the table -- NOTE: on DELETE we would be unable to convert the table
@ -143,4 +143,4 @@ CREATE OR REPLACE FUNCTION public.CDB_TableMetadataTouch(tablename regclass)
WHERE NOT EXISTS (SELECT * FROM upsert); WHERE NOT EXISTS (SELECT * FROM upsert);
END; END;
$$ $$
LANGUAGE 'plpgsql' VOLATILE STRICT; LANGUAGE 'plpgsql' VOLATILE STRICT PARALLEL UNSAFE;

View File

@ -75,4 +75,4 @@ BEGIN
RETURN ret; RETURN ret;
END END
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL UNSAFE;

View File

@ -21,7 +21,7 @@ AND CASE WHEN perm = 'public' THEN has_table_privilege('publicuser', c.oid, 'SEL
WHEN perm = 'all' THEN has_table_privilege(current_user, c.oid, 'SELECT') OR has_table_privilege('publicuser', c.oid, 'SELECT') WHEN perm = 'all' THEN has_table_privilege(current_user, c.oid, 'SELECT') OR has_table_privilege('publicuser', c.oid, 'SELECT')
ELSE false END; ELSE false END;
$$ LANGUAGE 'sql'; $$ LANGUAGE 'sql' STABLE PARALLEL SAFE;
-- This is to migrate from pre-0.2.0 version -- This is to migrate from pre-0.2.0 version
-- See http://github.com/CartoDB/cartodb-postgresql/issues/36 -- See http://github.com/CartoDB/cartodb-postgresql/issues/36

View File

@ -1,4 +1,3 @@
-- { -- {
-- Return pixel resolution at the given zoom level -- Return pixel resolution at the given zoom level
-- }{ -- }{
@ -7,7 +6,7 @@ RETURNS FLOAT8
AS $$ AS $$
-- circumference divided by 256 is z0 resolution, then divide by 2^z -- circumference divided by 256 is z0 resolution, then divide by 2^z
SELECT 6378137.0*2.0*pi() / 256.0 / power(2.0, z); SELECT 6378137.0*2.0*pi() / 256.0 / power(2.0, z);
$$ LANGUAGE SQL IMMUTABLE STRICT; $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE STRICT;
-- } -- }
-- { -- {
@ -58,7 +57,6 @@ BEGIN
--RAISE DEBUG 'ymax: %', ymax; --RAISE DEBUG 'ymax: %', ymax;
RETURN ST_MakeEnvelope(xmin, ymin, xmax, ymax, 3857); RETURN ST_MakeEnvelope(xmin, ymin, xmax, ymax, 3857);
END END
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT PARALLEL SAFE;
-- } -- }

View File

@ -2,7 +2,7 @@
CREATE OR REPLACE FUNCTION _CDB_MaxSupportedZoom() CREATE OR REPLACE FUNCTION _CDB_MaxSupportedZoom()
RETURNS int RETURNS int
LANGUAGE SQL LANGUAGE SQL
IMMUTABLE IMMUTABLE PARALLEL SAFE
AS $$ AS $$
-- The maximum zoom level has to be limited for various reasons, -- The maximum zoom level has to be limited for various reasons,
-- e.g. zoom levels greater than 31 would require tile coordinates -- e.g. zoom levels greater than 31 would require tile coordinates
@ -15,7 +15,7 @@ $$;
CREATE OR REPLACE FUNCTION cartodb.CDB_ZoomFromScale(scaleDenominator numeric) CREATE OR REPLACE FUNCTION cartodb.CDB_ZoomFromScale(scaleDenominator numeric)
RETURNS int RETURNS int
LANGUAGE SQL LANGUAGE SQL
IMMUTABLE IMMUTABLE PARALLEL SAFE
AS $$ AS $$
SELECT SELECT
CASE CASE