Changeset: c2460711a8a4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c2460711a8a4
Modified Files:
        gdk/gdk_aggr.c
        monetdb5/optimizer/opt_constants.c
        sql/server/sql_mvc.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: context
Log Message:

merged with default


diffs (truncated from 333 to 300 lines):

diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -100,26 +100,26 @@ BATgroupaggrinit(BAT *b, BAT *g, BAT *e,
                        } else if (g->tsorted) {
                                gids = (const oid *) Tloc(g, 0);
                                /* find first non-nil */
-                               for (i = 0, ngrp = BATcount(g); i < ngrp; i++, 
gids++) {
-                                       if (!is_oid_nil(*gids)) {
-                                               min = *gids;
+                               for (i = 0, ngrp = BATcount(g); i < ngrp; i++) {
+                                       if (!is_oid_nil(gids[i])) {
+                                               min = gids[i];
                                                break;
                                        }
                                }
                                if (!is_oid_nil(min)) {
                                        /* found a non-nil, max must be last
                                         * value (and there is one!) */
-                                       max = * (const oid *) Tloc(g, 
BUNlast(g) - 1);
+                                       max = gids[BUNlast(g) - 1];
                                }
                        } else {
                                /* we'll do a complete scan */
                                gids = (const oid *) Tloc(g, 0);
-                               for (i = 0, ngrp = BATcount(g); i < ngrp; i++, 
gids++) {
-                                       if (!is_oid_nil(*gids)) {
-                                               if (*gids < min)
-                                                       min = *gids;
-                                               if (*gids > max)
-                                                       max = *gids;
+                               for (i = 0, ngrp = BATcount(g); i < ngrp; i++) {
+                                       if (!is_oid_nil(gids[i])) {
+                                               if (gids[i] < min)
+                                                       min = gids[i];
+                                               if (gids[i] > max)
+                                                       max = gids[i];
                                        }
                                }
                                /* note: max < min is possible if all groups
@@ -799,7 +799,7 @@ BATgroupsum(BAT *b, BAT *g, BAT *e, BAT 
        if (BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        nils = dosum(Tloc(b, 0), b->tnonil, b->hseqbase, start, end,
                     Tloc(bn, 0), ngrp, b->ttype, tp,
@@ -1398,7 +1398,7 @@ BATgroupprod(BAT *b, BAT *g, BAT *e, BAT
        if (BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        nils = doprod(Tloc(b, 0), b->hseqbase, start, end,
                      Tloc(bn, 0), ngrp, b->ttype, tp,
@@ -1671,7 +1671,7 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
        if (BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        switch (b->ttype) {
        case TYPE_bte:
@@ -1991,7 +1991,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        if (BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        if (!skip_nils || b->tnonil) {
                /* if nils are nothing special, or if there are no
@@ -2134,7 +2134,7 @@ BATgroupsize(BAT *b, BAT *g, BAT *e, BAT
        if (BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        bits = (const bit *) Tloc(b, 0);
 
@@ -2523,7 +2523,7 @@ BATgroupminmax(BAT *b, BAT *g, BAT *e, B
        if (g == NULL || BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        nils = (*minmax)(oids, b, gids, ngrp, min, max, start, end,
                         cand, candend, BATcount(b), skip_nils,
@@ -3201,7 +3201,7 @@ dogroupstdev(BAT **avgb, BAT *b, BAT *g,
        if (BATtdense(g))
                gids = NULL;
        else
-               gids = (const oid *) Tloc(g, start);
+               gids = (const oid *) Tloc(g, 0);
 
        switch (b->ttype) {
        case TYPE_bte:
diff --git a/monetdb5/optimizer/opt_constants.c 
b/monetdb5/optimizer/opt_constants.c
--- a/monetdb5/optimizer/opt_constants.c
+++ b/monetdb5/optimizer/opt_constants.c
@@ -17,6 +17,10 @@
 /*
  * We have to keep an alias table to reorganize the program
  * after the variable stack has changed.
+ * The plan may contain many constants and to check them all would be 
quadratic 
+ * in the size of the constant list.
+ * The heuristic is to look back into the list only partially.
+ * A hash structure could help out with further reduction.
  */
 #include "monetdb_config.h"
 #include "mal_instruction.h"
@@ -25,7 +29,7 @@
 str
 OPTconstantsImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
p)
 {
-       int i,k=1, n=0, fnd=0, actions=0;
+       int i, k = 1, n  = 0, fnd = 0, actions  = 0, limit = 0;
        int *alias, *index;
        VarPtr x,y, *cst;
        char buf[256];
@@ -50,12 +54,13 @@ OPTconstantsImplementation(Client cntxt,
 
        for (i=0; i< mb->vtop; i++)
                alias[ i]= i;
-       for (i=0; i< mb->vtop && n < 100; i++)
+       for (i=0; i< mb->vtop; i++)
                if ( isVarConstant(mb,i)  && isVarFixed(mb,i)  && 
getVarType(mb,i) != TYPE_ptr){
                        x= getVar(mb,i); 
                        fnd = 0;
+                       limit = n - 128; // don't look to far back
                        if ( x->type && x->value.vtype)
-                       for( k= n-1; k>=0; k--){
+                       for( k = n-1; k >= 0 && k > limit; k--){
                                y= cst[k];
                                if ( x->type == y->type &&
                                         x->rowcnt == y->rowcnt &&
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
@@ -407,7 +407,7 @@ mvc_commit(mvc *m, int chain, const char
                if (mvc_debug)
                        fprintf(stderr, "#mvc_savepoint\n");
                store_lock();
-               m->session->tr = sql_trans_create(tr, name);
+               m->session->tr = sql_trans_create(tr, name, true);
                if(!m->session->tr) {
                        store_unlock();
                        msg = createException(SQL, "sql.commit", 
SQLSTATE(HY001) "%s allocation failure while committing the transaction, will 
ROLLBACK instead", operation);
@@ -444,7 +444,7 @@ mvc_commit(mvc *m, int chain, const char
                        ctr = sql_trans_deref(ctr);
                }
                while (tr->parent != NULL && ok == SQL_OK) 
-                       tr = sql_trans_destroy(tr);
+                       tr = sql_trans_destroy(tr, true);
                store_unlock();
        }
        cur -> parent = tr;
@@ -543,7 +543,7 @@ mvc_rollback(mvc *m, int chain, const ch
                        /* make sure we do not reuse changed data */
                        if (tr->wtime)
                                tr->status = 1;
-                       tr = sql_trans_destroy(tr);
+                       tr = sql_trans_destroy(tr, true);
                }
                m->session->tr = tr;    /* restart at savepoint */
                m->session->status = tr->status;
@@ -553,7 +553,7 @@ mvc_rollback(mvc *m, int chain, const ch
        } else if (tr->parent) {
                /* first release all intermediate savepoints */
                while (tr->parent->parent != NULL) {
-                       tr = sql_trans_destroy(tr);
+                       tr = sql_trans_destroy(tr, true);
                }
                m->session-> tr = tr;
                /* make sure we do not reuse changed data */
@@ -614,7 +614,7 @@ mvc_release(mvc *m, const char *name)
                /* commit all intermediate savepoints */
                if (sql_trans_commit(tr) != SQL_OK)
                        GDKfatal("release savepoints should not fail");
-               tr = sql_trans_destroy(tr);
+               tr = sql_trans_destroy(tr, true);
        }
        tr->name = NULL;
        store_unlock();
@@ -702,7 +702,7 @@ mvc_reset(mvc *m, bstream *rs, stream *w
                assert(m->session->tr->active == 0);
                store_lock();
                while (tr->parent->parent != NULL) 
-                       tr = sql_trans_destroy(tr);
+                       tr = sql_trans_destroy(tr, true);
                store_unlock();
        }
        if (tr && !sql_session_reset(m->session, 1 /*autocommit on*/))
@@ -759,7 +759,7 @@ mvc_destroy(mvc *m)
                if (m->session->tr->active)
                        sql_trans_end(m->session);
                while (tr->parent)
-                       tr = sql_trans_destroy(tr);
+                       tr = sql_trans_destroy(tr, true);
                m->session->tr = NULL;
                store_unlock();
        }
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -357,8 +357,8 @@ extern void store_lock(void);
 extern void store_unlock(void);
 extern int store_next_oid(void);
 
-extern sql_trans *sql_trans_create(sql_trans *parent, const char *name);
-extern sql_trans *sql_trans_destroy(sql_trans *tr);
+extern sql_trans *sql_trans_create(sql_trans *parent, const char *name, bool 
try_spare);
+extern sql_trans *sql_trans_destroy(sql_trans *tr, bool try_spare);
 extern bool sql_trans_validate(sql_trans *tr);
 extern int sql_trans_commit(sql_trans *tr);
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -218,7 +218,7 @@ trans_drop_tmp(sql_trans *tr)
 #endif
 
 sql_trans *
-sql_trans_destroy(sql_trans *t)
+sql_trans_destroy(sql_trans *t, bool try_spare)
 {
        sql_trans *res = t->parent;
 
@@ -226,7 +226,7 @@ sql_trans_destroy(sql_trans *t)
        fprintf(stderr, "#destroy trans (%p)\n", t);
 #endif
 
-       if (res == gtrans && spares < MAX_SPARES && !t->name) {
+       if (res == gtrans && spares < MAX_SPARES && !t->name && try_spare) {
 #ifdef STORE_DEBUG
                fprintf(stderr, "#spared (%d) trans (%p)\n", spares, t);
 #endif
@@ -252,7 +252,7 @@ destroy_spare_transactions(void)
 
        spares = MAX_SPARES; /* ie now there not spared anymore */
        for (i = 0; i < s; i++) {
-               sql_trans_destroy(spare_trans[i]);
+               sql_trans_destroy(spare_trans[i], false);
        }
        spares = 0;
 }
@@ -1790,7 +1790,7 @@ store_load(sql_allocator *pa) {
                /* cannot initialize database in readonly mode */
                if (store_readonly)
                        return -1;
-               tr = sql_trans_create(NULL, NULL);
+               tr = sql_trans_create(NULL, NULL, true);
                if (!tr) {
                        fprintf(stderr, "Failure to start a transaction while 
loading the storage\n");
                        return -1;
@@ -1959,7 +1959,7 @@ store_load(sql_allocator *pa) {
                if (sql_trans_commit(tr) != SQL_OK) {
                        fprintf(stderr, "cannot commit initial transaction\n");
                }
-               sql_trans_destroy(tr);
+               sql_trans_destroy(tr, true);
        } else {
                GDKqsort(store_oids, NULL, NULL, nstore_oids, sizeof(sqlid), 0, 
TYPE_int, false, false);
                store_oid = store_oids[nstore_oids - 1] + 1;
@@ -2190,7 +2190,7 @@ store_exit(void)
           exit (but leak memory).
         */
        if (!transactions) {
-               sql_trans_destroy(gtrans);
+               sql_trans_destroy(gtrans, false);
                gtrans = NULL;
        }
 #ifdef STORE_DEBUG
@@ -4200,12 +4200,12 @@ reset_trans(sql_trans *tr, sql_trans *pt
 }
 
 sql_trans *
-sql_trans_create(sql_trans *parent, const char *name)
+sql_trans_create(sql_trans *parent, const char *name, bool try_spare)
 {
        sql_trans *tr = NULL;
 
        if (gtrans) {
-               if (!parent && spares > 0 && !name) {
+               if (!parent && spares > 0 && !name && try_spare) {
                        tr = spare_trans[--spares];
 #ifdef STORE_DEBUG
                        fprintf(stderr, "#reuse trans (%p) %d\n", tr, spares);
@@ -6633,7 +6633,7 @@ sql_session_create(int ac )
        s = ZNEW(sql_session);
        if (!s)
                return NULL;
-       s->tr = sql_trans_create(NULL, NULL);
+       s->tr = sql_trans_create(NULL, NULL, true);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to