Changeset: 1606744f0f53 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1606744f0f53
Modified Files:
sql/server/rel_dump.c
sql/test/Tests/truncate-statements-extra.sql
sql/test/Tests/truncate-statements-extra.stable.out
Branch: Nov2019
Log Message:
Making truncate statement plans more readable
diffs (187 lines):
diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -510,8 +510,14 @@ rel_print_(mvc *sql, stream *fout, sql_
mnstr_printf(fout, "update(");
else if (rel->op == op_delete)
mnstr_printf(fout, "delete(");
- else if (rel->op == op_truncate)
- mnstr_printf(fout, "truncate(");
+ else if (rel->op == op_truncate) {
+ assert(list_length(rel->exps) == 2);
+ sql_exp *first = (sql_exp*) rel->exps->h->data, *second
= (sql_exp*) rel->exps->h->next->data;
+ int restart_sequences =
((atom*)first->l)->data.val.ival,
+ drop_action = ((atom*)second->l)->data.val.ival;
+ mnstr_printf(fout, "truncate %s identity, %s(",
restart_sequences ? "restart" : "continue",
+
drop_action ? "cascade" : "restrict");
+ }
if (rel_is_ref(rel->l)) {
int nr = find_ref(refs, rel->l);
@@ -530,7 +536,7 @@ rel_print_(mvc *sql, stream *fout, sql_
}
print_indent(sql, fout, depth, decorate);
mnstr_printf(fout, ")");
- if (rel->exps)
+ if (rel->op != op_truncate && rel->exps)
exps_print(sql, fout, rel->exps, depth, refs, 1, 0);
} break;
default:
@@ -1279,15 +1285,27 @@ rel_read(mvc *sql, char *r, int *pos, li
}
if (r[*pos] == 't' && r[*pos+1] == 'r' && r[*pos+2] == 'u') {
- *pos += (int) strlen("truncate");
+ int restart_sequences = 0, drop_action = 0;
+ *pos += (int) strlen("truncate ");
+ if (r[*pos] == 'r') {
+ restart_sequences = 1;
+ *pos += (int) strlen("restart identity, ");
+ } else {
+ *pos += (int) strlen("continue identity, ");
+ }
+ if (r[*pos] == 'c') {
+ drop_action = 1;
+ *pos += (int) strlen("cascade");
+ } else {
+ *pos += (int) strlen("restrict");
+ }
skipWS(r, pos);
(*pos)++; /* ( */
lrel = rel_read(sql, r, pos, refs); /* to be truncated relation
*/
skipWS(r,pos);
(*pos)++; /* ) */
- /* TODO drop_action and check_identity options */
- return rel_truncate(sql->sa, lrel, 0, 0);
+ return rel_truncate(sql->sa, lrel, drop_action,
restart_sequences);
}
if (r[*pos] == 'u' && r[*pos+1] == 'p' && r[*pos+2] == 'd') {
diff --git a/sql/test/Tests/truncate-statements-extra.sql
b/sql/test/Tests/truncate-statements-extra.sql
--- a/sql/test/Tests/truncate-statements-extra.sql
+++ b/sql/test/Tests/truncate-statements-extra.sql
@@ -10,11 +10,13 @@ TRUNCATE testing4; --error
SELECT a FROM testing4;
SELECT abc FROM testing5;
+PLAN TRUNCATE testing4 RESTRICT;
TRUNCATE testing4 RESTRICT; --error
SELECT a FROM testing4;
SELECT abc FROM testing5;
-TRUNCATE testing4 CASCADE;
+PLAN TRUNCATE testing4 CASCADE;
+TRUNCATE testing4 CASCADE;
SELECT a FROM testing4;
SELECT abc FROM testing5;
@@ -24,16 +26,22 @@ CREATE TABLE testing6 (a INT AUTO_INCREM
INSERT INTO testing6 (b) VALUES (1);
INSERT INTO testing6 (b) VALUES (1);
SELECT a, b FROM testing6;
+
+PLAN TRUNCATE testing6;
TRUNCATE testing6;
INSERT INTO testing6 (b) VALUES (3);
INSERT INTO testing6 (b) VALUES (4);
SELECT a, b FROM testing6;
+
+PLAN TRUNCATE testing6 CONTINUE IDENTITY;
TRUNCATE testing6 CONTINUE IDENTITY;
INSERT INTO testing6 (b) VALUES (5);
INSERT INTO testing6 (b) VALUES (6);
SELECT a, b FROM testing6;
+
+PLAN TRUNCATE testing6 RESTART IDENTITY;
TRUNCATE testing6 RESTART IDENTITY;
INSERT INTO testing6 (b) VALUES (7);
diff --git a/sql/test/Tests/truncate-statements-extra.stable.out
b/sql/test/Tests/truncate-statements-extra.stable.out
--- a/sql/test/Tests/truncate-statements-extra.stable.out
+++ b/sql/test/Tests/truncate-statements-extra.stable.out
@@ -82,6 +82,14 @@ stdout of test 'truncate-statements-extr
% int # type
% 1 # length
[ 1 ]
+#PLAN TRUNCATE testing4 RESTRICT;
+% .plan # table_name
+% rel # name
+% clob # type
+% 87 # length
+truncate continue identity, restrict(
+| table(sys.testing4) [ "testing4"."a" NOT NULL HASHCOL , "testing4"."%TID%"
NOT NULL ]
+)
#SELECT a FROM testing4;
% sys.testing4 # table_name
% a # name
@@ -94,7 +102,15 @@ stdout of test 'truncate-statements-extr
% int # type
% 1 # length
[ 1 ]
-#TRUNCATE testing CASCADE;
+#PLAN TRUNCATE testing4 CASCADE;
+% .plan # table_name
+% rel # name
+% clob # type
+% 87 # length
+truncate continue identity, cascade(
+| table(sys.testing4) [ "testing4"."a" NOT NULL HASHCOL , "testing4"."%TID%"
NOT NULL ]
+)
+#TRUNCATE testing4 CASCADE;
[ 1 ]
#SELECT a FROM testing4;
% sys.testing4 # table_name
@@ -118,7 +134,15 @@ stdout of test 'truncate-statements-extr
% 1, 1 # length
[ 1, 1 ]
[ 2, 1 ]
-#TRUNCATE testing3;
+#PLAN TRUNCATE testing6;
+% .plan # table_name
+% rel # name
+% clob # type
+% 85 # length
+truncate continue identity, restrict(
+| table(sys.testing6) [ "testing6"."a", "testing6"."b", "testing6"."%TID%" NOT
NULL ]
+)
+#TRUNCATE testing6;
[ 2 ]
#INSERT INTO testing3 (b) VALUES (3);
[ 1 ]
@@ -131,7 +155,15 @@ stdout of test 'truncate-statements-extr
% 1, 1 # length
[ 3, 3 ]
[ 4, 4 ]
-#TRUNCATE testing3 CONTINUE IDENTITY;
+#PLAN TRUNCATE testing6 CONTINUE IDENTITY;
+% .plan # table_name
+% rel # name
+% clob # type
+% 85 # length
+truncate continue identity, restrict(
+| table(sys.testing6) [ "testing6"."a", "testing6"."b", "testing6"."%TID%" NOT
NULL ]
+)
+#TRUNCATE testing6 CONTINUE IDENTITY;
[ 2 ]
#INSERT INTO testing3 (b) VALUES (5);
[ 1 ]
@@ -144,7 +176,15 @@ stdout of test 'truncate-statements-extr
% 1, 1 # length
[ 5, 5 ]
[ 6, 6 ]
-#TRUNCATE testing3 RESTART IDENTITY;
+#PLAN TRUNCATE testing6 RESTART IDENTITY;
+% .plan # table_name
+% rel # name
+% clob # type
+% 85 # length
+truncate restart identity, restrict(
+| table(sys.testing6) [ "testing6"."a", "testing6"."b", "testing6"."%TID%" NOT
NULL ]
+)
+#TRUNCATE testing6 RESTART IDENTITY;
[ 2 ]
#INSERT INTO testing3 (b) VALUES (7);
[ 1 ]
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list