Merge pull request #110 from CartoDB/issue-108

Fixes CDB_UserDataSize failing due `ERROR: relation "*" does not exist.`
This commit is contained in:
Raul Ochoa 2015-08-13 19:01:05 +02:00
commit 219d876973
5 changed files with 34 additions and 2 deletions

View File

@ -1,7 +1,7 @@
# cartodb/Makefile # cartodb/Makefile
EXTENSION = cartodb EXTENSION = cartodb
EXTVERSION = 0.8.2 EXTVERSION = 0.8.3
SED = sed SED = sed
@ -41,6 +41,7 @@ UPGRADABLE = \
0.7.4 \ 0.7.4 \
0.8.0 \ 0.8.0 \
0.8.1 \ 0.8.1 \
0.8.2 \
$(EXTVERSION)dev \ $(EXTVERSION)dev \
$(EXTVERSION)next \ $(EXTVERSION)next \
$(END) $(END)

View File

@ -1,3 +1,7 @@
0.8.3 (2015-mm-dd)
------------------
* Fixes CDB_UserDataSize failing due `ERROR: relation "*" does not exist.` [#108](https://github.com/CartoDB/cartodb-postgresql/issues/108)
0.8.2 (2015-07-27) 0.8.2 (2015-07-27)
------------------ ------------------
* Fix for CDB_UserTables returning wrong listings when publicuser is used * Fix for CDB_UserTables returning wrong listings when publicuser is used

View File

@ -1,3 +1,22 @@
CREATE OR REPLACE FUNCTION cartodb._CDB_total_relation_size(_schema_name TEXT, _table_name TEXT)
RETURNS bigint AS
$$
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;
END;
$$
LANGUAGE 'plpgsql' VOLATILE;
-- 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)
RETURNS bigint AS RETURNS bigint AS
@ -24,7 +43,7 @@ BEGIN
FROM user_tables FROM user_tables
), ),
sizes AS ( sizes AS (
SELECT COALESCE(INT8(SUM(pg_total_relation_size('"' || schema_name || '"."' || table_name || '"')))) table_size, SELECT COALESCE(INT8(SUM(cartodb._CDB_total_relation_size(schema_name, table_name)))) table_size,
CASE CASE
WHEN is_overview THEN 0 WHEN is_overview THEN 0
WHEN is_raster THEN 1 WHEN is_raster THEN 1

View File

@ -13,6 +13,11 @@ SELECT CDB_CartodbfyTable('big');
INSERT INTO big SELECT generate_series(1,2048); INSERT INTO big SELECT generate_series(1,2048);
INSERT INTO big SELECT generate_series(1,2048); INSERT INTO big SELECT generate_series(1,2048);
INSERT INTO big SELECT generate_series(1,2048); INSERT INTO big SELECT generate_series(1,2048);
-- Test for #108: https://github.com/CartoDB/cartodb-postgresql/issues/108
SELECT CDB_UserDataSize();
SELECT cartodb._CDB_total_relation_size('public', 'big');
SELECT cartodb._CDB_total_relation_size('public', 'nonexistent_table_name');
-- END Test for #108
SELECT CDB_SetUserQuotaInBytes(2); SELECT CDB_SetUserQuotaInBytes(2);
INSERT INTO big VALUES (1); INSERT INTO big VALUES (1);
SELECT CDB_SetUserQuotaInBytes(0); SELECT CDB_SetUserQuotaInBytes(0);

View File

@ -8,6 +8,9 @@ ERROR: Quota exceeded by 3.9990234375KB
INSERT 0 2048 INSERT 0 2048
INSERT 0 2048 INSERT 0 2048
INSERT 0 2048 INSERT 0 2048
581632
1163264
0
2 2
ERROR: Quota exceeded by 567.998046875KB ERROR: Quota exceeded by 567.998046875KB
0 0