Changeset: a631529b6834 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a631529b6834
Modified Files:
        clients/mapiclient/dump.c
        gdk/gdk_imprints.c
        gdk/gdk_private.h
        sql/storage/bat/bat_storage.c
        tools/merovingian/client/monetdb.c
        tools/merovingian/daemon/controlrunner.c
        tools/merovingian/daemon/handlers.c
Branch: default
Log Message:

Merge with Oct2014 branch.


diffs (truncated from 404 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -345,16 +345,16 @@ dump_foreign_keys(Mapi mid, const char *
                free(pkeys);
                if (c_faction) {
                        int action = atoi(c_faction);
-                       int on_update = (action >> 8) & 255;
-                       int on_delete = action & 255;
+                       int on_update;
+                       int on_delete;
 
-                       if (0 < on_delete &&
-                           on_delete < NR_ACTIONS &&
+                       if (action > 0 &&
+                           (on_delete = action & 255) < NR_ACTIONS &&
                            on_delete != 2         /* RESTRICT -- default */)
                                mnstr_printf(toConsole, " ON DELETE %s",
                                             actions[on_delete]);
-                       if (0 < on_update &&
-                           on_update < NR_ACTIONS &&
+                       if (action > 0 &&
+                           (on_update = (action >> 8) & 255) < NR_ACTIONS &&
                            on_update != 2         /* RESTRICT -- default */)
                                mnstr_printf(toConsole, " ON UPDATE %s",
                                             actions[on_update]);
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -412,6 +412,7 @@ do {                                                        
                \
        uint##B##_t *im = (uint##B##_t *) imps;                         \
        TYPE *col = (TYPE *) Tloc(b, b->batFirst);                      \
        TYPE *bins = (TYPE *) inbins;                                   \
+       TYPE nil = TYPE##_nil;                                                  
\
        prvmask = mask = 0;                                             \
        new = (IMPS_PAGE/sizeof(TYPE))-1;                               \
        for (i = 0; i < b->batCount; i++) {                             \
@@ -452,6 +453,23 @@ do {                                                       
                \
                }                                                       \
                GETBIN##B(bin,col[i]);                                  \
                mask = IMPSsetBit(B,mask,bin);                          \
+               if (!cnt_bins[bin]++) {                                         
\
+                       min_bins[bin] = max_bins[bin] = i;              \
+               } else {                                                        
                \
+                       /* nil value can not be min */                  \
+                       if ((bin == 0) && (col[i] != nil)) {                    
                \
+                               /* in case the first value was nil and 
min_bin[0]       \
+                                * has been initialized with it */              
                        \
+                               if (col[min_bins[0]] == nil) {                  
                        \
+                                       min_bins[0] = i;                        
                                        \
+                               } else if (col[i] < col[min_bins[0]]) {         
                \
+                                       min_bins[0] = i;                        
                                        \
+                               }                                               
                                                        \
+                       } else  {                                               
                                                \
+                               if (col[i] < col[min_bins[bin]]) min_bins[bin] 
= i;     \
+                       }                                                       
                                                        \
+                       if (col[i] > col[max_bins[bin]]) max_bins[bin] = i;     
        \
+               }                                                               
                                                \
        }                                                               \
        /* one last left */                                             \
        if (prvmask == mask && dcnt > 0 &&                              \
@@ -482,13 +500,18 @@ do {                                                      
                \
 } while (0)
 
 static int
-imprints_create(BAT *b, void *inbins, bte bits,
+imprints_create(BAT *b, void *inbins, void *stats, bte bits,
                void *imps, BUN *impcnt, cchdc_t *dict, BUN *dictcnt)
 {
        BUN i;
        BUN dcnt, icnt, new;
+       oid *min_bins = (oid *) stats;
+       oid *max_bins = min_bins + 64;
+       BUN *cnt_bins = (BUN *)(max_bins + 64);
        bte bin = 0;
        dcnt = icnt = 0;
+       for (i = 0; i < 64; i++)
+               cnt_bins[i] = 0;
 
        switch (ATOMstorage(b->T->type)) {
        case TYPE_bte:
@@ -623,7 +646,8 @@ BATimprints(BAT *b)
                }
                sprintf(imprints->imprints->filename, "%s.%cimprints", nme,
                        b->batCacheid > 0 ? 't' : 'h');
-               pages = (((size_t) BATcount(b) * b->T->width) + IMPS_PAGE - 1) 
/ IMPS_PAGE;
+               pages = (((size_t) BATcount(b) * b->T->width) + IMPS_PAGE - 1)
+                                                                             / 
IMPS_PAGE;
                imprints->imprints->farmid = BBPselectfarm(PERSISTENT, b->ttype,
                                                           imprintsheap);
                if ((fd = GDKfdlocate(imprints->imprints->farmid, nme, "rb",
@@ -632,9 +656,14 @@ BATimprints(BAT *b)
                        struct stat st;
                        if (read(fd, hdata, sizeof(hdata)) == sizeof(hdata) &&
                            hdata[0] & ((size_t) 1 << 16) &&
+                           ((hdata[0] & 0xFF00) >> 8) == 1 && /* version 1 */
                            hdata[3] == (size_t) BATcount(b) &&
                            fstat(fd, &st) == 0 &&
-                           st.st_size >= (off_t) (imprints->imprints->size = 
imprints->imprints->free = 64 * b->T->width +
+                           st.st_size >= (off_t) (imprints->imprints->size =
+                                                  imprints->imprints->free =
+                                                  64 * b->T->width +
+                                                  64 * 2 * SIZEOF_OID +
+                                                  64 * SIZEOF_BUN +
                                                   pages * ((bte) hdata[0] / 8) 
+
                                                   hdata[2] * sizeof(cchdc_t) +
                                                   sizeof(uint64_t) /* padding 
for alignment */
@@ -645,7 +674,9 @@ BATimprints(BAT *b)
                                imprints->impcnt = (BUN) hdata[1];
                                imprints->dictcnt = (BUN) hdata[2];
                                imprints->bins = imprints->imprints->base + 4 * 
SIZEOF_SIZE_T;
-                               imprints->imps = (char *) imprints->bins + 64 * 
b->T->width;
+                               imprints->stats = (char *) imprints->bins + 64 
* b->T->width;
+                               imprints->imps = (char *) imprints->stats + 64 
* 2 * SIZEOF_OID
+                                                                             + 
64 * SIZEOF_BUN;
                                imprints->dict = (void *) ((uintptr_t) ((char 
*) imprints->imps + pages * (imprints->bits / 8) + sizeof(uint64_t)) & 
~(sizeof(uint64_t) - 1));
                                b->T->imprints = imprints;
                                close(fd);
@@ -701,15 +732,19 @@ BATimprints(BAT *b)
                if (cnt < 8)
                        imprints->bits = 8;
 
-               /* The heap we create here consists of three parts:
+               /* The heap we create here consists of four parts:
                 * bins, max 64 entries with bin boundaries, domain of b;
+                * stats, min/max/count for each bin, min/max are oid, and 
count BUN;
                 * imps, max one entry per "page", entry is "bits" wide;
                 * dict, max two entries per three "pages".
                 * In addition, we add some housekeeping entries at
                 * the start so that we can determine whether we can
-                * trust the imprints when encountered on startup. */
+                * trust the imprints when encountered on startup (including
+                * a version number -- CURRENT VERSION is 1 ). */
                if (HEAPalloc(imprints->imprints,
                              64 * b->T->width +
+                             64 * 2 * SIZEOF_OID +
+                             64 * SIZEOF_BUN +
                              pages * (imprints->bits / 8) +
                              pages * sizeof(cchdc_t) +
                              sizeof(uint64_t) /* padding for alignment */
@@ -723,7 +758,9 @@ BATimprints(BAT *b)
                        return NULL;
                }
                imprints->bins = imprints->imprints->base + 4 * SIZEOF_SIZE_T;
-               imprints->imps = (char *) imprints->bins + 64 * b->T->width;
+               imprints->stats = (char *) imprints->bins + 64 * b->T->width;
+               imprints->imps = (char *) imprints->stats + 64 * 2 * SIZEOF_OID 
+
+                                                               64 * SIZEOF_BUN;
                imprints->dict = (void *) ((uintptr_t) ((char *) imprints->imps 
+ pages * (imprints->bits / 8) + sizeof(uint64_t)) & ~(sizeof(uint64_t) - 1));
 
                switch (ATOMstorage(b->T->type)) {
@@ -759,6 +796,7 @@ BATimprints(BAT *b)
 
                if (!imprints_create(b,
                                     imprints->bins,
+                                    imprints->stats,
                                     imprints->bits,
                                     imprints->imps,
                                     &imprints->impcnt,
@@ -776,13 +814,16 @@ BATimprints(BAT *b)
                assert(imprints->dictcnt <= pages);
                imprints->imprints->free = (size_t) ((char *) ((cchdc_t *) 
imprints->dict + imprints->dictcnt) - imprints->imprints->base);
                /* add info to heap for when they become persistent */
-               ((size_t *) imprints->imprints->base)[0] = (size_t) 
imprints->bits;
+               ((size_t *) imprints->imprints->base)[0] = (size_t) 
(imprints->bits);
                ((size_t *) imprints->imprints->base)[1] = (size_t) 
imprints->impcnt;
                ((size_t *) imprints->imprints->base)[2] = (size_t) 
imprints->dictcnt;
                ((size_t *) imprints->imprints->base)[3] = (size_t) BATcount(b);
                if (HEAPsave(imprints->imprints, nme, b->batCacheid > 0 ? 
"timprints" : "himprints") == 0 &&
                    (fd = GDKfdlocate(imprints->imprints->farmid, nme, "rb+",
                                      b->batCacheid > 0 ? "timprints" : 
"himprints")) >= 0) {
+                       /* add version number */
+                       ((size_t *) imprints->imprints->base)[0] |= (size_t) 1 
<< 8;
+                       /* sync-on-disk checked bit */
                        ((size_t *) imprints->imprints->base)[0] |= (size_t) 1 
<< 16;
                        if (write(fd, imprints->imprints->base, sizeof(size_t)) 
< 0)
                                perror("write imprints");
@@ -945,16 +986,37 @@ IMPSprint(BAT *b)
        cchdc_t *d;
        char s[65];             /* max number of bits + 1 */
        BUN icnt, dcnt, l, pages;
+       oid *min_bins, *max_bins;
+       BUN *cnt_bins;
        bte j;
+       int i;
 
        if (!BATimprints(b))
                return;
        imprints = b->T->imprints;
        d = (cchdc_t *) imprints->dict;
+       min_bins = (oid *) imprints->stats;
+       max_bins = min_bins + 64;
+       cnt_bins = (BUN *)(max_bins + 64);
 
        fprintf(stderr,
                "bits = %d, impcnt = " BUNFMT ", dictcnt = " BUNFMT "\n",
                imprints->bits, imprints->impcnt, imprints->dictcnt);
+       fprintf(stderr,"MIN = ");
+       for (i = 0; i < imprints->bits; i++) {
+               fprintf(stderr, "[ " OIDFMT " ] ", min_bins[i]);
+       }
+       fprintf(stderr,"\n");
+       fprintf(stderr,"MAX = ");
+       for (i = 0; i < imprints->bits; i++) {
+               fprintf(stderr, "[ " OIDFMT " ] ", max_bins[i]);
+       }
+       fprintf(stderr,"\n");
+       fprintf(stderr,"COUNT = ");
+       for (i = 0; i < imprints->bits; i++) {
+               fprintf(stderr, "[ " BUNFMT " ] ", cnt_bins[i]);
+       }
+       fprintf(stderr,"\n");
        for (dcnt = 0, icnt = 0, pages = 1; dcnt < imprints->dictcnt; dcnt++) {
                if (d[dcnt].repeat) {
                        BINSIZE(imprints->bits, IMPSPRNTMASK, " ");
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -214,11 +214,12 @@ struct PROPrec {
 struct Imprints {
        bte bits;               /* how many bits in imprints */
        Heap *imprints;
-       void *bins;             /* pointer into imprints heap */
-       void *imps;             /* pointer into imprints heap */
-       void *dict;             /* pointer into imprints heap */
-       BUN impcnt;             /* counter for imprints*/
-       BUN dictcnt;            /* counter for cache dictionary */
+       void *bins;             /* pointer into imprints heap (bins borders)  */
+       void *stats;    /* pointer into imprints heap (stats per bin) */
+       void *imps;             /* pointer into imprints heap (bit vectors)   */
+       void *dict;             /* pointer into imprints heap (dictionary)    */
+       BUN impcnt;             /* counter for imprints                       */
+       BUN dictcnt;    /* counter for cache dictionary               */
 };
 
 typedef struct {
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
@@ -1250,8 +1250,11 @@ log_destroy_idx(sql_trans *tr, sql_idx *
 static int
 destroy_dbat(sql_trans *tr, sql_dbat *bat)
 {
-       sql_dbat *n = bat->next;
-
+       sql_dbat *n;
+       
+       if (!bat)
+               return LOG_OK;
+       n = bat->next;
        if (bat->dname)
                _DELETE(bat->dname);
        if (bat->dbid)
@@ -1760,19 +1763,18 @@ update_table(sql_trans *tr, sql_table *f
 
        if (ft->base.allocated) {
                if (store_nr_active > 1) { /* move delta */
-                       sql_dbat *b = ft->data, *p = NULL;
+                       sql_dbat *b = ft->data;
 
                        ft->data = NULL;
                        b->next = tt->data;
                        tt->data = b;
 
-                       while (b && b->wtime >= oldest->stime) {
-                               p = b;
+                       while (b && b->wtime >= oldest->stime)
                                b = b->next;
-                       }
-                       if (b && b->wtime < oldest->stime && p) {
-                               p->next = NULL;
-                               destroy_dbat(tr, b);
+                       if (b && b->wtime < oldest->stime) {
+                               /* anything older can go */
+                               destroy_dbat(tr, b->next);
+                               b->next = NULL;
                        }
                } else {
                        assert(tt->base.allocated);
@@ -1786,18 +1788,17 @@ update_table(sql_trans *tr, sql_table *f
                if (cc->base.wtime && cc->base.allocated) {
                        assert(oc->base.wtime < cc->base.wtime);
                        if (store_nr_active > 1) { /* move delta */
-                               sql_delta *b = cc->data, *p = NULL;
+                               sql_delta *b = cc->data;
 
                                cc->data = NULL;
                                b->next = oc->data;
                                oc->data = b;
-                               while (b && b->wtime >= oldest->stime) {
-                                       p = b;
+                               while (b && b->wtime >= oldest->stime) 
                                        b = b->next;
-                               }
-                               if (b && b->wtime < oldest->stime && p) {
-                                       p->next = NULL;
-                                       destroy_bat(tr, b);
+                               if (b && b->wtime < oldest->stime) {
+                                       /* anything older can go */
+                                       destroy_bat(tr, b->next);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to