Merge pull request #113 from CartoDB/issue-108

Improve cartodb._CDB_total_relation_size performance
This commit is contained in:
Raul Ochoa 2015-08-18 11:17:42 +02:00
commit 5d22464036

View File

@ -1,18 +1,15 @@
CREATE OR REPLACE FUNCTION cartodb._CDB_total_relation_size(_schema_name TEXT, _table_name TEXT)
RETURNS bigint AS
$$
DECLARE relation_size bigint := 0;
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_catalog = current_database()
AND table_schema = _schema_name
AND table_name = _table_name
)
THEN
RETURN pg_total_relation_size(format('"%s"."%s"', _schema_name, _table_name));
ELSE
RETURN 0;
END IF;
BEGIN
SELECT pg_total_relation_size(format('"%s"."%s"', _schema_name, _table_name)) INTO relation_size;
EXCEPTION
WHEN undefined_table OR OTHERS THEN
RAISE NOTICE 'cartodb._CDB_total_relation_size(''%'', ''%'') caught error: % (%)', _schema_name, _table_name, SQLERRM, SQLSTATE;
END;
RETURN relation_size;
END;
$$
LANGUAGE 'plpgsql' VOLATILE;