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) 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;