Changeset: eb883d1307c5 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eb883d1307c5
Modified Files:
        sql/server/rel_updates.c
        sql/test/merge-partitions/Tests/mergepart10.sql
Branch: merge-partitions
Log Message:

Don't allow insert/update/delete on empty partitions


diffs (60 lines):

diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -397,6 +397,8 @@ insert_allowed(mvc *sql, sql_table *t, c
                return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot %s view 
'%s'", op, opname, tname);
        } else if (isNonPartitionedTable(t)) {
                return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot %s merge 
table '%s'", op, opname, tname);
+       } else if ((isRangePartitionTable(t) || isListPartitionTable(t)) && 
cs_size(&t->members) == 0) {
+               return sql_error(sql, 02, SQLSTATE(42000) "%s: %s partitioned 
table '%s' has no partitions set", op, isListPartitionTable(t)?"list":"range", 
tname);
        } else if (isStream(t)) {
                return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot %s stream 
'%s'", op, opname, tname);
        } else if (t->access == TABLE_READONLY) {
@@ -428,6 +430,8 @@ update_allowed(mvc *sql, sql_table *t, c
                return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot %s view 
'%s'", op, opname, tname);
        } else if (isNonPartitionedTable(t)) {
                return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot %s merge 
table '%s'", op, opname, tname);
+       } else if ((isRangePartitionTable(t) || isListPartitionTable(t)) && 
cs_size(&t->members) == 0) {
+               return sql_error(sql, 02, SQLSTATE(42000) "%s: %s partitioned 
table '%s' has no partitions set", op, isListPartitionTable(t)?"list":"range", 
tname);
        } else if (isStream(t)) {
                return sql_error(sql, 02, SQLSTATE(42000) "%s: cannot %s stream 
'%s'", op, opname, tname);
        } else if (t->access == TABLE_READONLY || t->access == 
TABLE_APPENDONLY) {
diff --git a/sql/test/merge-partitions/Tests/mergepart10.sql 
b/sql/test/merge-partitions/Tests/mergepart10.sql
--- a/sql/test/merge-partitions/Tests/mergepart10.sql
+++ b/sql/test/merge-partitions/Tests/mergepart10.sql
@@ -1,9 +1,28 @@
-CREATE MERGE TABLE ihavenopartitions (a int, b varchar(32)) PARTITION BY 
VALUES (a);
+CREATE MERGE TABLE testsmallpartitions (a int, b varchar(32)) PARTITION BY 
VALUES (a);
+CREATE TABLE testingme (a int, b varchar(32));
+
+INSERT INTO testsmallpartitions VALUES (1, 'fail'); --error
+DELETE FROM testsmallpartitions; --error
+DELETE FROM testsmallpartitions WHERE a < 400; --error
+TRUNCATE testsmallpartitions; --error
+UPDATE testsmallpartitions SET b = 'try update me'; --error
+
+ALTER TABLE testsmallpartitions ADD TABLE testingme AS PARTITION IN ('100');
 
-INSERT INTO ihavenopartitions VALUES (1, 'fail'); --error
-DELETE FROM ihavenopartitions;
-DELETE FROM ihavenopartitions WHERE a < 1;
-TRUNCATE ihavenopartitions;
-UPDATE ihavenopartitions SET a = 3;
+DELETE FROM testsmallpartitions;
+DELETE FROM testsmallpartitions WHERE a < 400;
+TRUNCATE testsmallpartitions;
+UPDATE testsmallpartitions SET b = 'updating';
 
-DROP TABLE ihavenopartitions;
+INSERT INTO testsmallpartitions VALUES (100, 'ok'), (100, 'also'), (100, 'ok');
+DELETE FROM testsmallpartitions;
+INSERT INTO testsmallpartitions VALUES (100, 'another'), (100, 'test'), (100, 
'todo');
+DELETE FROM testsmallpartitions WHERE a < 400;
+INSERT INTO testsmallpartitions VALUES (100, 'more'), (100, 'testing'), (100, 
'please'), (100, 'now');
+TRUNCATE testsmallpartitions;
+INSERT INTO testsmallpartitions VALUES (100, 'just'), (100, 'one'), (100, 
'more'), (100, 'insert');
+UPDATE testsmallpartitions SET b = 'updating';
+
+ALTER TABLE testsmallpartitions DROP TABLE testingme;
+DROP TABLE testingme;
+DROP TABLE testsmallpartitions;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to