Merge pull request #113 from CartoDB/issue-108
Improve cartodb._CDB_total_relation_size performance
This commit is contained in:
commit
5d22464036
@ -1,18 +1,15 @@
|
|||||||
CREATE OR REPLACE FUNCTION cartodb._CDB_total_relation_size(_schema_name TEXT, _table_name TEXT)
|
CREATE OR REPLACE FUNCTION cartodb._CDB_total_relation_size(_schema_name TEXT, _table_name TEXT)
|
||||||
RETURNS bigint AS
|
RETURNS bigint AS
|
||||||
$$
|
$$
|
||||||
|
DECLARE relation_size bigint := 0;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF EXISTS (
|
BEGIN
|
||||||
SELECT 1 FROM information_schema.tables
|
SELECT pg_total_relation_size(format('"%s"."%s"', _schema_name, _table_name)) INTO relation_size;
|
||||||
WHERE table_catalog = current_database()
|
EXCEPTION
|
||||||
AND table_schema = _schema_name
|
WHEN undefined_table OR OTHERS THEN
|
||||||
AND table_name = _table_name
|
RAISE NOTICE 'cartodb._CDB_total_relation_size(''%'', ''%'') caught error: % (%)', _schema_name, _table_name, SQLERRM, SQLSTATE;
|
||||||
)
|
END;
|
||||||
THEN
|
RETURN relation_size;
|
||||||
RETURN pg_total_relation_size(format('"%s"."%s"', _schema_name, _table_name));
|
|
||||||
ELSE
|
|
||||||
RETURN 0;
|
|
||||||
END IF;
|
|
||||||
END;
|
END;
|
||||||
$$
|
$$
|
||||||
LANGUAGE 'plpgsql' VOLATILE;
|
LANGUAGE 'plpgsql' VOLATILE;
|
||||||
|
Loading…
Reference in New Issue
Block a user