Changeset: 9b27b8134269 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9b27b8134269
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/backends/monet5/sql.mal
        sql/common/sql_types.c
        sql/server/rel_distribute.c
        sql/server/rel_dump.c
        sql/server/rel_optimizer.c
        sql/server/sql_mvc.c
        sql/storage/bat/bat_storage.c
        sql/storage/restrict/restrict_storage.c
        sql/storage/sql_storage.h
Branch: default
Log Message:

added initial support for using the var heaps dictionary table from sql.
On the sql level the used var columns can be rewriten into dict's + joins.
With some group by push down this give more efficient execution.
Currently this is not enable, use --set sql_debug=8 to use this.


diffs (truncated from 902 to 300 lines):

diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1136,19 +1136,40 @@ static stmt *
 rel2bin_basetable( mvc *sql, sql_rel *rel)
 {
        sql_table *t = rel->l;
+       sql_column *c = rel->r;
        list *l = sa_list(sql->sa);
-       stmt *dels = stmt_dels( sql, t);
+       stmt *dels;
        node *en;
 
+       if (!t && c)
+               t = c->t;
+               dels = stmt_dels( sql, t);
+
+       /* add aliases */
        assert(rel->exps);
-       /* add aliases */
        for( en = rel->exps->h; en; en = en->next ) {
                sql_exp *exp = en->data;
                char *rname = exp->rname?exp->rname:exp->l;
                char *oname = exp->r;
                stmt *s = NULL;
 
-               if (oname[0] == '%' && strcmp(oname, TID) == 0) {
+               if (is_func(exp->type)) {
+                       list *exps = exp->l;
+                       sql_exp *cexp = exps->h->data;
+                       char *cname = cexp->r;
+                       list *l = sa_list(sql->sa);
+
+                       c = find_sql_column(t, cname);
+                       s = stmt_col(sql, c, dels);
+                       append(l, s);
+                       if (exps->h->next) {
+                               sql_exp *at = exps->h->next->data;
+                               stmt *u = exp_bin(sql, at, NULL, NULL, NULL, 
NULL, NULL, NULL);
+
+                               append(l, u);
+                       }
+                       s = stmt_Nop(sql->sa, stmt_list(sql->sa, l), exp->f);
+               } else if (oname[0] == '%' && strcmp(oname, TID) == 0) {
                        /* tid function  sql.tid(t) */
                        char *rnme = t->base.name;
 
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4508,3 +4508,191 @@ freeVariables(Client c, MalBlkPtr mb, Ma
        }
        mb->ptop = j;
 }
+
+/* if at least (2*SIZEOF_BUN), also store length (heaps are then
+ * incompatible) */
+#define EXTRALEN ((SIZEOF_BUN + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1))
+
+str
+STRindex_int(int *i, str src, bit *u)
+{
+       (void)src; (void)u;
+       *i = 0;
+       return MAL_SUCCEED;
+}
+
+str
+BATSTRindex_int(bat *res, bat *src, bit *u)
+{
+       BAT *s, *r;
+
+       if ((s = BATdescriptor(*src)) == NULL)
+               throw(SQL, "calc.index", "Cannot access descriptor");
+       
+       if (*u) {
+               Heap *h = s->T->vheap;
+               size_t pad, pos;
+               const size_t extralen = h->hashash ? EXTRALEN : 0;
+               int v;
+
+               r = BATnew(TYPE_void, TYPE_int, 1024);
+               BATseqbase(r, 0);
+               pos = GDK_STRHASHSIZE;
+               while (pos < h->free) {
+                       const char *s;
+
+                       pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+                       if (pad < sizeof(stridx_t))
+                               pad += GDK_VARALIGN;
+                       pos += pad + extralen;
+                       s = h->base + pos;
+                       v = pos-GDK_STRHASHSIZE;
+                       BUNappend(r, &v, FALSE);
+                       pos += GDK_STRLEN(s);
+               }
+       } else {
+               r = VIEWcreate(s, s);
+               r->ttype = TYPE_int;
+               r->tvarsized = 0;
+               r->T->vheap = NULL;
+       }
+       BBPunfix(s->batCacheid);
+       BBPkeepref((*res = r->batCacheid));
+       return MAL_SUCCEED;
+}
+
+str
+STRindex_sht(sht *i, str src, bit *u)
+{
+       (void)src; (void)u;
+       *i = 0;
+       return MAL_SUCCEED;
+}
+
+str
+BATSTRindex_sht(bat *res, bat *src, bit *u)
+{
+       BAT *s, *r;
+
+       if ((s = BATdescriptor(*src)) == NULL)
+               throw(SQL, "calc.index", "Cannot access descriptor");
+       
+       if (*u) {
+               Heap *h = s->T->vheap;
+               size_t pad, pos;
+               const size_t extralen = h->hashash ? EXTRALEN : 0;
+               sht v;
+
+               r = BATnew(TYPE_void, TYPE_sht, 1024);
+               BATseqbase(r, 0);
+               pos = GDK_STRHASHSIZE;
+               while (pos < h->free) {
+                       const char *s;
+
+                       pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+                       if (pad < sizeof(stridx_t))
+                               pad += GDK_VARALIGN;
+                       pos += pad + extralen;
+                       s = h->base + pos;
+                       v = pos-GDK_STRHASHSIZE;
+                       BUNappend(r, &v, FALSE);
+                       pos += GDK_STRLEN(s);
+               }
+       } else {
+               r = VIEWcreate(s, s);
+               r->ttype = TYPE_sht;
+               r->tvarsized = 0;
+               r->T->vheap = NULL;
+       }
+       BBPunfix(s->batCacheid);
+       BBPkeepref((*res = r->batCacheid));
+       return MAL_SUCCEED;
+}
+
+str
+STRindex_bte(bte *i, str src, bit *u)
+{
+       (void)src; (void)u;
+       *i = 0;
+       return MAL_SUCCEED;
+}
+
+str
+BATSTRindex_bte(bat *res, bat *src, bit *u)
+{
+       BAT *s, *r;
+
+       if ((s = BATdescriptor(*src)) == NULL)
+               throw(SQL, "calc.index", "Cannot access descriptor");
+       
+       if (*u) {
+               Heap *h = s->T->vheap;
+               size_t pad, pos;
+               const size_t extralen = h->hashash ? EXTRALEN : 0;
+               bte v;
+
+               r = BATnew(TYPE_void, TYPE_bte, 64);
+               BATseqbase(r, 0);
+               pos = GDK_STRHASHSIZE;
+               while (pos < h->free) {
+                       const char *s;
+
+                       pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+                       if (pad < sizeof(stridx_t))
+                               pad += GDK_VARALIGN;
+                       pos += pad + extralen;
+                       s = h->base + pos;
+                       v = pos-GDK_STRHASHSIZE;
+                       BUNappend(r, &v, FALSE);
+                       pos += GDK_STRLEN(s);
+               }
+       } else {
+               r = VIEWcreate(s, s);
+               r->ttype = TYPE_bte;
+               r->tvarsized = 0;
+               r->T->vheap = NULL;
+       }
+       BBPunfix(s->batCacheid);
+       BBPkeepref((*res = r->batCacheid));
+       return MAL_SUCCEED;
+}
+
+str
+STRstrings(str *i, str src)
+{
+       (void)src;
+       *i = 0;
+       return MAL_SUCCEED;
+}
+
+str
+BATSTRstrings(bat *res, bat *src)
+{
+       BAT *s, *r;
+       Heap *h;
+       size_t pad, pos;
+       size_t extralen;
+
+       if ((s = BATdescriptor(*src)) == NULL)
+               throw(SQL, "calc.strings", "Cannot access descriptor");
+       
+               h = s->T->vheap;
+               extralen = h->hashash ? EXTRALEN : 0;
+       r = BATnew(TYPE_void, TYPE_str, 1024);
+       BATseqbase(r, 0);
+       pos = GDK_STRHASHSIZE;
+       while (pos < h->free) {
+               const char *s;
+
+               pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+               if (pad < sizeof(stridx_t))
+                       pad += GDK_VARALIGN;
+               pos += pad + extralen;
+               s = h->base + pos;
+               BUNappend(r, s, FALSE);
+               pos += GDK_STRLEN(s);
+       }
+       BBPunfix(s->batCacheid);
+       BBPkeepref((*res = r->batCacheid));
+       return MAL_SUCCEED;
+}
diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h
--- a/sql/backends/monet5/sql.h
+++ b/sql/backends/monet5/sql.h
@@ -313,4 +313,13 @@ sql5_export str timestamp_2_daytime(dayt
 sql5_export str date_2_timestamp(timestamp *res, date *v, int *d);
 sql5_export str SQLcurrent_daytime(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 sql5_export str SQLcurrent_timestamp(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
+
+sql5_export str STRindex_int(int *res, str src, bit *u);
+sql5_export str BATSTRindex_int(bat *res, bat *src, bit *u);
+sql5_export str STRindex_sht(sht *res, str src, bit *u);
+sql5_export str BATSTRindex_sht(bat *res, bat *src, bit *u);
+sql5_export str STRindex_bte(bte *res, str src, bit *u);
+sql5_export str BATSTRindex_bte(bat *res, bat *src, bit *u);
+sql5_export str STRstrings(str *res, str src);
+sql5_export str BATSTRstrings(bat *res, bat *src);
 #endif /* _SQL_H */
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -1004,6 +1004,37 @@ command calc.timestamp( v:date, d:int) :
 address date_2_timestamp
 comment "cast date to a timestamp and check for overflow";
 
+command calc.index(v:str, u:bit) :bte 
+address STRindex_bte
+comment "Return the offsets as an index bat";
+
+command batcalc.index(v:bat[:oid,:str], u:bit) :bat[:oid,:bte] 
+address BATSTRindex_bte
+comment "Return the offsets as an index bat";
+
+command calc.index(v:str, u:bit) :sht 
+address STRindex_sht
+comment "Return the offsets as an index bat";
+
+command batcalc.index(v:bat[:oid,:str], u:bit) :bat[:oid,:sht] 
+address BATSTRindex_sht
+comment "Return the offsets as an index bat";
+
+command calc.index(v:str, u:bit) :int 
+address STRindex_int
+comment "Return the offsets as an index bat";
+
+command batcalc.index(v:bat[:oid,:str], u:bit) :bat[:oid,:int] 
+address BATSTRindex_int
+comment "Return the offsets as an index bat";
+
+command calc.strings(v:str) :str 
+address STRstrings
+comment "Return the strings";
+
+command batcalc.strings(v:bat[:oid,:str]) :bat[:oid,:str] 
+address BATSTRstrings
+comment "Return the strings";
 
 include sql_decimal;
 include sql_rank;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to