Changeset: 79646e95efd0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=79646e95efd0
Modified Files:
        MonetDB/src/gdk/gdk.mx
        MonetDB/src/gdk/gdk_batop.mx
        sql/src/backends/monet5/sql_scenario.mx
        sql/src/include/sql_catalog.h
        sql/src/server/sql_mvc.mx
        sql/src/storage/bat/Makefile.ag
        sql/src/storage/bat/bat_storage.mx
        sql/src/storage/sql_storage.h
        sql/src/storage/store.mx
Branch: default
Log Message:

start collection min/max values with bats


diffs (truncated from 308 to 300 lines):

diff -r a773c7419829 -r 79646e95efd0 MonetDB/src/gdk/gdk.mx
--- a/MonetDB/src/gdk/gdk.mx    Fri May 21 20:20:17 2010 +0200
+++ b/MonetDB/src/gdk/gdk.mx    Fri May 21 20:21:01 2010 +0200
@@ -3361,8 +3361,12 @@
 
 #define GDK_AGGR_SIZE 1
 #define GDK_AGGR_CARD 2
+#define GDK_MIN_VALUE 3
+#define GDK_MAX_VALUE 4
 
 gdk_export void PROPdestroy(PROPrec *p);
+gdk_export PROPrec * BATgetprop(BAT *b, int idx);
+gdk_export void BATsetprop(BAT *b, int idx, int type, void *v);
 gdk_export bit BATgetprop_bit(BAT *b, int idx);
 gdk_export int BATgetprop_int(BAT *b, int idx);
 gdk_export wrd BATgetprop_wrd(BAT *b, int idx);
diff -r a773c7419829 -r 79646e95efd0 MonetDB/src/gdk/gdk_batop.mx
--- a/MonetDB/src/gdk/gdk_batop.mx      Fri May 21 20:20:17 2010 +0200
+++ b/MonetDB/src/gdk/gdk_batop.mx      Fri May 21 20:21:01 2010 +0200
@@ -2849,7 +2849,7 @@
        }
 }
 
-static PROPrec *
+PROPrec *
 BATgetprop(BAT *b, int idx)
 {
        PROPrec *p = b->T->props;
@@ -2894,7 +2894,7 @@
        return (p) ? p->v.val.pval : str_nil;
 }
 
-static void
+void
 BATsetprop(BAT *b, int idx, int type, void *v)
 {
        ValRecord vr;
diff -r a773c7419829 -r 79646e95efd0 sql/src/backends/monet5/sql_scenario.mx
--- a/sql/src/backends/monet5/sql_scenario.mx   Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/backends/monet5/sql_scenario.mx   Fri May 21 20:21:01 2010 +0200
@@ -233,7 +233,7 @@
        return MAL_SUCCEED;
 }
 
-MT_Id sqllogthread;
+MT_Id sqllogthread, minmaxthread;
 
 static str
 SQLinit(void)
@@ -280,6 +280,10 @@
                mal_unset_lock(sql_contextLock,"SQL init");
                throw(SQL, "SQLinit", "Starting log manager failed");
        }
+       if (!GDKembedded && MT_create_thread(&minmaxthread, (void (*)(void *)) 
mvc_minmaxmanager, NULL) < 0) {
+               mal_unset_lock(sql_contextLock,"SQL init");
+               throw(SQL, "SQLinit", "Starting minmax manager failed");
+       }
        return MAL_SUCCEED;
 }
 
diff -r a773c7419829 -r 79646e95efd0 sql/src/include/sql_catalog.h
--- a/sql/src/include/sql_catalog.h     Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/include/sql_catalog.h     Fri May 21 20:21:01 2010 +0200
@@ -338,34 +338,6 @@
        X_EQUI_HEIGHT
 } sql_histype;
 
-/* a single-column histogram */
-typedef struct sql_histo {
-               enum sql_histype        type;           /* type of histogram */
-       int     num_buckets;    /* number of buckets (> 0) */
-       void    **min_value;    /* smallest value in this column 
-                                   (min_valuei+1 = max_valuei, min_value0 = 
column->min_value) */
-       void    **max_value;    /* largest value in each bucket 
-                                   (max_valuei = min_valuei+1, max_valuei-1 < 
max_valuei) */
-       lng     *num_values;    /* number if distinct values in each bucket 
-                                  (0 < num_valuesi <= num_tuplesi) */
-       lng     *num_tuples;    /* total number of tuples in each bucket 
-                                   (0 < num_valuesi <= num_tuplesi)*/
-} sql_histo;
-
-/* derived histogram of an (intermediate) column */
-typedef struct sql_histo_instance {
-struct sql_histo   *histogram;    /* the underlying base histogram; must NOT 
be NULL */
-       void     *min_value;    /* new smallest value in this column */
-       void     *max_value;    /* new largest value in this column */
-       dbl       sel_values;   /* selectivity factor to be applied to 
num_values of all buckets
-                                  of the underlying base histogram (0 < 
sel_values <= 1) */
-       dbl       sel_tuples;   /* selectivity factor to be applied to 
num_tuples of all buckets
-                                  of the underlying base histogram (0 < 
sel_tuples) */
-                               /* Note: sel_values & sel_tuples represent the 
relative changes
-                                  since the base histogram, not since the 
previous
-                                  derived/intermediate histogram instance ! */
-} sql_histo_instance;
-
 typedef struct sql_column {
        sql_base base;
        sql_subtype type;
diff -r a773c7419829 -r 79646e95efd0 sql/src/server/sql_mvc.mx
--- a/sql/src/server/sql_mvc.mx Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/server/sql_mvc.mx Fri May 21 20:21:01 2010 +0200
@@ -140,6 +140,7 @@
 extern int mvc_init(char *dbname, int debug, store_type store, backend_stack 
stk);
 extern void mvc_exit(void);
 extern void mvc_logmanager(void);
+extern void mvc_minmaxmanager(void);
 
 extern mvc *mvc_create(int clientid, backend_stack stk, int debug, bstream 
*rs, stream *ws);
 extern void mvc_reset(mvc *m, bstream *rs, stream *ws, int debug, int 
globalvars);
@@ -355,6 +356,12 @@
        store_manager();
 }
 
+void
+mvc_minmaxmanager()
+{
+       minmax_manager();
+}
+
 int
 mvc_status(mvc *m)
 {
diff -r a773c7419829 -r 79646e95efd0 sql/src/storage/bat/Makefile.ag
--- a/sql/src/storage/bat/Makefile.ag   Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/storage/bat/Makefile.ag   Fri May 21 20:21:01 2010 +0200
@@ -17,7 +17,7 @@
 
 ## Process this file with automake to produce Makefile.in
 
-INCLUDES = .. ../../include ../../common $(MONETDB_INCS)
+INCLUDES = .. ../../include ../../common $(MONETDB_INCS) $(MONETDB5_INCS)
 
 lib_batstore = {
        NOINST
diff -r a773c7419829 -r 79646e95efd0 sql/src/storage/bat/bat_storage.mx
--- a/sql/src/storage/bat/bat_storage.mx        Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/storage/bat/bat_storage.mx        Fri May 21 20:21:01 2010 +0200
@@ -83,6 +83,7 @@
 #include "bat_storage.h"
 #include "bat_utils.h"
 #include <sql_string.h>
+#include <algebra.h>
 
 #define SNAPSHOT_MINSIZE ((BUN) 1024)
 
@@ -1211,7 +1212,7 @@
 
                if (!c->base.wtime) 
                        continue;
-               gtr_update_delta(tr, c->data);
+               ok = gtr_update_delta(tr, c->data);
        }
        if (ok == LOG_OK && t->idxs.set) {
                for (n = t->idxs.set->h; ok == LOG_OK && n; n = n->next) {
@@ -1221,33 +1222,92 @@
                        if (!ci->base.wtime)
                                continue;
 
-                       gtr_update_delta(tr, ci->data);
+                       ok = gtr_update_delta(tr, ci->data);
                }
        }
        return ok;
 }
 
+typedef int (*gtr_update_table_fptr)( sql_trans *tr, sql_table *t);
+
 static int
-gtr_update( sql_trans *tr )
+_gtr_update( sql_trans *tr, gtr_update_table_fptr gtr_update_table_f )
 {
+       int ok = LOG_OK;
        node *sn;
 
-       for(sn = tr->schemas.set->h; sn; sn = sn->next) {
+       for(sn = tr->schemas.set->h; sn && ok == LOG_OK; sn = sn->next) {
                sql_schema *s = sn->data;
                
                if (!isTempSchema(s) && s->tables.set) {
                        node *n;
-                       for (n = s->tables.set->h; n; n = n->next) {
+                       for (n = s->tables.set->h; n && ok == LOG_OK; n = 
n->next) {
                                sql_table *t = n->data;
 
                                if (isGlobalTable(t))
-                                       gtr_update_table(tr, t);
+                                       ok = gtr_update_table_f(tr, t);
                        }
                }
        }
        return LOG_OK;
 }
 
+static int
+gtr_update( sql_trans *tr )
+{
+       return _gtr_update(tr, &gtr_update_table);
+}
+
+int 
+gtr_minmax_col( sql_trans *tr, sql_column *c)
+{
+       int ok = LOG_OK;
+       sql_delta *cbat = c->data;
+       BAT *cur;
+       lng val;
+
+       (void)tr;
+       if (store_nr_active > 0)
+               return LOG_ERR;
+
+       /* allready set */
+       if (!cbat || c->type.type->localtype >= TYPE_str || c->t->system)
+               return ok;
+
+       cur = temp_descriptor(cbat->bid);
+       if (BATgetprop(cur, GDK_MIN_VALUE)) {
+               bat_destroy(cur);
+               return ok;
+       }
+
+       BATmin(cur, &val);
+       BATsetprop(cur, GDK_MIN_VALUE, cur->ttype, &val);
+       BATmax(cur, &val);
+       BATsetprop(cur, GDK_MAX_VALUE, cur->ttype, &val);
+       bat_destroy(cur);
+       return ok;
+}
+
+static int
+gtr_minmax_table(sql_trans *tr, sql_table *t)
+{
+       int ok = LOG_OK;
+       node *n;
+
+       for (n = t->columns.set->h; ok == LOG_OK && n; n = n->next) {
+               sql_column *c = n->data;
+
+               ok = gtr_minmax_col(tr, c);
+       }
+       return ok;
+}
+
+static int
+gtr_minmax( sql_trans *tr )
+{
+       return _gtr_update(tr, &gtr_minmax_table);
+}
+
 int 
 tr_update_delta( sql_trans *tr, sql_delta *obat, sql_delta *cbat, int cluster, 
BUN snapshot_minsize)
 {
@@ -1618,6 +1678,7 @@
        sf->log_table = (update_table_fptr)&log_table;
        sf->snapshot_table = (update_table_fptr)&snapshot_table;
        sf->gtrans_update = (gtrans_update_fptr)&gtr_update;
+       sf->gtrans_minmax = (gtrans_update_fptr)&gtr_minmax;
        return LOG_OK;
 }
 
diff -r a773c7419829 -r 79646e95efd0 sql/src/storage/sql_storage.h
--- a/sql/src/storage/sql_storage.h     Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/storage/sql_storage.h     Fri May 21 20:21:01 2010 +0200
@@ -229,6 +229,7 @@
        update_table_fptr log_table;
        update_table_fptr update_table;
        gtrans_update_fptr gtrans_update;
+       gtrans_update_fptr gtrans_minmax;
 
        col_ins_fptr col_ins;
        col_upd_fptr col_upd;
@@ -285,11 +286,10 @@
 
 extern int
  store_init(int debug, store_type store, char *logdir, char *dbname, 
backend_stack stk);
-extern void
- store_exit(void);
+extern void store_exit(void);
 
-extern void
- store_manager(void);
+extern void store_manager(void);
+extern void minmax_manager(void);
 
 extern void store_lock(void);
 extern void store_unlock(void);
diff -r a773c7419829 -r 79646e95efd0 sql/src/storage/store.mx
--- a/sql/src/storage/store.mx  Fri May 21 20:20:17 2010 +0200
+++ b/sql/src/storage/store.mx  Fri May 21 20:21:01 2010 +0200
@@ -1522,6 +1522,18 @@
        }
 }
 
+void
+minmax_manager(void)
+{
+       while (active) {
+               MT_sleep_ms(30000);
+               if (store_nr_active || !active) 
+                       continue;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to