Update of /cvsroot/monetdb/sql/src/storage/bat
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12198

Modified Files:
        Makefile.ag bat_table.mx res_table.mx 
Added Files:
        bat_logger.mx bat_storage.mx 
Removed Files:
        bat_bm.mx bat_connections.mx bat_dependency.mx bat_sequence.mx 
        bat_store.mx sql_catalog.mx 
Log Message:
The sql storage setup is changed.

Most code is moved one directory up as its independed of bats now.

bat remaining part has 4 components

bat_logger.mx logging 
bat_storage:  storage (for idxs, columns and tables)
bat_table:    relational operators, needed for obtaining and changing
              the catalog information
res_table.mx: result set interface




--- bat_store.mx DELETED ---

--- NEW FILE: bat_logger.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.

@f bat_logger
@h
#ifndef BAT_LOGGER_H
#define BAT_LOGGER_H

#include "sql_storage.h"
#include <gdk_logger.h>

extern logger *sql_logger;

extern int bat_logger_init( logger_functions *lf );

#endif /*BAT_LOGGER_H */
@c
#include "sql_config.h"
#include "bat_logger.h"

logger *sql_logger = NULL;

static int 
bl_create(char *logdir, char *dbname, int catalog_version)
{
        if (sql_logger)
                return LOG_ERR;
        sql_logger = logger_create(0, "sql", logdir, dbname, catalog_version);
        if (sql_logger)
                return LOG_OK;
        return LOG_ERR;
}

static void 
bl_destroy(void)
{
        logger *l = sql_logger;

        sql_logger = NULL;
        if (l) {
                logger_exit(l);
                logger_destroy(l);
        }
}

static int 
bl_restart(void)
{
        if (sql_logger)
                return logger_restart(sql_logger);
        return LOG_OK;
}

static int
bl_cleanup(void)
{
        if (sql_logger)
                return logger_cleanup(sql_logger);
        return LOG_OK;
}

static int
bl_changes(void)
{       
        return logger_changes(sql_logger);
}

static int 
bl_get_sequence(int seq, lng *id)
{
        return logger_sequence(sql_logger, seq, id);
}

static int
bl_log_isnew(void)
{
        if (BATcount(sql_logger->catalog) > 10) {
                return 0;
        }
        return 1;
}

static int 
bl_tstart(void)
{
        return log_tstart(sql_logger);
}

static int 
bl_tend(void)
{
        return log_tend(sql_logger);
}

static int 
bl_sequence(int seq, lng id)
{
        return log_sequence(sql_logger, seq, id);
}

int 
bat_logger_init( logger_functions *lf )
{
        lf->create = bl_create;
        lf->destroy = bl_destroy;
        lf->restart = bl_restart;
        lf->cleanup = bl_cleanup;
        lf->changes = bl_changes;
        lf->get_sequence = bl_get_sequence;
        lf->log_isnew = bl_log_isnew;
        lf->log_tstart = bl_tstart;
        lf->log_tend = bl_tend;
        lf->log_sequence = bl_sequence;
        return LOG_OK;
}

--- bat_sequence.mx DELETED ---

Index: res_table.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/storage/bat/res_table.mx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- res_table.mx        3 Jan 2007 12:39:50 -0000       1.14
+++ res_table.mx        5 Sep 2007 08:30:46 -0000       1.15
@@ -22,8 +22,8 @@
 
 #include "sql_catalog.h"
 
-extern res_table *res_table_create(sql_trans *tr, int res_id, int nr_cols, int 
querytype, res_table *next);
-extern res_col *res_col_create(sql_trans *tr, res_table *t, char *tn, char 
*name, char *typename, int digits, int scale);
+extern res_table *res_table_create(sql_trans *tr, int res_id, int nr_cols, int 
querytype, res_table *next, void *order);
+extern res_col *res_col_create(sql_trans *tr, res_table *t, char *tn, char 
*name, char *typename, int digits, int scale, int mtype, void *v);
 
 extern void res_table_destroy(res_table *t);
 
@@ -37,11 +37,24 @@
 #include "sql_config.h"
 #include "res_table.h"
 #include "sql_types.h"
-#include "bat_bm.h"
+
+static void
+bat_incref(bat bid)
+{
+       BBPincref(bid, TRUE);
+}
+
+static void
+bat_decref(bat bid)
+{
+       BBPdecref(bid, TRUE);
+}
+
 
 res_table *
-res_table_create(sql_trans *tr, int res_id, int nr_cols, int type, res_table 
*next)
+res_table_create(sql_trans *tr, int res_id, int nr_cols, int type, res_table 
*next, void *O)
 {
+       BAT *order = (BAT*)O;
        res_table *t = NEW(res_table);
 
        (void) tr;
@@ -53,12 +66,16 @@
        t->cols = NEW_ARRAY(res_col, nr_cols);
 
        t->order = 0;
+       if (order) {
+               t->order = order->batCacheid;
+               bat_incref(t->order);
+       } 
        t->next = next;
        return t;
 }
 
 res_col *
-res_col_create(sql_trans *tr, res_table *t, char *tn, char *name, char 
*typename, int digits, int scale)
+res_col_create(sql_trans *tr, res_table *t, char *tn, char *name, char 
*typename, int digits, int scale, int mtype, void *val)
 {
        res_col *c = t->cols + t->cur_col;
        
@@ -68,7 +85,15 @@
        c->name = _strdup(name);
        c->b = 0;
        c->p = NULL;
-       c->mtype = TYPE_bat;
+       c->mtype = mtype;
+       if (mtype == TYPE_bat) {
+               BAT *b = (BAT*)val;
+
+               c->b = b->batCacheid;
+               bat_incref(c->b);
+       } else {
+               c->p = ATOMdup(mtype, val);
+       }
        t->cur_col++;
        return c;
 }
@@ -77,7 +102,7 @@
 res_col_destroy(res_col *c)
 {
        if (c->b) {
-               bat_decref(c->b, TRUE);
+               bat_decref(c->b);
        } else {
                _DELETE(c->p);
        }
@@ -97,7 +122,7 @@
                res_col_destroy(c);
        }
        if (t->order)
-               bat_decref(t->order, TRUE);
+               bat_decref(t->order);
        _DELETE(t->cols);
        _DELETE(t);
 }

--- bat_dependency.mx DELETED ---

Index: Makefile.ag
===================================================================
RCS file: /cvsroot/monetdb/sql/src/storage/bat/Makefile.ag,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Makefile.ag 17 Jan 2007 13:30:50 -0000      1.16
+++ Makefile.ag 5 Sep 2007 08:30:36 -0000       1.17
@@ -22,8 +22,5 @@
        NOINST
        DIR = libdir
        SOURCES = \
-               bat_dependency.mx bat_connections.mx bat_store.mx bat_table.mx 
bat_bm.mx \
-               bat_sequence.mx \
-               sql_catalog.mx \
-               res_table.mx
+               bat_table.mx bat_storage.mx bat_logger.mx res_table.mx
 }

Index: bat_table.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/storage/bat/bat_table.mx,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- bat_table.mx        3 Jan 2007 12:39:50 -0000       1.27
+++ bat_table.mx        5 Sep 2007 08:30:45 -0000       1.28
@@ -36,16 +36,27 @@
 pushing the union, minus and update operations through the relational
 operators.  
 
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+#ifndef BAT_TABLE_H
+#define BAT_TABLE_H
 
-#include "sql_config.h"
 #include "sql_storage.h"
-#include "bat_bm.h"
-#include "bat_store.h"
+
+/* initialize bat storage call back functions interface */
+extern int bat_table_init( table_functions *tf );
+
+#endif /*BAT_TABLE_H*/
[EMAIL PROTECTED]
+#include "sql_config.h"
+#include "bat_table.h"
+#include "bat_storage.h"
+
+/* TODO use store functions */
 
 static BAT *
 full_column(sql_column *c, BAT *d, BAT *s )
 {
+       sql_bat *bat = c->data;
        /* return full normalized column bat
 
                if (s) {
@@ -58,7 +69,7 @@
                b := b.kunion(u);
                b := b.kdiff(reverse(d));
        */
-       BAT *r, *b, *u, *i = temp_descriptor(c->bat.ibid);
+       BAT *r, *b, *u, *i = temp_descriptor(bat->ibid);
        r = i; 
        if (isTemp(c)) {
                if (s) {
@@ -67,8 +78,8 @@
                }
                return r;
        }
-       b = temp_descriptor(c->bat.bid);
-       u = temp_descriptor(c->bat.ubid);
+       b = temp_descriptor(bat->bid);
+       u = temp_descriptor(bat->ubid);
        if (s) {
                BAT *t;
 
@@ -88,114 +99,6 @@
        return r;
 }
 
-
-list*
-table_select_column_multi_values( sql_trans *tr, sql_column *val, sql_column 
*key1, void *key_value1, sql_column *key,list *values)
-{
-        BAT *b = NULL, *s = NULL, *valB = NULL, *d = NULL, *tmp = NULL;
-       ptr lid;
-       BUN p,q;
-       int i, sz, ccnt;
-       void * value = NULL, *aux = NULL;
-       node *value_node;
-       list* res = list_create((fdestroy) NULL);
-
-       if (val->t->dbid)
-               d = bind_dbat(tr, val->t, RDONLY);
-       if(key1){
-               b = full_column(key1, d, s);
-               if(s)
-                       bat_destroy(s);
-               s = BATselect(b, key_value1, key_value1);
-               bat_destroy(b);
-       }
-       b = full_column(key, d, s);
-       if (s)
-               bat_destroy(s);
-       tmp = bat_new(TYPE_void, b->ttype, key->t->sz, 
"tmp_table_select_column");
-       value_node = values->h;
-       for(i = 0; i < list_length(values); i++){
-               value = value_node->data;
-               BUNappend(tmp,value,FALSE);
-       }
-       s = BATjoin(b,BATmirror(tmp),BATcount(b)*BATcount(tmp));
-       
-       valB = full_column(val, d, s);
-       if (s)
-               bat_destroy(s);
-       if (d)
-               bat_destroy(d);
-       ccnt = BATcount(valB);
-       if (ccnt) {
-               BATloop(valB,p,q){
-                       lid = BUNhead(valB,p);
-                       aux = bun_find(valB,lid);
-                       sz = ATOMlen(valB->ttype,aux);
-                      value = GDKmalloc(sz);
-                       memcpy(value,aux,sz);
-                       res = list_append(res,value);
-               }
-       }
-       bat_destroy(b);
-       bat_destroy(tmp);
-        bat_destroy(valB);
-        return res;
-}
-
-list*
-table_select_column( sql_trans *tr, sql_column *val, sql_column *key, void 
*key_value, ...)
-{
-        BAT *b = NULL, *s = NULL, *valB = NULL, *d = NULL;
-       ptr lid;
-       BUN p,q;
-       list* res = list_create((fdestroy) NULL);
-       va_list va;
-       sql_column *nc;
-       void *nv,*value = NULL, *aux = NULL;
-       int sz, ccnt;
-
-       if (val->t->dbid)
-               d = bind_dbat(tr, val->t, RDONLY);
-       if(key){
-               b = full_column(key, d, s);
-               if(s)
-                       bat_destroy(s);
-               s = BATselect(b, key_value, key_value);
-               bat_destroy(b);
-       }
-       va_start(va, key_value);
-       while ((nc = va_arg(va, sql_column *)) != NULL) {
-               nv = va_arg(va, void *);
-               key_value = nv;
-               key = nc;
-               
-               b = full_column(key, d, s);
-               if (s)
-                       bat_destroy(s);
-               s = BATselect(b, key_value, key_value);
-               bat_destroy(b);
-       }
-       valB = full_column(val, d, s);
-       if (s)
-               bat_destroy(s);
-       if (d)
-               bat_destroy(d);
-       ccnt = BATcount(valB);
-       
-       if (ccnt) {
-               BATloop(valB,p,q){
-                       lid = BUNhead(valB,p);
-                       aux = bun_find(valB,lid);
-                       sz = ATOMlen(valB->ttype,aux);
-                       value = GDKmalloc(sz);
-                       memcpy(value,aux,sz);
-                       res = list_append(res,value);
-               }
-       }
-        bat_destroy(valB);
-        return res;
-}
-
 ssize_t
 column_find_row(sql_trans *tr, sql_column *c, void *value, ...)
 {
@@ -205,9 +108,10 @@
        ssize_t rid = -1;
        sql_column *nc;
        void *nv;
+       sql_dbat *bat = c->t->data;
 
-       if (c->t->dbid) 
-               d = bind_dbat(tr, c->t, RDONLY);
+       if (bat->dbid) 
+               d = store_funcs.bind_del(tr, c->t, RDONLY);
        va_start(va, value);
        while ((nc = va_arg(va, sql_column *)) != NULL) {
                nv = va_arg(va, void *);
@@ -240,9 +144,10 @@
        BUN p;
        BAT *b, *d = NULL;
        void *res = NULL;
+       sql_dbat *bat = c->t->data;
 
-       if (c->t->dbid) 
-               d = bind_dbat(tr, c->t, RDONLY);
+       if (bat->dbid) 
+               d = store_funcs.bind_del(tr, c->t, RDONLY);
        b = full_column(c, d, NULL);
        if (d)
                bat_destroy(d);
@@ -266,12 +171,13 @@
 column_update_value(sql_trans *tr, sql_column *c, ssize_t rid, void *value)
 {
        BAT *b;
+       sql_bat *bat = c->data;
 
        assert(rid != (ssize_t)oid_nil);
        assert(rid != -1);
 
-       if (c->bat.ubid) {
-               b = temp_descriptor(c->bat.ubid);
+       if (bat->ubid) {
+               b = temp_descriptor(bat->ubid);
                if (BUNfnd(b, &rid)) {
                        BUNreplace(b, (ptr) &rid, value, TRUE);
                } else {
@@ -281,7 +187,7 @@
                }
                bat_destroy(b);
        } else {
-               b = temp_descriptor(c->bat.ibid);
+               b = temp_descriptor(bat->ibid);
                void_inplace(b, rid, value, TRUE);
                bat_destroy(b);
        }
@@ -295,7 +201,8 @@
        va_list va;
        node *n = cs_first_node(&t->columns);
        sql_column *c = n->data;
-       BAT *b = temp_descriptor(c->bat.ibid);
+       sql_bat *bat = c->data;
+       BAT *b = temp_descriptor(bat->ibid);
        void *val = NULL;
        int cnt = 0;
 
@@ -307,7 +214,8 @@
        {
                cnt++;
                c = n->data;
-               b = temp_descriptor(c->bat.ibid);
+               bat = c->data;
+               b = temp_descriptor(bat->ibid);
                BUNappend(b, val, TRUE);
                bat_destroy(b);
                c->base.wtime = tr->stime;
@@ -325,7 +233,7 @@
 int
 table_delete(sql_trans *tr, sql_table *t, ssize_t rid)
 {
-       BAT *b = bind_dbat(tr, t, INS);
+       BAT *b = store_funcs.bind_del(tr, t, INS);
 
        assert(rid != (ssize_t)oid_nil);
        assert(rid != -1);
@@ -337,7 +245,8 @@
 }
 
 
-int
+#if 0
+static int
 table_dump(sql_trans *tr, sql_table *t)
 {
        node *n = cs_first_node(&t->columns);
@@ -347,8 +256,9 @@
        (void)tr;
        for (i = 0; n; n = n->next, i++) {
                sql_column *c = n->data;
+               sql_bat *bat = c->data;
 
-               b[i] = temp_descriptor(c->bat.bid);
+               b[i] = temp_descriptor(bat->bid);
        }
        BATmultiprintf(GDKstdout, l +1, b, TRUE, 0, 1);
        for (i = 0; i < l; i++)
@@ -357,7 +267,7 @@
        return 0;
 }
 
-int
+static int
 table_check(sql_trans *tr, sql_table *t)
 {
        node *n = cs_first_node(&t->columns);
@@ -366,9 +276,9 @@
        (void)tr;
        for (; n; n = n->next) {
                sql_column *c = n->data;
-               BAT *b;
+               sql_bat *bat = c->data;
+               BAT *b = temp_descriptor(bat->bid);
 
-               b = temp_descriptor(c->bat.bid);
                if (cnt == -1) {
                        cnt = BATcount(b);
                } else if (cnt != (ssize_t)BATcount(b)) {
@@ -379,3 +289,138 @@
        }
        return 0;
 }
+#endif
+
+/* returns table rids, for the given select ranges */
+rids *
+rids_select( sql_trans *tr, sql_column *key, void *key_value_low, void 
*key_value_high, ...)
+{
+       va_list va;
+       BAT *b = NULL, *s = NULL, *d = NULL;
+       sql_column *nc;
+       void *nvl, *nvh;
+       rids *rs = NEW(rids);
+       sql_dbat *bat = key->t->data;
+
+       /* special case, key_value_low and high NULL, ie return all */
+       if (bat->dbid) 
+               d = store_funcs.bind_del(tr, key->t, RDONLY);
+       if (key_value_low || key_value_high) {
+               va_start(va, key_value_high);
+               while ((nc = va_arg(va, sql_column *)) != NULL) {
+                       nvl = va_arg(va, void *);
+                       nvh = va_arg(va, void *);
+       
+                       b = full_column(key, d, s);
+                       if (s)
+                               bat_destroy(s);
+                       if (!key_value_low)
+                               key_value_low = ATOMnilptr(b->ttype);
+                       if (!key_value_high)
+                               key_value_high = ATOMnilptr(b->ttype);
+                       s = BATselect(b, key_value_low, key_value_high);
+                       bat_destroy(b);
+                       key = nc;
+                       key_value_low = nvl;
+                       key_value_high = nvh;
+               }
+       }
+       b = full_column(key, d, s);
+       if (s)
+               bat_destroy(s);
+       if (d)
+               bat_destroy(d);
+       if (key_value_low || key_value_high) {
+               if (!key_value_low)
+                       key_value_low = ATOMnilptr(b->ttype);
+               if (!key_value_high)
+                       key_value_high = ATOMnilptr(b->ttype);
+               rs->data = BATselect(b, key_value_low, key_value_high);
+               bat_destroy(b);
+       } else {
+               rs->data = b;
+       }
+       rs->cur = 0;
+       return rs;
+}
+
+/* order rids by orderby_column values */
+rids *
+rids_orderby(sql_trans *tr, rids *r, sql_column *orderby_col)
+{
+       BAT *b, *d = NULL;
+       sql_dbat *bat = orderby_col->t->data;
+
+       if (bat->dbid) 
+               d = store_funcs.bind_del(tr, orderby_col->t, RDONLY);
+       b = full_column(orderby_col, d, r->data);
+       if (d)
+               bat_destroy(d);
+       bat_destroy(r->data);
+       b = BATmirror(b);
+       r->data = BATmirror(BATsort(b));
+       bat_destroy(b);
+       return r;
+}
+
+
+/* return table rids from result of rids_select, return (-1) when done */
+ssize_t 
+rids_next(rids *r)
+{
+       if (r->cur < BATcount(r->data)) {
+               BAT *b = r->data;
+               return *(oid*)BUNhead(b, BUNptr(b, r->cur++));
+       }
+       return -1;
+}
+
+rids *
+rids_join(sql_trans *tr, rids *l, sql_column *lc, rids *r, sql_column *rc)
+{
+       BAT *lcb, *rcb, *d = NULL;
+       sql_dbat *lbat, *rbat;
+       
+       lbat = lc->t->data;
+       if (lbat->dbid) 
+               d = store_funcs.bind_del(tr, lc->t, RDONLY);
+       lcb = full_column(lc, d, r->data);
+       if (d)
+               bat_destroy(d);
+       rbat = rc->t->data;
+       if (rbat->dbid) 
+               d = store_funcs.bind_del(tr, rc->t, RDONLY);
+       rcb = full_column(rc, d, r->data);
+       if (d)
+               bat_destroy(d);
+       bat_destroy(l->data);
+       l->data = BATjoin(lcb, BATmirror(rcb), BATcount(lcb));
+       bat_destroy(lcb);
+       bat_destroy(rcb);
+       return l;
+}
+
+/* clean up the resources taken by the result of rids_select */
+void 
+rids_destroy(rids *r)
+{
+       bat_destroy(r->data);
+       _DELETE(r);
+}
+
+int 
+bat_table_init( table_functions *tf )
+{
+       tf->column_find_row = column_find_row;
+       tf->column_find_value = column_find_value;
+       tf->column_update_value = column_update_value;
+       tf->table_insert = table_insert;
+       tf->table_delete = table_delete;
+       
+       tf->rids_select = rids_select;
+       tf->rids_orderby = rids_orderby;
+       tf->rids_join = rids_join;
+       tf->rids_next = rids_next;
+       tf->rids_destroy = rids_destroy;
+       return LOG_OK;
+}

--- NEW FILE: bat_storage.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.

@f bat_storage

@h
[...992 lines suppressed...]
        sf->create_col = (create_col_fptr)&create_col;
        sf->create_idx = (create_idx_fptr)&create_idx;
        sf->create_del = (create_del_fptr)&create_del;

        sf->dup_col = (dup_col_fptr)&dup_col;
        sf->dup_idx = (dup_idx_fptr)&dup_idx;
        sf->dup_del = (dup_del_fptr)&dup_del;

        sf->destroy_col = (destroy_col_fptr)&destroy_col;
        sf->destroy_idx = (destroy_idx_fptr)&destroy_idx;
        sf->destroy_del = (destroy_del_fptr)&destroy_del;

        sf->clear_col = (clear_col_fptr)&clear_col;
        sf->clear_idx = (clear_idx_fptr)&clear_idx;
        sf->clear_del = (clear_del_fptr)&clear_del;

        sf->update_table = (update_table_fptr)&update_table;
        return LOG_OK;
}


--- bat_bm.mx DELETED ---

--- bat_connections.mx DELETED ---

--- sql_catalog.mx DELETED ---


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to