Changeset: c4a349032405 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c4a349032405
Modified Files:
        sql/server/rel_optimizer.c
        sql/server/rel_schema.c
        sql/storage/store.c
        sql/test/BugTracker-2015/Tests/readonly.Bug-3709.stable.err
        sql/test/mergetables/Tests/forex.stable.out
        sql/test/mergetables/Tests/forex.stable.out.int128
        sql/test/mergetables/Tests/forex1.sql
Branch: default
Log Message:

fixed several problems with merge table,
        properly handle alter table drop table.
        check if a bat is already part of a merge table
        fixed problems with single table merge tables


diffs (221 lines):

diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -6535,7 +6535,7 @@ rel_merge_table_rewrite(int *changes, mv
                if (isMergeTable(t)) {
                        /* instantiate merge tabel */
                        sql_rel *nrel = NULL;
-                       char *tname = exp_find_rel_name(rel->exps->h->data);
+                       char *tname = t->base.name;
                        list *cols = NULL, *low = NULL, *high = NULL;
 
                        if (list_empty(t->tables.set)) 
@@ -6591,10 +6591,10 @@ rel_merge_table_rewrite(int *changes, mv
                                                continue;
                                        }
 
-                                       /* rename (mostly the idxs) */
                                        MT_lock_set(&prel->exps->ht_lock, 
"rel_merge_table_rewrite");
                                        prel->exps->ht = NULL;
                                        MT_lock_unset(&prel->exps->ht_lock, 
"rel_merge_table_rewrite");
+                                       /* rename (mostly the idxs) */
                                        for (n = rel->exps->h, m = 
prel->exps->h; n && m && !skip; n = n->next, m = m->next ) {
                                                sql_exp *e = n->data;
                                                sql_exp *ne = m->data;
@@ -6616,7 +6616,8 @@ rel_merge_table_rewrite(int *changes, mv
                                                                        skip = 
1;
                                                        }
                                                }
-                                               exp_setname(sql->sa, ne, 
e->rname, e->name);
+                                               assert(e->type == e_column);
+                                               exp_setname(sql->sa, ne, e->l, 
e->r);
                                        }
                                        if (!skip) {
                                                append(tables, prel);
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -1182,6 +1182,10 @@ rel_alter_table(mvc *sql, dlist *qname, 
 
                        /* check tables */
                        if (nnt) {
+                               node *n = cs_find_id(&nt->tables, nnt->base.id);
+                       
+                               if (n)
+                                       return sql_error(sql, 02, "42S02!ALTER 
TABLE: table '%s' is already part of the MERGE TABLE '%s.%s'", ntname, sname, 
tname);
                                if (rel_check_tables(sql, t, nnt) < 0)
                                        return NULL;
                                cs_add(&nt->tables, nnt, TR_NEW); 
@@ -1190,12 +1194,11 @@ rel_alter_table(mvc *sql, dlist *qname, 
                /* table drop table */
                if (te->token == SQL_DROP_TABLE) {
                        char *ntname = te->data.lval->h->data.sval;
+                       sql_table *ntt = mvc_bind_table(sql, s, ntname);
                        int drop_action = te->data.lval->h->next->data.i_val;
-                       node *n = cs_find_name(&nt->tables, ntname);
+                       node *n = cs_find_id(&nt->tables, ntt->base.id);
 
                        if (n) {
-                               sql_table *ntt = n->data;
-
                                ntt->drop_action = drop_action;
                                cs_del(&nt->tables, n, ntt->base.flag); 
                        }
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -1139,8 +1139,8 @@ bootstrap_create_column(sql_trans *tr, s
        return col;
 }
 
-sql_table *
-create_sql_table(sql_allocator *sa, const char *name, sht type, bit system, 
int persistence, int commit_action)
+static sql_table *
+create_sql_table_with_id(sql_allocator *sa, int id, const char *name, sht 
type, bit system, int persistence, int commit_action)
 {
        sql_table *t = SA_ZNEW(sa, sql_table);
 
@@ -1148,7 +1148,8 @@ create_sql_table(sql_allocator *sa, cons
        assert((persistence==SQL_PERSIST ||
                persistence==SQL_DECLARED_TABLE || 
                commit_action) && commit_action>=0);
-       base_init(sa, &t->base, next_oid(), TR_NEW, name);
+       assert(id);
+       base_init(sa, &t->base, id, TR_NEW, name);
        t->type = type;
        t->system = system;
        t->persistence = (temp_t)persistence;
@@ -1166,6 +1167,12 @@ create_sql_table(sql_allocator *sa, cons
        return t;
 }
 
+sql_table *
+create_sql_table(sql_allocator *sa, const char *name, sht type, bit system, 
int persistence, int commit_action)
+{
+       return create_sql_table_with_id(sa, next_oid(), name, type, system, 
persistence, commit_action);
+}
+
 static sql_column *
 dup_sql_column(sql_allocator *sa, sql_table *t, sql_column *c)
 {
@@ -1189,11 +1196,32 @@ dup_sql_column(sql_allocator *sa, sql_ta
        return col;
 }
 
+static sql_table *
+dup_sql_ptable(sql_allocator *sa, sql_table *mt, sql_table *t)
+{
+       node *n;
+       sql_table *nt = create_sql_table_with_id(sa, t->base.id, t->base.name, 
t->type, t->system, SQL_DECLARED_TABLE, t->commit_action);
+
+       nt->base.flag = t->base.flag;
+
+       nt->access = t->access;
+       nt->query = (t->query) ? sa_strdup(sa, t->query) : NULL;
+
+       for (n = t->columns.set->h; n; n = n->next) 
+               dup_sql_column(sa, nt, n->data);
+       nt->columns.dset = NULL;
+       nt->columns.nelm = NULL;
+       cs_add(&mt->tables, nt, TR_NEW);
+       /* we need a valid schema */
+       nt->s = t->s;
+       return nt;
+}
+
 sql_table *
 dup_sql_table(sql_allocator *sa, sql_table *t)
 {
        node *n;
-       sql_table *nt = create_sql_table(sa, t->base.name, t->type, t->system, 
SQL_DECLARED_TABLE, t->commit_action);
+       sql_table *nt = create_sql_table_with_id(sa, t->base.id, t->base.name, 
t->type, t->system, SQL_DECLARED_TABLE, t->commit_action);
 
        nt->base.flag = t->base.flag;
 
@@ -1204,6 +1232,12 @@ dup_sql_table(sql_allocator *sa, sql_tab
                dup_sql_column(sa, nt, n->data);
        nt->columns.dset = NULL;
        nt->columns.nelm = NULL;
+
+       if (t->tables.set)
+               for (n = t->tables.set->h; n; n = n->next) 
+                       dup_sql_ptable(sa, nt, n->data);
+       nt->tables.dset = NULL;
+       nt->tables.nelm = NULL;
        return nt;
 }
 
@@ -3953,7 +3987,7 @@ sql_trans_drop_schema(sql_trans *tr, int
                
 }
 
- sql_table *
+sql_table *
 sql_trans_add_table(sql_trans *tr, sql_table *mt, sql_table *pt)
 {
        sql_schema *syss = find_sql_schema(tr, isGlobal(mt)?"sys":"tmp");
@@ -3978,7 +4012,7 @@ sql_trans_del_table(sql_trans *tr, sql_t
        oid rid = table_funcs.column_find_row(tr, find_sql_column(sysobj, 
"name"), pt->base.name, NULL);
 
        /* merge table depends on part table */
-       sql_trans_create_dependency(tr, pt->base.id, mt->base.id, 
TABLE_DEPENDENCY);
+       sql_trans_drop_dependency(tr, pt->base.id, mt->base.id, 
TABLE_DEPENDENCY);
        cs_del(&mt->tables, n, pt->base.flag);
        mt->s->base.wtime = mt->base.wtime = tr->wtime = tr->wstime;
        table_funcs.table_delete(tr, sysobj, rid);
diff --git a/sql/test/BugTracker-2015/Tests/readonly.Bug-3709.stable.err 
b/sql/test/BugTracker-2015/Tests/readonly.Bug-3709.stable.err
--- a/sql/test/BugTracker-2015/Tests/readonly.Bug-3709.stable.err
+++ b/sql/test/BugTracker-2015/Tests/readonly.Bug-3709.stable.err
@@ -30,10 +30,10 @@ stderr of test 'readonly.Bug-3709` in di
 # 21:17:25 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-5516" "--port=31025"
 # 21:17:25 >  
 
-MAPI  = (monetdb) /var/tmp/mtest-5516/.s.monetdb.31025
+MAPI  = (monetdb) /var/tmp/mtest-15194/.s.monetdb.36528
 QUERY = alter table s10 set read only; 
-ERROR = !ALTER TABLE: set READONLY not possible with outstanding updates (wait 
until updates are flushed)
-MAPI  = (monetdb) /var/tmp/mtest-5516/.s.monetdb.31025
+ERROR = !ALTER TABLE: set READ or INSERT ONLY not possible with outstanding 
updates (wait until updates are flushed)
+MAPI  = (monetdb) /var/tmp/mtest-15194/.s.monetdb.36528
 QUERY = trace select * from s10; 
 ERROR = !current transaction is aborted (please ROLLBACK)
 
diff --git a/sql/test/mergetables/Tests/forex.stable.out 
b/sql/test/mergetables/Tests/forex.stable.out
--- a/sql/test/mergetables/Tests/forex.stable.out
+++ b/sql/test/mergetables/Tests/forex.stable.out
@@ -214,7 +214,6 @@ Ready.
 % clk, currency,       ts,     bid,    offer,  spread # name
 % timestamp,   clob,   timestamp,      decimal,        decimal,        decimal 
# type
 % 26,  7,      26,     14,     14,     14 # length
-[ 2014-10-14 06:12:51.000000,  "EUR/USD",      2014-10-14 06:12:38.643000,     
1.271810,       1.271890,       0.000080        ]
 [ 2014-10-14 06:12:56.000000,  "EUR/USD",      2014-10-14 06:12:57.168000,     
1.271780,       1.271880,       0.000100        ]
 [ 2014-10-14 06:13:01.000000,  "EUR/USD",      2014-10-14 06:13:02.327000,     
1.271910,       1.271990,       0.000080        ]
 #DROP TABLE forex;
diff --git a/sql/test/mergetables/Tests/forex.stable.out.int128 
b/sql/test/mergetables/Tests/forex.stable.out.int128
--- a/sql/test/mergetables/Tests/forex.stable.out.int128
+++ b/sql/test/mergetables/Tests/forex.stable.out.int128
@@ -214,7 +214,6 @@ Ready.
 % clk, currency,       ts,     bid,    offer,  spread # name
 % timestamp,   clob,   timestamp,      decimal,        decimal,        decimal 
# type
 % 26,  7,      26,     14,     14,     14 # length
-[ 2014-10-14 06:12:51.000000,  "EUR/USD",      2014-10-14 06:12:38.643000,     
1.271810,       1.271890,       0.000080        ]
 [ 2014-10-14 06:12:56.000000,  "EUR/USD",      2014-10-14 06:12:57.168000,     
1.271780,       1.271880,       0.000100        ]
 [ 2014-10-14 06:13:01.000000,  "EUR/USD",      2014-10-14 06:13:02.327000,     
1.271910,       1.271990,       0.000080        ]
 #DROP TABLE forex;
diff --git a/sql/test/mergetables/Tests/forex1.sql 
b/sql/test/mergetables/Tests/forex1.sql
--- a/sql/test/mergetables/Tests/forex1.sql
+++ b/sql/test/mergetables/Tests/forex1.sql
@@ -3,12 +3,9 @@ CREATE TABLE forex1 ( clk timestamp, cur
 ALTER TABLE forex1 SET READ ONLY;
 ALTER TABLE forex ADD TABLE forex1;
 
-PLAN SELECT X.clk FROM forex AS X;
-
--- did not show a plan nor resultset
-EXPLAIN SELECT X.clk FROM forex AS X;
 SELECT X.clk FROM forex AS X;
 
 -- drop the single partition
+ALTER TABLE forex DROP TABLE forex1;
 DROP TABLE forex1;
 DROP TABLE forex;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to