Changeset: 253ebf64f0f3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=253ebf64f0f3
Modified Files:
sql/storage/sql_catalog.c
Branch: Oct2020
Log Message:
Merged with Jun2020
diffs (269 lines):
diff --git a/sql/storage/sql_catalog.c b/sql/storage/sql_catalog.c
--- a/sql/storage/sql_catalog.c
+++ b/sql/storage/sql_catalog.c
@@ -453,44 +453,54 @@ sql_range_part_validate_and_insert(void
sql_part* pt = (sql_part*) v1, *newp = (sql_part*) v2;
int res1, res2, tpe = pt->tpe.type->localtype;
const void *nil = ATOMnilptr(tpe);
- bool pt_down_all = false, pt_upper_all = false;
+ bool pt_down_all = false, pt_upper_all = false, newp_down_all = false,
newp_upper_all = false;
if (pt == newp) /* same pointer, skip (used in updates) */
return NULL;
assert(tpe == newp->tpe.type->localtype);
- if (is_bit_nil(pt->with_nills)) //if one partition holds all including
nills, then conflicts
+ if (is_bit_nil(pt->with_nills) || is_bit_nil(newp->with_nills)) /* if
one partition holds all including nills, then conflicts */
return pt;
- if (newp->with_nills && pt->with_nills) //only one partition at most
has null values
+ if (newp->with_nills && pt->with_nills) /* only one partition at most
has null values */
return pt;
pt_down_all = !ATOMcmp(tpe, nil, pt->part.range.minvalue);
pt_upper_all = !ATOMcmp(tpe, nil, pt->part.range.maxvalue);
+ newp_down_all = !ATOMcmp(tpe, nil, newp->part.range.minvalue);
+ newp_upper_all = !ATOMcmp(tpe, nil, newp->part.range.maxvalue);
- if (pt_down_all || pt_upper_all) {
- if (pt_down_all) {
- if (pt->with_nills == true) /* only holds nils, allowed
*/
- return NULL;
- if (pt_upper_all) /* holds all range, conflicts if
newp holds more than nills */
- return newp->with_nills ? NULL : pt;
- if (!ATOMcmp(tpe, nil, newp->part.range.minvalue) ||
ATOMcmp(tpe, pt->part.range.maxvalue, newp->part.range.minvalue) > 0)
- return pt;
- }
- if (pt_upper_all) {
- if (pt->with_nills == true) /* only holds nils, allowed
*/
- return NULL;
- if (pt_down_all) /* holds all range, conflicts if newp
holds more than nills */
- return newp->with_nills ? NULL : pt;
- if (!ATOMcmp(tpe, nil, newp->part.range.maxvalue) ||
ATOMcmp(tpe, newp->part.range.maxvalue, pt->part.range.minvalue) > 0)
- return pt;
- }
+ /* if one partition just holds NULL values, then there's no conflict */
+ if ((newp_down_all && newp_upper_all && newp->with_nills) ||
(pt_down_all && pt_upper_all && pt->with_nills))
+ return NULL;
+ /* holds all range, will always conflict */
+ if ((pt_down_all && pt_upper_all && !pt->with_nills) || (newp_down_all
&& newp_upper_all && !newp->with_nills))
+ return pt;
+
+ if (pt_down_all) { /* from range min value until a value */
+ if (newp_down_all || ATOMcmp(tpe, pt->part.range.maxvalue,
newp->part.range.minvalue) > 0)
+ return pt;
+ return NULL;
+ }
+ if (pt_upper_all) { /* from value until range max value */
+ if (newp_upper_all || ATOMcmp(tpe, newp->part.range.maxvalue,
pt->part.range.minvalue) > 0)
+ return pt;
+ return NULL;
+ }
+ if (newp_down_all) { /* from range min value until a value */
+ if (pt_down_all || ATOMcmp(tpe, newp->part.range.maxvalue,
pt->part.range.minvalue) > 0)
+ return pt;
+ return NULL;
+ }
+ if (newp_upper_all) { /* from value until range max value */
+ if (pt_upper_all || ATOMcmp(tpe, pt->part.range.maxvalue,
newp->part.range.minvalue) > 0)
+ return pt;
return NULL;
}
/* Fallback into normal cases */
res1 = ATOMcmp(tpe, pt->part.range.minvalue, newp->part.range.maxvalue);
res2 = ATOMcmp(tpe, newp->part.range.minvalue, pt->part.range.maxvalue);
- if (res1 < 0 && res2 < 0) //overlap: x1 < y2 && y1 < x2
+ if (res1 < 0 && res2 < 0) /* overlap: x1 < y2 && y1 < x2 */
return pt;
return NULL;
}
diff --git a/sql/test/merge-partitions/Tests/mergepart30.sql
b/sql/test/merge-partitions/Tests/mergepart30.sql
--- a/sql/test/merge-partitions/Tests/mergepart30.sql
+++ b/sql/test/merge-partitions/Tests/mergepart30.sql
@@ -42,7 +42,7 @@ ALTER TABLE table1 ADD TABLE another2 AS
ALTER TABLE table1 ADD TABLE another2 AS PARTITION FOR NULL VALUES;
TRUNCATE table1;
-INSERT INTO table1 VALUES (2), (NULL);
+INSERT INTO table1 VALUES (2), (NULL);
INSERT INTO another1 VALUES (3);
INSERT INTO another1 VALUES (NULL); --error
@@ -55,6 +55,44 @@ SELECT a FROM another2;
ALTER TABLE table1 DROP TABLE another1;
ALTER TABLE table1 DROP TABLE another2;
+
+ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO 10;
+ALTER TABLE table1 ADD TABLE another2 AS PARTITION FOR NULL VALUES;
+SELECT a FROM table1;
+SELECT a FROM another1;
+SELECT a FROM another2;
+ALTER TABLE table1 DROP TABLE another1;
+ALTER TABLE table1 DROP TABLE another2;
+
+ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO 10
WITH NULL VALUES;
+ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM 0 to 5; --error,
conflicts with another1
+SELECT a FROM table1;
+SELECT a FROM another1;
+SELECT a FROM another2;
+ALTER TABLE table1 DROP TABLE another1;
+ALTER TABLE table1 DROP TABLE another2; --error, not there
+
+ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO
RANGE MAXVALUE;
+ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM 0 to 5; --error,
conflicts with another1
+SELECT a FROM table1;
+SELECT a FROM another1;
+SELECT a FROM another2;
+ALTER TABLE table1 DROP TABLE another1;
+ALTER TABLE table1 DROP TABLE another2; --error, not there
+
+TRUNCATE another1;
+TRUNCATE another2;
+
+ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO 2;
+ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM RANGE MINVALUE TO 1;
--error, conflicts with another1
+ALTER TABLE table1 DROP TABLE another1;
+ALTER TABLE table1 DROP TABLE another2; --error, not there
+
+ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM 2 TO RANGE MAXVALUE;
+ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM 10 TO RANGE MAXVALUE;
--error, conflicts with another1
+ALTER TABLE table1 DROP TABLE another1;
+ALTER TABLE table1 DROP TABLE another2; --error, not there
+
DROP TABLE another1;
DROP TABLE another2;
DROP TABLE table1;
diff --git a/sql/test/merge-partitions/Tests/mergepart30.stable.err
b/sql/test/merge-partitions/Tests/mergepart30.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart30.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart30.stable.err
@@ -57,6 +57,38 @@ MAPI = (monetdb) /var/tmp/mtest-92816/.
QUERY = INSERT INTO another2 VALUES (2); --error
ERROR = !INSERT: table sys.another2 is part of merge table sys.table1 and the
insert violates the partition range of values
CODE = M0M29
+MAPI = (monetdb) /var/tmp/mtest-84239/.s.monetdb.31974
+QUERY = ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM 0 to 5;
--error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: 0 to 5 and absolute min value to
10 from table sys.another1
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-84239/.s.monetdb.31974
+QUERY = ALTER TABLE table1 DROP TABLE another2; --error, not there
+ERROR = !ALTER TABLE: table 'sys.another2' isn't part of RANGE PARTITION TABLE
'sys.table1'
+CODE = 42S02
+MAPI = (monetdb) /var/tmp/mtest-84239/.s.monetdb.31974
+QUERY = ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM 0 to 5;
--error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: 0 to 5 and absolute min value to
absolute max value from table sys.another1
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-84239/.s.monetdb.31974
+QUERY = ALTER TABLE table1 DROP TABLE another2; --error, not there
+ERROR = !ALTER TABLE: table 'sys.another2' isn't part of RANGE PARTITION TABLE
'sys.table1'
+CODE = 42S02
+MAPI = (monetdb) /var/tmp/mtest-86521/.s.monetdb.35752
+QUERY = ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM RANGE MINVALUE
TO 1; --error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: absolute min value to 1 and
absolute min value to 2 from table sys.another1
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-86671/.s.monetdb.39443
+QUERY = ALTER TABLE table1 DROP TABLE another2; --error, not there
+ERROR = !ALTER TABLE: table 'sys.another2' isn't part of RANGE PARTITION TABLE
'sys.table1'
+CODE = 42S02
+MAPI = (monetdb) /var/tmp/mtest-86671/.s.monetdb.39443
+QUERY = ALTER TABLE table1 ADD TABLE another2 AS PARTITION FROM 10 TO RANGE
MAXVALUE; --error, conflicts with another1
+ERROR = !ALTER TABLE: conflicting partitions: 10 to absolute max value and 2
to absolute max value from table sys.another1
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-86671/.s.monetdb.39443
+QUERY = ALTER TABLE table1 DROP TABLE another2; --error, not there
+ERROR = !ALTER TABLE: table 'sys.another2' isn't part of RANGE PARTITION TABLE
'sys.table1'
+CODE = 42S02
# 09:24:49 >
# 09:24:49 > "Done."
diff --git a/sql/test/merge-partitions/Tests/mergepart30.stable.out
b/sql/test/merge-partitions/Tests/mergepart30.stable.out
--- a/sql/test/merge-partitions/Tests/mergepart30.stable.out
+++ b/sql/test/merge-partitions/Tests/mergepart30.stable.out
@@ -77,6 +77,87 @@ stdout of test 'mergepart30` in director
[ NULL ]
#ALTER TABLE table1 DROP TABLE another1;
#ALTER TABLE table1 DROP TABLE another2;
+#ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO 10;
+#ALTER TABLE table1 ADD TABLE another2 AS PARTITION FOR NULL VALUES;
+#SELECT a FROM table1;
+% .table1 # table_name
+% a # name
+% int # type
+% 1 # length
+[ 2 ]
+[ 3 ]
+[ NULL ]
+[ NULL ]
+#SELECT a FROM another1;
+% sys.another1 # table_name
+% a # name
+% int # type
+% 1 # length
+[ 2 ]
+[ 3 ]
+#SELECT a FROM another2;
+% sys.another2 # table_name
+% a # name
+% int # type
+% 1 # length
+[ NULL ]
+[ NULL ]
+#ALTER TABLE table1 DROP TABLE another1;
+#ALTER TABLE table1 DROP TABLE another2;
+#ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO 10
WITH NULL VALUES;
+#SELECT a FROM table1;
+% sys.table1 # table_name
+% a # name
+% int # type
+% 1 # length
+[ 2 ]
+[ 3 ]
+#SELECT a FROM another1;
+% sys.another1 # table_name
+% a # name
+% int # type
+% 1 # length
+[ 2 ]
+[ 3 ]
+#SELECT a FROM another2;
+% sys.another2 # table_name
+% a # name
+% int # type
+% 1 # length
+[ NULL ]
+[ NULL ]
+#ALTER TABLE table1 DROP TABLE another1;
+#ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO
RANGE MAXVALUE;
+#SELECT a FROM table1;
+% sys.table1 # table_name
+% a # name
+% int # type
+% 1 # length
+[ 2 ]
+[ 3 ]
+#SELECT a FROM another1;
+% sys.another1 # table_name
+% a # name
+% int # type
+% 1 # length
+[ 2 ]
+[ 3 ]
+#SELECT a FROM another2;
+% sys.another2 # table_name
+% a # name
+% int # type
+% 1 # length
+[ NULL ]
+[ NULL ]
+#ALTER TABLE table1 DROP TABLE another1;
+#TRUNCATE another1;
+[ 2 ]
+#TRUNCATE another2;
+[ 2 ]
+#ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM RANGE MINVALUE TO 2;
+#ALTER TABLE table1 DROP TABLE another1;
+#ALTER TABLE table1 ADD TABLE another1 AS PARTITION FROM 2 TO RANGE MAXVALUE;
+#ALTER TABLE table1 DROP TABLE another1;
#DROP TABLE another1;
#DROP TABLE another2;
#DROP TABLE table1;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list