Changeset: 01d3e88859f6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/01d3e88859f6
Modified Files:
        sql/backends/monet5/sql.c
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

Merged with Jan2022


diffs (truncated from 865 to 300 lines):

diff --git a/monetdb5/optimizer/opt_fastpath.c 
b/monetdb5/optimizer/opt_fastpath.c
--- a/monetdb5/optimizer/opt_fastpath.c
+++ b/monetdb5/optimizer/opt_fastpath.c
@@ -17,6 +17,8 @@
 #include "opt_costModel.h"
 #include "opt_dataflow.h"
 #include "opt_deadcode.h"
+#include "opt_dict.h"
+#include "opt_for.h"
 #include "opt_emptybind.h"
 #include "opt_evaluate.h"
 #include "opt_garbageCollector.h"
@@ -76,7 +78,10 @@ OPTminimalfastImplementation(Client cntx
        optcall(true, OPTinlineImplementation);
        optcall(true, OPTremapImplementation);
        optcall(bincopy, OPTbincopyfromImplementation);
+       optcall(true, OPTemptybindImplementation);
        optcall(true, OPTdeadcodeImplementation);
+       optcall(true, OPTforImplementation);
+       optcall(true, OPTdictImplementation);
        optcall(multiplex, OPTmultiplexImplementation);
        optcall(generator, OPTgeneratorImplementation);
        optcall(malProfileMode, OPTprofilerImplementation);
@@ -117,6 +122,8 @@ OPTdefaultfastImplementation(Client cntx
        optcall(true, OPTdeadcodeImplementation);
        optcall(true, OPTpushselectImplementation);
        optcall(true, OPTaliasesImplementation);
+       optcall(true, OPTforImplementation);
+       optcall(true, OPTdictImplementation);
        optcall(true, OPTmitosisImplementation);
        optcall(true, OPTmergetableImplementation);
        optcall(bincopy, OPTbincopyfromImplementation);
diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -233,6 +233,8 @@ DICTcompress_col(Client cntxt, MalBlkPtr
        if (!isTable(t))
                throw(SQL, "dict.compress", SQLSTATE(42000) "%s '%s' is not 
persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (t->system)
+               throw(SQL, "dict.compress", SQLSTATE(42000) "columns from 
system tables cannot be compressed");
        sql_column *c = find_sql_column(t, cname);
        if (!c)
                throw(SQL, "dict.compress", SQLSTATE(3F000) "column '%s.%s.%s' 
unknown", sname, tname, cname);
@@ -497,7 +499,7 @@ DICTrenumber_intern( BAT *o, BAT *lc, BA
        }
        /* dense or cheap dense check */
        if (!BATtdense(lc) && !(lc->tsorted && lc->tkey && BATcount(lc) == 
offcnt && *(oid*)Tloc(lc, offcnt-1) == offcnt-1)) {
-               BAT *nrc = COLnew(0, rc->ttype, offcnt, TRANSIENT);
+               BAT *nrc = COLnew(0, ATOMtype(rc->ttype), offcnt, TRANSIENT);
                if (!nrc) {
                        if (lc != olc)
                                bat_destroy(lc);
@@ -507,14 +509,26 @@ DICTrenumber_intern( BAT *o, BAT *lc, BA
                }
 
                /* create map with holes filled in */
-               oid *op = Tloc(nrc, 0);
-               oid *ip = Tloc(rc, 0);
+               oid *restrict op = Tloc(nrc, 0);
                unsigned char *lp = Tloc(lc, 0);
-               for(BUN i = 0, j = 0; i<offcnt; i++) {
-                       if (lp[j] > i) {
-                               op[i] = offcnt;
-                       } else {
-                               op[i] = ip[j++];
+               if (BATtvoid(rc)) {
+                       oid seq = rc->tseqbase, j = 0;
+                       for(BUN i = 0; i<offcnt; i++) {
+                               if (lp[j] > i) {
+                                       op[i] = offcnt;
+                               } else {
+                                       op[i] = seq + j;
+                                       j++;
+                               }
+                       }
+               } else {
+                       oid *ip = Tloc(rc, 0);
+                       for(BUN i = 0, j = 0; i<offcnt; i++) {
+                               if (lp[j] > i) {
+                                       op[i] = offcnt;
+                               } else {
+                                       op[i] = ip[j++];
+                               }
                        }
                }
                BATsetcount(nrc, offcnt);
@@ -685,7 +699,7 @@ DICTthetaselect(Client cntxt, MalBlkPtr 
        BUN max_cnt = lv->ttype == TYPE_bte?256:(64*1024);
        if ((lv->tkey && (op[0] == '=' || op[0] == '!')) || ((op[0] == '<' || 
op[0] == '>') && lv->tsorted && BATcount(lv) < (max_cnt/2))) {
                BUN p = BUN_NONE;
-               if (ATOMvarsized(lv->ttype))
+               if (ATOMextern(lv->ttype))
                        v = *(ptr*)v;
                if (op[0] == '=' || op[0] == '!') {
                        p =  BUNfnd(lv, v);
@@ -707,7 +721,7 @@ DICTthetaselect(Client cntxt, MalBlkPtr 
                        bn = BATdense(0, 0, 0);
                }
        } else { /* select + intersect */
-               if (ATOMvarsized(lv->ttype))
+               if (ATOMextern(lv->ttype))
                        v = *(ptr*)v;
                bn = BATthetaselect(lv, NULL, v, op);
                /* call dict convert */
@@ -767,7 +781,7 @@ DICTselect(Client cntxt, MalBlkPtr mb, M
                throw(SQL, "dict.select", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
 
-       if (ATOMvarsized(lv->ttype)) {
+       if (ATOMextern(lv->ttype)) {
                l = *(ptr*)l;
                h = *(ptr*)h;
        }
diff --git a/sql/backends/monet5/for.c b/sql/backends/monet5/for.c
--- a/sql/backends/monet5/for.c
+++ b/sql/backends/monet5/for.c
@@ -29,6 +29,59 @@ BATnegateprops(BAT *b)
        b->tnokey[1] = 0;
 }
 
+BAT *
+FORdecompress_(BAT *o, lng minval, int type, role_t role)
+{
+       BAT *b = COLnew(o->hseqbase, type, BATcount(o), role);
+
+       if (!b)
+               return NULL;
+       BUN cnt = BATcount(o);
+#ifdef HAVE_HGE
+       if (type == TYPE_hge) {
+               if (o->ttype == TYPE_bte) {
+                       hge *ov = Tloc(b, 0);
+                       bte *iv = Tloc(o, 0);
+                       for(BUN i = 0; i<cnt; i++)
+                               ov[i] = minval + iv[i];
+               } else {
+                       hge *ov = Tloc(b, 0);
+                       sht *iv = Tloc(o, 0);
+                       for(BUN i = 0; i<cnt; i++)
+                               ov[i] = minval + iv[i];
+               }
+       } else
+#endif
+       if (type == TYPE_lng) {
+               if (o->ttype == TYPE_bte) {
+                       lng *ov = Tloc(b, 0);
+                       bte *iv = Tloc(o, 0);
+                       for(BUN i = 0; i<cnt; i++)
+                               ov[i] = minval + iv[i];
+               } else {
+                       lng *ov = Tloc(b, 0);
+                       sht *iv = Tloc(o, 0);
+                       for(BUN i = 0; i<cnt; i++)
+                               ov[i] = minval + iv[i];
+               }
+       } else if (type == TYPE_int) {
+               if (o->ttype == TYPE_bte) {
+                       int *ov = Tloc(b, 0);
+                       bte *iv = Tloc(o, 0);
+                       for(BUN i = 0; i<cnt; i++)
+                               ov[i] = (int) (minval + iv[i]);
+               } else {
+                       int *ov = Tloc(b, 0);
+                       sht *iv = Tloc(o, 0);
+                       for(BUN i = 0; i<cnt; i++)
+                               ov[i] = (int) (minval + iv[i]);
+               }
+       }
+       BATsetcount(b, cnt);
+       BATnegateprops(b);
+       return b;
+}
+
 str
 FORdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
@@ -54,37 +107,46 @@ FORdecompress(Client cntxt, MalBlkPtr mb
                throw(SQL, "for.decompress", SQLSTATE(3F000) "for decompress: 
invalid type");
        }
 
-       BUN cnt = BATcount(o);
-       if (tt == TYPE_lng) {
-               lng minval = *getArgReference_lng(stk, pci, 2);
+       lng minval = *getArgReference_lng(stk, pci, 2);
 
-               b = COLnew(o->hseqbase, TYPE_lng, cnt, PERSISTENT);
-               if (!b) {
-                       bat_destroy(o);
-                       throw(SQL, "for.decompress", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               }
-               if (o->ttype == TYPE_bte) {
-                       lng *ov = Tloc(b, 0);
-                       bte *iv = Tloc(o, 0);
-                       for(BUN i = 0; i<cnt; i++)
-                               ov[i] = minval + iv[i];
-               } else {
-                       lng *ov = Tloc(b, 0);
-                       sht *iv = Tloc(o, 0);
-                       for(BUN i = 0; i<cnt; i++)
-                               ov[i] = minval + iv[i];
-               }
-       } else {
+       b = FORdecompress_(o, minval, tt, TRANSIENT);
+       if (!b) {
                bat_destroy(o);
-               throw(SQL, "for.decompress", SQLSTATE(3F000) "offset type %s 
not yet implemented", ATOMname(tt));
+               throw(SQL, "for.decompress", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
        bat_destroy(o);
-       BATsetcount(b, cnt);
-       BATnegateprops(b);
        BBPkeepref(*r = b->batCacheid);
        return MAL_SUCCEED;
 }
 
+static BAT *
+FORcompress_(BAT *b, lng min_val, lng max_val, role_t role)
+{
+       BAT *o;
+       BUN cnt = BATcount(b);
+
+       if ((max_val-min_val) < GDK_bte_max/2) {
+               o = COLnew(b->hseqbase, TYPE_bte, cnt, role);
+               if (!o)
+                       return NULL;
+               bte *ov = Tloc(o, 0);
+               lng *iv = Tloc(b, 0);
+               for(BUN i = 0; i<cnt; i++)
+                       ov[i] = (bte)(iv[i] - min_val);
+       } else {
+               o = COLnew(b->hseqbase, TYPE_sht, cnt, role);
+               if (!o)
+                       return NULL;
+               sht *ov = Tloc(o, 0);
+               lng *iv = Tloc(b, 0);
+               for(BUN i = 0; i<cnt; i++)
+                       ov[i] = (sht)(iv[i] - min_val);
+       }
+       BATsetcount(o, cnt);
+       BATnegateprops(o);
+       return o;
+}
+
 static str
 FORcompress_intern(char **comp_min_val, BAT **r, BAT *b)
 {
@@ -122,23 +184,9 @@ FORcompress_intern(char **comp_min_val, 
                        throw(SQL, "for.compress", SQLSTATE(3F000) "for 
compress: for 'for' compression column's cannot have NULL's");
                if ((max_val-min_val) > GDK_sht_max)
                        throw(SQL, "for.compress", SQLSTATE(3F000) "for 
compress: too large value spread for 'for' compression");
-               if ((max_val-min_val) < GDK_bte_max/2) {
-                       o = COLnew(b->hseqbase, TYPE_bte, cnt, PERSISTENT);
-                       if (!o)
-                               throw(SQL, "for.compress", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       bte *ov = Tloc(o, 0);
-                       lng *iv = Tloc(b, 0);
-                       for(BUN i = 0; i<cnt; i++)
-                               ov[i] = (bte)(iv[i] - min_val);
-               } else {
-                       o = COLnew(b->hseqbase, TYPE_sht, cnt, PERSISTENT);
-                       if (!o)
-                               throw(SQL, "for.compress", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       sht *ov = Tloc(o, 0);
-                       lng *iv = Tloc(b, 0);
-                       for(BUN i = 0; i<cnt; i++)
-                               ov[i] = (sht)(iv[i] - min_val);
-               }
+               o = FORcompress_(b, min_val, max_val, PERSISTENT);
+               if (!o)
+                       throw(SQL, "for.compress", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                snprintf(buf, 64, "FOR-" LLFMT, min_val);
        } else {
                GDKfree(mn);
@@ -149,8 +197,6 @@ FORcompress_intern(char **comp_min_val, 
                bat_destroy(o);
                throw(SQL, "for.compress", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
-       BATsetcount(o, cnt);
-       BATnegateprops(o);
        *r = o;
        return NULL;
 }
@@ -188,6 +234,8 @@ FORcompress_col(Client cntxt, MalBlkPtr 
        if (!isTable(t))
                throw(SQL, "for.compress", SQLSTATE(42000) "%s '%s' is not 
persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
+       if (t->system)
+               throw(SQL, "for.compress", SQLSTATE(42000) "columns from system 
tables cannot be compressed");
        sql_column *c = find_sql_column(t, cname);
        if (!c)
                throw(SQL, "for.compress", SQLSTATE(3F000) "column '%s.%s.%s' 
unknown", sname, tname, cname);
@@ -236,3 +284,72 @@ FORcompress_col(Client cntxt, MalBlkPtr 
        }
        return msg;
 }
+
+int
+FORprepare4append(BAT **noffsets, BAT *b, lng minval, int tt)
+{
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to