Changeset: d7d2d16a8a40 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d7d2d16a8a40
Modified Files:
        monetdb5/optimizer/opt_garbageCollector.c
        sql/backends/monet5/sql.c
        sql/server/rel_optimizer.c
        sql/server/sql_mvc.c
        sql/storage/bat/bat_storage.c
        sql/storage/store.c
Branch: default
Log Message:

merged with Apr2019


diffs (truncated from 319 to 300 lines):

diff --git a/monetdb5/optimizer/opt_garbageCollector.c 
b/monetdb5/optimizer/opt_garbageCollector.c
--- a/monetdb5/optimizer/opt_garbageCollector.c
+++ b/monetdb5/optimizer/opt_garbageCollector.c
@@ -25,13 +25,13 @@
 str
 OPTgarbageCollectorImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci)
 {
-       int arg, i, j, limit, slimit;
+       int i, j, limit, slimit;
        InstrPtr p, *old;
        int actions = 0;
        char buf[256];
        lng usec = GDKusec();
        str msg = MAL_SUCCEED;
-       str nme;
+       //str nme;
        char *used;
        //int *varlnk, *stmtlnk;
 
@@ -60,6 +60,15 @@ OPTgarbageCollectorImplementation(Client
        slimit = mb->ssize;
        //vlimit = mb->vtop;
 
+       /* rename all temporaries used for ease of debugging and profile 
interpretation */
+
+       for( i = 0; i < mb->vtop; i++)
+               if( sscanf(getVarName(mb,i),"X_%d", &j) == 1)
+                       snprintf(getVarName(mb,i),IDLENGTH,"X_%d",i);
+               else
+               if( sscanf(getVarName(mb,i),"C_%d", &j) == 1)
+                       snprintf(getVarName(mb,i),IDLENGTH,"C_%d",i);
+
        // move SQL query definition to the front for event profiling tools
        p = NULL;
        for(i = 0; i < limit; i++)
@@ -98,6 +107,9 @@ OPTgarbageCollectorImplementation(Client
                /* Set the program counter to ease profiling */
                p->pc = i;
                /* rename all temporaries used for ease of debugging and 
profile interpretation */
+/* lets check if this is the culprit for DS22 on april
+ * Remove the use of 'used' and only looking at returns. 
+ * It should be sufficient to look into the variable table
                for( j = 0; j< p->retc; j++){
                        arg = getArg(p,j);
                        if( used[arg] ==0){
@@ -110,6 +122,7 @@ OPTgarbageCollectorImplementation(Client
                                used[arg] ++;
                        }
                }
+*/
 
                if ( p->barrier == RETURNsymbol){
                        pushInstruction(mb, p);
@@ -122,8 +135,8 @@ OPTgarbageCollectorImplementation(Client
 
                /* A block exit is never within a parallel block,
                 * otherwise we could not inject the assignment */
-                       /* force garbage collection of all declared within 
output block and ending here  */
-/* ignore for the time being, it requires a more thorough analysis of 
dependencies.
+               /* force garbage collection of all declared within output block 
and ending here  */
+               /* ignore for the time being, it requires a more thorough 
analysis of dependencies.
                if (blockExit(p) ){
                        for( k = stmtlnk[i]; k; k = varlnk[k])
                        if( isaBatType(getVarType(mb,k)) ){
@@ -137,7 +150,7 @@ OPTgarbageCollectorImplementation(Client
                                actions++;
                        }
                }
-*/
+               */
        }
        /* A good MAL plan should end with an END instruction */
        pushInstruction(mb, p);
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
@@ -1071,7 +1071,10 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
                                        bat_destroy(vl);
                                        throw(SQL, "sql.bind", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
                                }
-                               assert(BATcount(id) == BATcount(vl));
+                               if ( BATcount(id) != BATcount(vl)){
+                                       BBPunfix(b->batCacheid);
+                                       throw(SQL, "sql.bind", SQLSTATE(0000) 
"Inconsistent BAT count");
+                               }
                                BBPkeepref(*bid = id->batCacheid);
                                BBPkeepref(*uvl = vl->batCacheid);
                        } else {
@@ -2180,7 +2183,7 @@ SQLtid(Client cntxt, MalBlkPtr mb, MalSt
 {
        bat *res = getArgReference_bat(stk, pci, 0);
        mvc *m = NULL;
-       str msg;
+       str msg = MAL_SUCCEED;
        sql_trans *tr;
        const char *sname = *getArgReference_str(stk, pci, 2);
        const char *tname = *getArgReference_str(stk, pci, 3);
@@ -2232,7 +2235,7 @@ SQLtid(Client cntxt, MalBlkPtr mb, MalSt
        if (tids == NULL)
                throw(SQL, "sql.tid", SQLSTATE(HY001) MAL_MALLOC_FAIL);
 
-       if ((dcnt=store_funcs.count_del(tr, t)) > 0) {
+       if ((dcnt = store_funcs.count_del(tr, t)) > 0) {
                BAT *d = store_funcs.bind_del(tr, t, RD_INS);
                BAT *diff;
                if (d == NULL) {
@@ -2241,8 +2244,9 @@ SQLtid(Client cntxt, MalBlkPtr mb, MalSt
                }
 
                diff = BATdiff(tids, d, NULL, NULL, false, false, BUN_NONE);
-               (void)dcnt;
-               assert(pci->argc == 6 || BATcount(diff) == (nr-dcnt));
+               // assert(pci->argc == 6 || BATcount(diff) == (nr-dcnt));
+               if( !(pci->argc == 6 || BATcount(diff) == (nr-dcnt)) )
+                       msg = createException(SQL, "sql.tid", SQLSTATE(00000) 
"Invalid sqltid state argc= %d diff=  %d, dcnt=%d", pci->argc, (int)nr, 
(int)dcnt);
                BBPunfix(d->batCacheid);
                BBPunfix(tids->batCacheid);
                if (diff == NULL)
@@ -2251,7 +2255,7 @@ SQLtid(Client cntxt, MalBlkPtr mb, MalSt
                tids = diff;
        }
        BBPkeepref(*res = tids->batCacheid);
-       return MAL_SUCCEED;
+       return msg;
 }
 
 /* unsafe pattern resultSet(tbl:bat[:str], attr:bat[:str], tpe:bat[:str], 
len:bat[:int],scale:bat[:int], cols:bat[:any]...) :int */
@@ -3281,7 +3285,6 @@ mvc_bin_import_table_wrap(Client cntxt, 
        }
        return MAL_SUCCEED;
   bailout:
-       assert(msg != MAL_SUCCEED);
        for (i = 0; i < pci->retc; i++) {
                bat bid; 
                if ((bid = *getArgReference_bat(stk, pci, i)) != 0) {
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
@@ -2965,9 +2965,12 @@ rel_case_fixup(int *changes, mvc *sql, s
                }
 
                /* get proper output first, then rewrite lower project (such 
that it can split expressions) */
-               push_down = is_simple_project(rel->op) && !rel->r && 
!rel_is_ref(rel) && !need_distinct(rel);
-               if (push_down)
+               push_down = is_simple_project(rel->op) && !rel->r && 
!rel_is_ref(rel);
+               if (push_down) {
                        res = rel_project(sql->sa, rel, rel_projections(sql, 
rel, NULL, 1, 2));
+                       if (need_distinct(rel))
+                               set_distinct(res);
+               }
 
                rel->exps = new_exp_list(sql->sa); 
                for (n = exps->h; n; n = n->next) { 
@@ -7471,7 +7474,7 @@ split_exps(mvc *sql, list *exps, sql_rel
 static sql_rel *
 rel_split_project(int *changes, mvc *sql, sql_rel *rel, int top) 
 {
-       if (is_project(rel->op) && list_length(rel->exps) && 
(is_groupby(rel->op) || rel->l)) {
+       if (is_project(rel->op) && list_length(rel->exps) && 
(is_groupby(rel->op) || rel->l) && !need_distinct(rel)) {
                list *exps = rel->exps;
                node *n;
                int funcs = 0;
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -326,7 +326,12 @@ sql_trans_deref( sql_trans *tr )
                        if (t->po) { 
                                sql_table *p = t->po;
 
-                               t->po = t->po->po;
+                               if (t->base.rtime < p->base.rtime)
+                                       t->base.rtime = p->base.rtime;
+                               if (t->base.wtime < p->base.wtime)
+                                       t->base.wtime = p->base.wtime;
+                               t->po = p->po;
+                               p->po = NULL; /* we used its reference */
                                table_destroy(p);
                        }
 
@@ -337,7 +342,12 @@ sql_trans_deref( sql_trans *tr )
                                        if (c->po) {
                                                sql_column *p = c->po;
 
-                                               c->po = c->po->po;
+                                               if (c->base.rtime < 
p->base.rtime)
+                                                       c->base.rtime = 
p->base.rtime;
+                                               if (c->base.wtime < 
p->base.wtime)
+                                                       c->base.wtime = 
p->base.wtime;
+                                               c->po = p->po;
+                                               p->po = NULL; /* we used its 
reference */
                                                column_destroy(p);
                                        }
                                }
@@ -354,7 +364,12 @@ sql_trans_deref( sql_trans *tr )
                                if (i->po) {
                                        sql_idx *p = i->po;
 
-                                       i->po = i->po->po;
+                                       if (i->base.rtime < p->base.rtime)
+                                               i->base.rtime = p->base.rtime;
+                                       if (i->base.wtime < p->base.wtime)
+                                               i->base.wtime = p->base.wtime;
+                                       i->po = p->po;
+                                       p->po = NULL; /* we used its reference 
*/
                                        idx_destroy(p);
                                }
                        }
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -2803,6 +2803,7 @@ update_table(sql_trans *tr, sql_table *f
                        } else if (oc->data && cc->base.allocated) {
                                tr_update_delta(tr, oc->data, cc->data, 
cc->unique == 1);
                        } else if (ATOMIC_GET(&store_nr_active) == 1 && 
!cc->base.allocated) {
+                               /* only deletes, merge earlier changes */
                                if (!oc->data) {
                                        sql_column *o = 
tr_find_column(tr->parent, oc);
                                        oc->data = timestamp_delta(o->data, 
oc->base.stime);
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2714,6 +2714,9 @@ trigger_dup(sql_trans *tr, int flags, sq
        return nt;
 }
 
+/* flags 0, dup from parent to new tr 
+ *      TR_NEW, dup from child tr to parent
+ * */
 static sql_column *
 column_dup(sql_trans *tr, int flags, sql_column *oc, sql_table *t)
 {
@@ -2751,6 +2754,12 @@ column_dup(sql_trans *tr, int flags, sql
 
        /* Needs copy when committing (ie from tr to gtrans) and 
         * on savepoints from tr->parent to new tr */
+       if (flags) {
+               c->base.allocated = oc->base.allocated;
+               c->data = oc->data;
+               oc->base.allocated = 0;
+               oc->data = NULL;
+       } else 
        if ((isNew(oc) && newFlagSet(flags) && tr->parent == gtrans) ||
            (oc->base.allocated && tr->parent != gtrans))
                if (isTable(c->t)) 
@@ -2948,6 +2957,12 @@ table_dup(sql_trans *tr, int flags, sql_
 
        /* Needs copy when committing (ie from tr to gtrans) and 
         * on savepoints from tr->parent to new tr */
+       if (flags) {
+               t->base.allocated = ot->base.allocated;
+               t->data = ot->data;
+               ot->base.allocated = 0;
+               ot->data = NULL;
+       } else 
        if ((isNew(ot) && newFlagSet(flags) && tr->parent == gtrans) ||
            (ot->base.allocated && tr->parent != gtrans))
                if (isTable(t))
@@ -3175,7 +3190,8 @@ trans_init(sql_trans *tr, backend_stack 
        for (m = otr->schemas.set->h, n = tr->schemas.set->h; m && n; m = 
m->next, n = n->next ) { 
                sql_schema *ps = m->data; /* parent transactions schema */
                sql_schema *s = n->data; 
-
+               int istmp = isTempSchema(ps);
+       
                if (s->base.id == ps->base.id) {
                        node *k, *l;
 
@@ -3189,6 +3205,9 @@ trans_init(sql_trans *tr, backend_stack 
 
                                t->base.rtime = t->base.wtime = 0;
                                t->base.stime = pt->base.wtime;
+                               if (!istmp && !t->base.allocated)
+                                       t->data = NULL;
+                               assert (istmp || (!t->data && 
!t->base.allocated));
 
                                if (pt->base.id == t->base.id) {
                                        node *i, *j;
@@ -3200,6 +3219,9 @@ trans_init(sql_trans *tr, backend_stack 
                                                if (pc->base.id == c->base.id) {
                                                        c->base.rtime = 
c->base.wtime = 0;
                                                        c->base.stime = 
pc->base.wtime;
+                                                       if (!istmp && 
!c->base.allocated)
+                                                               c->data = NULL;
+                                                       assert (istmp || 
(!c->data && !c->base.allocated));
                                                } else {
                                                        /* for now assert */
                                                        assert(0);
@@ -6703,12 +6725,15 @@ sql_trans_begin(sql_session *s)
                        reset_trans(tr, gtrans);
                }
        }
-       tr = trans_init(tr, tr->stk, tr->parent);
+       if (tr->parent == gtrans)
+               tr = trans_init(tr, tr->stk, tr->parent);
        tr->active = 1;
        s->schema = find_sql_schema(tr, s->schema_name);
        s->tr = tr;
-       (void) ATOMIC_INC(&store_nr_active);
-       list_append(active_sessions, s); 
+       if (tr->parent == gtrans) {
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to