Merge pull request #281 from CartoDB/277-exclude-analysis-quota
Exclude analysis cache tables from the quota
This commit is contained in:
@@ -41,7 +41,7 @@ AS $$
|
|||||||
FROM pg_class c
|
FROM pg_class c
|
||||||
JOIN pg_namespace n ON n.oid = c.relnamespace
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||||
WHERE c.relkind = 'r'
|
WHERE c.relkind = 'r'
|
||||||
AND c.relname NOT IN ('cdb_tablemetadata', 'spatial_ref_sys')
|
AND c.relname NOT IN ('cdb_tablemetadata', 'cdb_analysis_catalog', 'cdb_conf', 'spatial_ref_sys')
|
||||||
AND CASE WHEN schema_name IS NULL
|
AND CASE WHEN schema_name IS NULL
|
||||||
THEN n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb')
|
THEN n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb')
|
||||||
ELSE n.nspname = schema_name
|
ELSE n.nspname = schema_name
|
||||||
|
|||||||
@@ -26,19 +26,14 @@ BEGIN
|
|||||||
WHERE o_table_schema = schema_name AND o_table_catalog = current_database()
|
WHERE o_table_schema = schema_name AND o_table_catalog = current_database()
|
||||||
),
|
),
|
||||||
user_tables AS (
|
user_tables AS (
|
||||||
SELECT table_name FROM information_schema.tables
|
SELECT table_name FROM _CDB_NonAnalysisTablesInSchema(schema_name)
|
||||||
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'
|
|
||||||
),
|
),
|
||||||
table_cat AS (
|
table_cat AS (
|
||||||
SELECT
|
SELECT
|
||||||
table_name,
|
table_name,
|
||||||
(
|
(
|
||||||
EXISTS(select * from raster_tables where o_table_name = table_name)
|
EXISTS(select * from raster_tables where o_table_name = table_name)
|
||||||
OR
|
OR table_name SIMILAR TO _CDB_OverviewTableDiscriminator() || '[\w\d]*'
|
||||||
table_name SIMILAR TO _CDB_OverviewTableDiscriminator() || '[\w\d]*'
|
|
||||||
) AS is_overview,
|
) AS is_overview,
|
||||||
EXISTS(SELECT * FROM raster_tables WHERE r_table_name = table_name) AS is_raster
|
EXISTS(SELECT * FROM raster_tables WHERE r_table_name = table_name) AS is_raster
|
||||||
FROM user_tables
|
FROM user_tables
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ SELECT c.relname
|
|||||||
FROM pg_class c
|
FROM pg_class c
|
||||||
JOIN pg_namespace n ON n.oid = c.relnamespace
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||||
WHERE c.relkind = 'r'
|
WHERE c.relkind = 'r'
|
||||||
AND c.relname NOT IN ('cdb_tablemetadata', 'spatial_ref_sys')
|
AND c.relname NOT IN ('cdb_tablemetadata', 'cdb_analysis_catalog', 'cdb_conf', 'spatial_ref_sys')
|
||||||
AND n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb')
|
AND n.nspname NOT IN ('pg_catalog', 'information_schema', 'topology', 'cartodb')
|
||||||
AND CASE WHEN perm = 'public' THEN has_table_privilege('publicuser', c.oid, 'SELECT')
|
AND CASE WHEN perm = 'public' THEN has_table_privilege('publicuser', c.oid, 'SELECT')
|
||||||
WHEN perm = 'private' THEN has_table_privilege(current_user, c.oid, 'SELECT') AND NOT has_table_privilege('publicuser', c.oid, 'SELECT')
|
WHEN perm = 'private' THEN has_table_privilege(current_user, c.oid, 'SELECT') AND NOT has_table_privilege('publicuser', c.oid, 'SELECT')
|
||||||
|
|||||||
@@ -27,5 +27,21 @@ INSERT INTO big VALUES (8193);
|
|||||||
SELECT CDB_SetUserQuotaInBytes(0);
|
SELECT CDB_SetUserQuotaInBytes(0);
|
||||||
INSERT INTO big VALUES (8194);
|
INSERT INTO big VALUES (8194);
|
||||||
DROP TABLE big;
|
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;
|
set client_min_messages to NOTICE;
|
||||||
DROP FUNCTION _CDB_UserQuotaInBytes();
|
DROP FUNCTION _CDB_UserQuotaInBytes();
|
||||||
|
|||||||
@@ -18,5 +18,15 @@ ERROR: Quota exceeded by 443.998046875KB
|
|||||||
0
|
0
|
||||||
INSERT 0 1
|
INSERT 0 1
|
||||||
DROP TABLE
|
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
|
SET
|
||||||
DROP FUNCTION
|
DROP FUNCTION
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ function setup_database() {
|
|||||||
log_info "########################### BOOTSTRAP ###########################"
|
log_info "########################### BOOTSTRAP ###########################"
|
||||||
${CMD} -d ${DATABASE} -f scripts-available/CDB_Organizations.sql
|
${CMD} -d ${DATABASE} -f scripts-available/CDB_Organizations.sql
|
||||||
${CMD} -d ${DATABASE} -f scripts-available/CDB_OverviewsSupport.sql
|
${CMD} -d ${DATABASE} -f scripts-available/CDB_OverviewsSupport.sql
|
||||||
|
${CMD} -d ${DATABASE} -f scripts-available/CDB_AnalysisSupport.sql
|
||||||
# trick to allow forcing a schema when loading SQL files (see: http://bit.ly/1HeLnhL)
|
# trick to allow forcing a schema when loading SQL files (see: http://bit.ly/1HeLnhL)
|
||||||
${CMD} -d ${DATABASE} -f test/extension/run_at_cartodb_schema.sql
|
${CMD} -d ${DATABASE} -f test/extension/run_at_cartodb_schema.sql
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user