Changeset: b49fd117675a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b49fd117675a
Added Files:
        sql/test/mergetables/Tests/multiple-merge-tables.sql
        sql/test/mergetables/Tests/multiple-merge-tables.stable.err
        sql/test/mergetables/Tests/multiple-merge-tables.stable.out
Modified Files:
        sql/storage/store.c
        sql/test/mergetables/Tests/All
        sql/test/mergetables/Tests/mergedrop2.sql
Branch: Jun2020-mmt
Log Message:

mergetables and schemas lists of parts use different node lists, so find again 
on the schema while removing. Also added test


diffs (185 lines):

diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -6326,7 +6326,7 @@ sql_trans_set_table_schema(sql_trans *tr
 sql_table *
 sql_trans_del_table(sql_trans *tr, sql_table *mt, sql_table *pt, int 
drop_action)
 {
-       node *n = members_find_child_id(mt->members, pt->base.id);
+       node *sn, *n = members_find_child_id(mt->members, pt->base.id);
        sql_part *p = n ? (sql_part*) n->data : NULL;
        sql_schema *syss = find_sql_schema(tr, isGlobal(mt)?"sys":"tmp");
        sql_table *sysobj = find_sql_table(syss, "objects");
@@ -6349,7 +6349,9 @@ sql_trans_del_table(sql_trans *tr, sql_t
        /* merge table depends on part table */
        sql_trans_drop_dependency(tr, pt->base.id, mt->base.id, 
TABLE_DEPENDENCY);
 
-       cs_del(&mt->s->parts, n, p->base.flags);
+       sn = list_find_base_id(mt->s->parts.set, p->base.id);
+       assert(sn);
+       cs_del(&mt->s->parts, sn, p->base.flags);
        list_remove_data(mt->members, p);
        pt->partition--;/* check other hierarchies? */
        p->member = NULL;
diff --git a/sql/test/mergetables/Tests/All b/sql/test/mergetables/Tests/All
--- a/sql/test/mergetables/Tests/All
+++ b/sql/test/mergetables/Tests/All
@@ -33,3 +33,4 @@ sqlsmith-exists
 sqlsmith-exists2
 mergedb_drop
 mergetable_rel_push_aggr_down
+multiple-merge-tables
diff --git a/sql/test/mergetables/Tests/mergedrop2.sql 
b/sql/test/mergetables/Tests/mergedrop2.sql
--- a/sql/test/mergetables/Tests/mergedrop2.sql
+++ b/sql/test/mergetables/Tests/mergedrop2.sql
@@ -22,3 +22,12 @@ alter table t add table t3;
 
 alter table t drop table t1;
 alter table t add table t1;
+
+alter table t drop table t1;
+alter table t drop table t2;
+alter table t drop table t3;
+
+drop table t;
+drop table t1;
+drop table t2;
+drop table t3;
diff --git a/sql/test/mergetables/Tests/multiple-merge-tables.sql 
b/sql/test/mergetables/Tests/multiple-merge-tables.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/mergetables/Tests/multiple-merge-tables.sql
@@ -0,0 +1,31 @@
+create table t (i int);
+insert into t values (42), (666);
+create merge table mt1 (like t);
+create merge table mt2 (like t);
+
+create temp table mycount(cc BIGINT) ON COMMIT PRESERVE ROWS;
+insert into mycount SELECT (SELECT COUNT(*) FROM sys.dependencies) + (SELECT 
COUNT(*) FROM sys.objects);
+
+alter table mt1 add table t;
+select i from mt1;
+select i from mt2; -- error, no tables associated
+
+alter table mt2 add table t;
+select i from mt1;
+select i from mt2;
+
+alter table mt1 drop table t;
+select i from mt1; -- error, no tables associated
+select i from mt2;
+
+alter table mt2 drop table t;
+select i from mt1; -- error, no tables associated
+select i from mt2; -- error, no tables associated
+
+SELECT CAST((SELECT COUNT(*) FROM sys.dependencies) + (SELECT COUNT(*) FROM 
sys.objects) - (SELECT cc FROM mycount) AS BIGINT);
+       -- 0 it shouldn't have increased
+
+drop table mycount;
+drop table mt1;
+drop table mt2;
+drop table t;
diff --git a/sql/test/mergetables/Tests/multiple-merge-tables.stable.err 
b/sql/test/mergetables/Tests/multiple-merge-tables.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/mergetables/Tests/multiple-merge-tables.stable.err
@@ -0,0 +1,28 @@
+stderr of test 'multiple-merge-tables` in directory 'sql/test/mergetables` 
itself:
+
+
+# 10:32:16 >  
+# 10:32:16 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-37610" "--port=36699"
+# 10:32:16 >  
+
+MAPI  = (monetdb) /var/tmp/mtest-40339/.s.monetdb.34967
+QUERY = select i from mt2; -- error, no tables associated
+ERROR = !MERGE or REPLICA TABLE should have at least one table associated
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-40339/.s.monetdb.34967
+QUERY = select i from mt1; -- error, no tables associated
+ERROR = !MERGE or REPLICA TABLE should have at least one table associated
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-37610/.s.monetdb.36699
+QUERY = select i from mt1; -- error, no tables associated
+ERROR = !MERGE or REPLICA TABLE should have at least one table associated
+CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-37610/.s.monetdb.36699
+QUERY = select i from mt2; -- error, no tables associated
+ERROR = !MERGE or REPLICA TABLE should have at least one table associated
+CODE  = 42000
+
+# 10:32:16 >  
+# 10:32:16 >  "Done."
+# 10:32:16 >  
+
diff --git a/sql/test/mergetables/Tests/multiple-merge-tables.stable.out 
b/sql/test/mergetables/Tests/multiple-merge-tables.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/mergetables/Tests/multiple-merge-tables.stable.out
@@ -0,0 +1,64 @@
+stdout of test 'multiple-merge-tables` in directory 'sql/test/mergetables` 
itself:
+
+
+# 10:32:16 >  
+# 10:32:16 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-37610" "--port=36699"
+# 10:32:16 >  
+
+#create table t (i int);
+#insert into t values (42), (666);
+[ 2    ]
+#create merge table mt1 (like t);
+#create merge table mt2 (like t);
+#create temp table mycount(cc BIGINT) ON COMMIT PRESERVE ROWS;
+#insert into mycount SELECT (SELECT COUNT(*) FROM sys.dependencies) + (SELECT 
COUNT(*) FROM sys.objects);
+[ 1    ]
+#alter table mt1 add table t;
+#select i from mt1;
+% sys.mt1 # table_name
+% i # name
+% int # type
+% 3 # length
+[ 42   ]
+[ 666  ]
+#alter table mt2 add table t;
+#select i from mt1;
+% sys.mt1 # table_name
+% i # name
+% int # type
+% 3 # length
+[ 42   ]
+[ 666  ]
+#select i from mt2;
+% sys.mt2 # table_name
+% i # name
+% int # type
+% 3 # length
+[ 42   ]
+[ 666  ]
+#alter table mt1 drop table t;
+#select i from mt2;
+% sys.mt2 # table_name
+% i # name
+% int # type
+% 3 # length
+[ 42   ]
+[ 666  ]
+#alter table mt2 drop table t;
+#SELECT CAST((SELECT COUNT(*) FROM sys.dependencies) + (SELECT COUNT(*) FROM 
sys.objects) - (SELECT cc FROM mycount) AS BIGINT);
+% .%4 # table_name
+% %4 # name
+% bigint # type
+% 1 # length
+[ 0    ]
+#drop table mycount;
+#drop table mt1;
+#drop table mt2;
+#drop table t;
+
+
+
+# 10:32:16 >  
+# 10:32:16 >  "Done."
+# 10:32:16 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to