Changeset: 20c47a5ce04d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=20c47a5ce04d
Modified Files:
        gdk/gdk_logger.c
        sql/backends/monet5/sql.mx
        sql/backends/monet5/sql_scenario.c
        sql/common/sql_string.c
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_storage.h
        sql/test/leaks/Tests/check0.stable.out
        sql/test/leaks/Tests/temp2.stable.out
        sql/test/leaks/Tests/temp3.stable.out
Branch: Feb2013
Log Message:

fixed usage of preallocation in sql_logger (gives again stable insert 
performance)
more usage of counts in the sql structures (reduce fix/unfix)


diffs (truncated from 578 to 300 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -729,6 +729,7 @@ logger_open(logger *lg)
        snprintf(filename, BUFSIZ, "%s%s." LLFMT, lg->dir, LOGFILE, lg->id);
 
        lg->log = open_wstream(filename);
+       lg->end = 0;
        if (mnstr_errnr(lg->log))
                return LOG_ERR;
 
@@ -1868,7 +1869,7 @@ log_tstart(logger *lg)
 
 #define DBLKSZ 8192
 #define DBLKMASK 8191
-#define SEGSZ 16*DBLKSZ
+#define SEGSZ 64*DBLKSZ
 static char zeros[DBLKSZ] = { 0 };
 
 static void
@@ -1881,7 +1882,7 @@ pre_allocate(logger *lg)
                lng s = p;
 
                if (p > lg->end) {
-                       lg->end = p & ~DBLKMASK;
+                       lg->end = (p & ~DBLKMASK);
                        if (p > DBLKSZ)
                                p -= DBLKSZ;
                }
@@ -1891,7 +1892,7 @@ pre_allocate(logger *lg)
                        lg->end += p;
                        p = 0;
                }
-               for (; p < SEGSZ; p += DBLKSZ, lg->end += DBLKSZ)
+               for (; p < SEGSZ; p += DBLKSZ, lg->end += DBLKSZ) 
                        mnstr_write(lg->log, zeros, DBLKSZ, 1);
                mnstr_fsetpos(lg->log, s);
        }
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -1310,7 +1310,6 @@ extern int sqlcleanup(mvc *c, int err);
 extern sql_rel *sql_symbol2relation(mvc *c, symbol *sym);
 extern stmt *sql_relation2stmt(mvc *c, sql_rel *r);
 
-extern BAT *mvc_bind(mvc *m, char *sname, char *tname, char *cname, int 
access);
 extern BAT *mvc_bind_dbat(mvc *m, char *sname, char *tname, int access);
 extern BAT *mvc_bind_idxbat(mvc *m, char *sname, char *tname, char *iname, int 
access);
 
@@ -3038,9 +3037,7 @@ mvc_restart_seq(Client cntxt, MalBlkPtr 
        throw(SQL, "sql.restart", "sequence %s not found", *sname);
 }
 
-
-
-BAT *
+static BAT *
 mvc_bind(mvc *m, char *sname, char *tname, char *cname, int access)
 {
        sql_trans *tr = m->session->tr;
@@ -3470,44 +3467,34 @@ DELTAbat(bat *result, bat *col, bat *uid
 {
        BAT *c, *u_id, *u_val, *u, *i = NULL, *res;
 
-       if ((u_id = BATdescriptor(*uid)) == NULL) 
+       if ((u_id = BBPquickdesc(ABS(*uid), 0)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       if (ins && (i = BATdescriptor(*ins)) == NULL) {
-               BBPunfix(u_id->batCacheid);
+       if (ins && (i = BBPquickdesc(ABS(*ins), 0)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       }
 
        /* no updates, no inserts */
        if (BATcount(u_id) == 0 && (!i || BATcount(i) == 0)) {
-               BBPunfix(u_id->batCacheid);
-               if (i) BBPunfix(i->batCacheid);
                BBPincref(*result = *col, TRUE);
                return MAL_SUCCEED;
        }
 
-       if ((c = BATdescriptor(*col)) == NULL) {
-               BBPunfix(u_id->batCacheid);
-               if (i) BBPunfix(i->batCacheid);
+       if ((c = BBPquickdesc(ABS(*col), 0)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       }
 
        /* bat may change */
        if (i && BATcount(c) == 0 && BATcount(u_id) == 0) {
-               BBPunfix(c->batCacheid);
-               BBPunfix(u_id->batCacheid);
-               BBPkeepref(*result = i->batCacheid);
+               BBPincref(*result = *ins, TRUE);
                return MAL_SUCCEED;
        }
 
+       c = BATdescriptor(*col);
        if ((res = BATcopy(c, TYPE_void, c->ttype, TRUE)) == NULL) 
                throw(MAL, "sql.delta", OPERATION_FAILED);
        BBPunfix(c->batCacheid);
 
-       if ((u_val = BATdescriptor(*uval)) == NULL) {
-               BBPunfix(u_id->batCacheid);
-               if (i) BBPunfix(i->batCacheid);
+       if ((u_val = BATdescriptor(*uval)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       }
+       u_id = BATdescriptor(*uid);
        u = BATleftfetchjoin(BATmirror(u_id), u_val, BATcount(u_val));
        BBPunfix(u_id->batCacheid);
        BBPunfix(u_val->batCacheid);
@@ -3515,9 +3502,11 @@ DELTAbat(bat *result, bat *col, bat *uid
                res = BATreplace(res, u, TRUE);
        BBPunfix(u->batCacheid);
 
-       if (i && BATcount(i)) 
+       if (i && BATcount(i)) {
+               i = BATdescriptor(*ins);
                res = BATappend(res, i, TRUE);
-       if (i) BBPunfix(i->batCacheid);
+               BBPunfix(i->batCacheid);
+       }
 
        BBPkeepref(*result = res->batCacheid);
        return MAL_SUCCEED;
@@ -3528,37 +3517,30 @@ DELTAsub(bat *result, bat *col, bat *uid
 {
        BAT *c, *cminu, *u_id, *u_val, *u, *i = NULL, *res;
 
-       if ((u_id = BATdescriptor(*uid)) == NULL) 
+       if ((u_id = BBPquickdesc(ABS(*uid), 0)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       if (ins && (i = BATdescriptor(*ins)) == NULL) {
-               BBPunfix(u_id->batCacheid);
+       if (ins && (i = BBPquickdesc(ABS(*ins), 0)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       }
 
        /* no updates, no inserts */
        if (BATcount(u_id) == 0 && (!i || BATcount(i) == 0)) {
-               BBPunfix(u_id->batCacheid);
-               if (i) BBPunfix(i->batCacheid);
                BBPincref(*result = *col, TRUE);
                return MAL_SUCCEED;
        }
 
-       if ((c = BATdescriptor(*col)) == NULL) {
-               BBPunfix(u_id->batCacheid);
-               if (i) BBPunfix(i->batCacheid);
+       if ((c = BBPquickdesc(ABS(*col), 0)) == NULL) 
                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
-       }
 
        /* bat may change */
        if (i && BATcount(c) == 0 && BATcount(u_id) == 0) {
-               BBPunfix(c->batCacheid);
-               BBPunfix(u_id->batCacheid);
-               BBPkeepref(*result = i->batCacheid);
+               BBPincref(*result = *ins, TRUE);
                return MAL_SUCCEED;
        }
 
+       c = BATdescriptor(*col);
        res = c;
        if (BATcount(u_id)) {
+               u_id = BATdescriptor(*uid);
                cminu = BATkdiff(BATmirror(c), BATmirror(u_id));
                BBPunfix(c->batCacheid);
                c = BATmirror(BATmark(cminu, 0));
@@ -3566,7 +3548,6 @@ DELTAsub(bat *result, bat *col, bat *uid
 
                if ((u_val = BATdescriptor(*uval)) == NULL) {
                        BBPunfix(c->batCacheid);
-                       if (i) BBPunfix(i->batCacheid);
                        BBPunfix(u_id->batCacheid);
                        throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
                }
@@ -3577,9 +3558,11 @@ DELTAsub(bat *result, bat *col, bat *uid
                BBPunfix(u->batCacheid);
        }
 
-       if (i) res = BATappend(res, i, TRUE);
-       if (i) BBPunfix(i->batCacheid);
-
+       if (i) {
+               i = BATdescriptor(*ins);
+               res = BATappend(res, i, TRUE);
+               BBPunfix(i->batCacheid);
+       }
        BBPkeepref(*result = res->batCacheid);
        return MAL_SUCCEED;
 }
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1124,6 +1124,7 @@ SQLreader(Client c)
 {
        int go = TRUE;
        int more = TRUE;
+       int commit_done = FALSE;
        backend *be = (backend *) c->sqlcontext;
        bstream *in = c->fdin;
        int language = -1;
@@ -1174,8 +1175,10 @@ SQLreader(Client c)
                    B \n C; -- statements in one block  S
                 */
                /* auto_commit on end of statement */
-               if (m->scanner.mode == LINE_N)
+               if (m->scanner.mode == LINE_N && !commit_done) {
                        go = SQLautocommit(c, m);
+                       commit_done=TRUE;
+               }
 
                if (go && in->pos >= in->len) {
                        ssize_t rd;
@@ -1195,8 +1198,10 @@ SQLreader(Client c)
 
                                /* The rules of auto_commit require us to finish
                                   and start a transaction on the start of a 
new statement (s A;B; case) */
-                               if (!(m->emod & mod_debug))
+                               if (!(m->emod & mod_debug) && !commit_done) {
                                        go = SQLautocommit(c, m);
+                                       commit_done = TRUE;
+                               }
 
                                if (go && ((!blocked && mnstr_write(c->fdout, 
c->prompt, c->promptlength, 1) != 1) || mnstr_flush(c->fdout))) {
                                        go = FALSE;
diff --git a/sql/common/sql_string.c b/sql/common/sql_string.c
--- a/sql/common/sql_string.c
+++ b/sql/common/sql_string.c
@@ -113,7 +113,12 @@ sql2str(char *s)
 
        if (strcmp(str_nil, s) == 0)
                return s;
+       for (cur = s; *cur && !escaped; cur++)
+               escaped = (*cur == '\\'); 
 
+       if (!escaped)
+               return s;
+       escaped = 0;
        for (cur = s; *cur; cur++) {
                if (escaped) {
                        if (*cur == 'n') {
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
@@ -198,6 +198,7 @@ delta_update_bat( sql_delta *bat, BAT *t
                b = temp_descriptor(bat->ibid);
                void_replace_bat(b, upd, TRUE);
        }
+       bat->ucnt = BATcount(b);
        bat_destroy(b);
        bat_destroy(upd);
 }
@@ -236,8 +237,10 @@ delta_update_val( sql_delta *bat, oid ri
                b = temp_descriptor(bat->ibid);
                void_inplace(b, rid, upd, TRUE);
        }
-       if (b)
+       if (b) {
+               bat->ucnt = BATcount(b);
                bat_destroy(b);
+       }
 }
 
 static void
@@ -276,17 +279,6 @@ delta_append_bat( sql_delta *bat, BAT *i
                bat->cached = NULL;
        }
        bat->cnt += BATcount(i);
-       /* We simply use the to be inserted bat directly.
-        * Disabled this optimization: sometimes the bat is used later in the
-        * mal plan. 
-        * This should be solved by changing the input into a view (somehow).
-        * Alternatively, COPY INTO ... LOCKED can/should be used.
-       if (BATcount(b) == 0 && !isVIEW(i) && BBP_lrefs(i->batCacheid) <= 1 && 
i->htype == TYPE_void && i->ttype != TYPE_void && bat->ibase == i->H->seq){
-               temp_destroy(bat->ibid);
-               bat->ibid = temp_create(i);
-               BATseqbase(i, bat->ibase);
-       } else 
-        */
        if (!isEbat(b)){
                /* try to use mmap() */
                if (BATcount(b)+BATcount(i) > (BUN) REMAP_PAGE_MAXSIZE) { 
@@ -560,6 +552,7 @@ new_persistent_delta( sql_delta *bat, in
 
                bat->ibase = BATcount(b);
                bat->cnt = BATcount(b) + BATcount(i);
+               bat->ucnt = 0;
                bat->ibid = temp_copy(i->batCacheid, FALSE);
                bat_destroy(i);
                i = temp_descriptor(bat->ibid);
@@ -572,6 +565,7 @@ new_persistent_delta( sql_delta *bat, in
 
                bat->bid = bat->ibid;
                bat->cnt = bat->ibase = BATcount(b);
+               bat->ucnt = 0;
                bat_destroy(b);
 
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to