Changeset: cc2f9c2ac8a2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cc2f9c2ac8a2
Modified Files:
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/sql.c
        sql/include/sql_relation.h
        sql/server/rel_schema.c
        sql/storage/store.c
Branch: Jan2014
Log Message:

fix for bug 3435. Indices created on tables already holding data
are properly initialized again.
fixed a bug when loading using LOCKED. The properties weren't properly checked


diffs (183 lines):

diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -258,24 +258,19 @@ TABLETcollect_parts(Tablet *as, BUN offs
                BAT *bv = NULL;
 
                BATsetaccess(b, BAT_READ);
-               bv = BATslice(b, offset, BATcount(b));
+               bv = BATslice(b, (offset>0)?offset-1:0, BATcount(b));
                bats[i] = bv;
                BATderiveProps(bv, 1);
 
-               b->hkey &= bv->hkey;
-               b->tkey &= bv->tkey;
-               b->H->nonil &= bv->H->nonil;
+               b->tkey = (offset>0)?FALSE:bv->tkey; 
                b->T->nonil &= bv->T->nonil;
-               b->hdense &= bv->hdense;
                b->tdense &= bv->tdense;
-               if (b->hsorted != bv->hsorted)
-                       b->hsorted = 0;
-               if (b->hrevsorted != bv->hrevsorted)
-                       b->hrevsorted = 0;
                if (b->tsorted != bv->tsorted)
                        b->tsorted = 0;
                if (b->trevsorted != bv->trevsorted)
                        b->trevsorted = 0;
+               if (b->tdense)
+                       b->tkey = TRUE;
                b->batDirty = TRUE;
 
                if (cnt != BATcount(b)) {
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -503,7 +503,7 @@ alter_table(mvc *sql, char *sname, sql_t
                if (nt->pkey) {
                        for (n = t->idxs.nelm; n; n = n->next) {
                                sql_idx *i = n->data;
-                               if (i->key->type == pkey)
+                               if (i->key && i->key->type == pkey)
                                        return sql_message("40000!CONSTRAINT 
PRIMARY KEY: a table can have only one PRIMARY KEY\n");
                        }
                }
@@ -1184,6 +1184,7 @@ SQLcatalog(Client cntxt, MalBlkPtr mb, M
                int itype = *(int *) getArgReference(stk, pci, 3);
                char *ssname = *(str *) getArgReference(stk, pci, 4);
                char *tname = *(str *) getArgReference(stk, pci, 5);
+               assert(0); /* not used anymore */
                msg = create_index(sql, sname, itype, ssname, tname, stk, pci);
                break;
        }
diff --git a/sql/include/sql_relation.h b/sql/include/sql_relation.h
--- a/sql/include/sql_relation.h
+++ b/sql/include/sql_relation.h
@@ -107,7 +107,7 @@ typedef struct expression {
 #define DDL_CREATE_TYPE 30 
 #define DDL_DROP_TYPE   31 
 
-#define DDL_CREATE_INDEX  32
+#define DDL_CREATE_INDEX  32   /* not used anymore */
 #define DDL_DROP_INDEX    33
 
 #define DDL_CREATE_FUNCTION 41 
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
@@ -1491,36 +1491,55 @@ rel_revoke_privs(mvc *sql, sql_schema *c
 
 /* iname, itype, sname.tname (col1 .. coln) */
 static sql_rel *
-rel_create_index(mvc *sql, sql_schema *ss, char *iname, int itype, dlist 
*qname, dlist *column_list)
+rel_create_index(mvc *sql, char *iname, int itype, dlist *qname, dlist 
*column_list)
 {
-       sql_allocator *sa = sql->sa;
-       sql_rel *rel = rel_create(sa);
-       list *exps = new_exp_list(sa);
+       sql_schema *s = NULL;
+       sql_table *t, *nt;
+       sql_rel *r, *res;
+       sql_exp ** updates, *e;
+       sql_idx *i;
+       dnode *n;
+       char *sname = qname_schema(qname);
        char *tname = qname_table(qname);
-       char *sname = qname_schema(qname);
-       dnode *n = column_list->h;
+              
+       if (sname && !(s = mvc_bind_schema(sql, sname))) 
+               return sql_error(sql, 02, "3F000!CREATE INDEX: no such schema 
'%s'", sname);
+       if (!s) 
+               s = cur_schema(sql);
+       i = mvc_bind_idx(sql, s, iname);
+       if (i) 
+               return sql_error(sql, 02, "42S11!CREATE INDEX: name '%s' 
already in use", iname);
+       t = mvc_bind_table(sql, s, tname);
+       if (!t) {
+               return sql_error(sql, 02, "42S02!CREATE INDEX: no such table 
'%s'", tname);
+       } else if (isView(t)) {
+               return sql_error(sql, 02, "42S02!CREATE INDEX: cannot create 
index on view '%s'", tname);
+       }
+       sname = get_schema_name( sql, sname, tname);
+       nt = dup_sql_table(sql->sa, t);
 
-       if (!sname && ss)
-               sname = ss->base.name;
+       if (t->persistence != SQL_DECLARED_TABLE && s)
+               sname = s->base.name;
+       if (t->s && !nt->s)
+               nt->s = t->s;
 
-       append(exps, exp_atom_clob(sa, iname));
-       append(exps, exp_atom_int(sa, itype));
-       append(exps, exp_atom_clob(sa, sname));
-       append(exps, exp_atom_clob(sa, tname));
+       /* add index here */
+       i = mvc_create_idx(sql, nt, iname, itype);
+       for (n = column_list->h; n; n = n->next) {
+               sql_column *c = mvc_bind_column(sql, nt, n->data.sval);
 
-       for (; n; n = n->next) {
-               char *cname = n->data.sval;
+               if (!c) 
+                       return sql_error(sql, 02, "42S22!CREATE INDEX: no such 
column '%s'", n->data.sval);
+               mvc_create_ic(sql, i, c);
+       }
 
-               append(exps, exp_atom_clob(sa, cname));
-       }
-       rel->l = NULL;
-       rel->r = NULL;
-       rel->op = op_ddl;
-       rel->flag = DDL_CREATE_INDEX;
-       rel->exps = exps;
-       rel->card = 0;
-       rel->nrcols = 0;
-       return rel;
+       /* new columns need update with default values */
+       updates = table_update_array(sql, nt); 
+       e = exp_column(sql->sa, nt->base.name, "%TID%", 
sql_bind_localtype("oid"), CARD_MULTI, 0, 1);
+       res = rel_table(sql, DDL_ALTER_TABLE, sname, nt, 0);
+       r = rel_project(sql->sa, res, append(new_exp_list(sql->sa),e));
+       res = rel_update(sql, res, r, updates, NULL); 
+       return res;
 }
 
 static sql_rel *
@@ -1704,7 +1723,7 @@ rel_schemas(mvc *sql, symbol *s)
                dlist *l = s->data.lval;
 
                assert(l->h->next->type == type_int);
-               ret = rel_create_index(sql, cur_schema(sql), l->h->data.sval, 
l->h->next->data.i_val, l->h->next->next->data.lval, 
l->h->next->next->next->data.lval);
+               ret = rel_create_index(sql, l->h->data.sval, 
l->h->next->data.i_val, l->h->next->next->data.lval, 
l->h->next->next->next->data.lval);
        }       break;
        case SQL_DROP_INDEX: {
                dlist *l = s->data.lval;
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -1820,6 +1820,8 @@ sql_trans_copy_idx( sql_trans *tr, sql_t
 
                table_funcs.table_insert(tr, sysic, &ni->base.id, 
ic->c->base.name, &nr);
                sysic->base.wtime = sysic->s->base.wtime = tr->wtime = 
tr->wstime;
+
+               sql_trans_create_dependency(tr, ic->c->base.id, i->base.id, 
INDEX_DEPENDENCY);
        }
        list_append(t->s->idxs, ni);
        cs_add(&t->idxs, ni, TR_NEW);
@@ -4622,8 +4624,12 @@ void
 sql_trans_drop_idx(sql_trans *tr, sql_schema *s, int id, int drop_action)
 {
        node *n = list_find_base_id(s->idxs, id);
-       sql_idx *i = n->data;
-       
+       sql_idx *i;
+       
+       if (!n) /* allready dropped */
+               return;
+
+       i = n->data;
        if (drop_action == DROP_CASCADE_START || drop_action == DROP_CASCADE) {
                int *local_id = NEW(int);
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to