diff --git a/scripts-available/CDB_Quota.sql b/scripts-available/CDB_Quota.sql index aeda2d3..f96bdc6 100644 --- a/scripts-available/CDB_Quota.sql +++ b/scripts-available/CDB_Quota.sql @@ -26,19 +26,14 @@ BEGIN WHERE o_table_schema = schema_name AND o_table_catalog = current_database() ), user_tables AS ( - SELECT table_name FROM information_schema.tables - WHERE table_catalog = current_database() AND table_schema = schema_name - AND table_name != 'spatial_ref_sys' - AND table_name != 'cdb_tablemetadata' - AND table_type = 'BASE TABLE' + SELECT table_name FROM _CDB_NonAnalysisTablesInSchema(schema_name) ), table_cat AS ( SELECT table_name, ( EXISTS(select * from raster_tables where o_table_name = table_name) - OR - table_name SIMILAR TO _CDB_OverviewTableDiscriminator() || '[\w\d]*' + OR table_name SIMILAR TO _CDB_OverviewTableDiscriminator() || '[\w\d]*' ) AS is_overview, EXISTS(SELECT * FROM raster_tables WHERE r_table_name = table_name) AS is_raster FROM user_tables diff --git a/test/CDB_QuotaTest.sql b/test/CDB_QuotaTest.sql index dc4ec68..fa5188c 100644 --- a/test/CDB_QuotaTest.sql +++ b/test/CDB_QuotaTest.sql @@ -27,5 +27,21 @@ INSERT INTO big VALUES (8193); SELECT CDB_SetUserQuotaInBytes(0); INSERT INTO big VALUES (8194); DROP TABLE big; + + +--analysis tables should be excluded from quota: +CREATE TABLE big(a int); +CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big + EXECUTE PROCEDURE CDB_CheckQuota(1, 1, 'public'); +SELECT CDB_SetUserQuotaInBytes(1); +CREATE TABLE analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id int); +INSERT INTO analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4(id) VALUES (1),(2),(3),(4),(5); +INSERT INTO big VALUES (1); -- allowed, check runs before +DROP TABLE analysis_2f13a3dbd7_41bd92976fc6dd97072afe4ee450054f4c0715d4; +INSERT INTO big VALUES (2); -- disallowed, quota exceeds before +DROP TABLE big; +SELECT CDB_SetUserQuotaInBytes(0); + + set client_min_messages to NOTICE; DROP FUNCTION _CDB_UserQuotaInBytes(); diff --git a/test/CDB_QuotaTest_expect b/test/CDB_QuotaTest_expect index 0d1b9c0..9204514 100644 --- a/test/CDB_QuotaTest_expect +++ b/test/CDB_QuotaTest_expect @@ -18,5 +18,15 @@ ERROR: Quota exceeded by 443.998046875KB 0 INSERT 0 1 DROP TABLE +CREATE TABLE +CREATE TRIGGER +1 +CREATE TABLE +INSERT 0 5 +INSERT 0 1 +DROP TABLE +ERROR: Quota exceeded by 3.9990234375KB +DROP TABLE +0 SET DROP FUNCTION