Changeset: dbf651dd9ddd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/dbf651dd9ddd
Branch: Jul2021
Log Message:

merged


diffs (truncated from 595 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
@@ -1688,10 +1688,27 @@ dump_table_data(Mapi mid, const char *sc
                goto bailout;
        }
        while ((mapi_fetch_row(hdl)) != 0) {
-               if (strcmp(mapi_fetch_field(hdl, 2), "1") == 0) {
+               const char *ttype = mapi_fetch_field(hdl, 2);
+               if (strcmp(ttype, "1") == 0) {
                        /* the table is actually a view */
                        goto doreturn;
                }
+               if (strcmp(ttype, "3") == 0) {
+                       /* merge table */
+                       goto doreturn;
+               }
+               if (strcmp(ttype, "4") == 0) {
+                       /* stream table */
+                       goto doreturn;
+               }
+               if (strcmp(ttype, "5") == 0) {
+                       /* remote table */
+                       goto doreturn;
+               }
+               if (strcmp(ttype, "6") == 0) {
+                       /* replica table */
+                       goto doreturn;
+               }
        }
        if (mapi_error(mid))
                goto bailout;
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -255,7 +255,7 @@ BATmaterialize(BAT *b)
        b->tbaseoff = 0;
        b->theap->dirty = true;
        BATsetprop_nolock(b, GDK_NUNIQUE, TYPE_oid, &(oid){is_oid_nil(t) ? 1 : 
b->batCount});
-       BATsetprop_nolock(b, GDK_UNIQUE_ESTIMATE, TYPE_dbl, 
&(dbl){is_oid_nil(t) ? 1 : b->batCount});
+       BATsetprop_nolock(b, GDK_UNIQUE_ESTIMATE, TYPE_dbl, 
&(dbl){is_oid_nil(t) ? 1.0 : (dbl)b->batCount});
        MT_lock_unset(&b->theaplock);
        b->ttype = TYPE_oid;
        BATsetdims(b);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -674,7 +674,7 @@ BATfree(BAT *b)
        MT_lock_set(&b->theaplock);
        if (nunique != BUN_NONE) {
                BATsetprop_nolock(b, GDK_NUNIQUE, TYPE_oid, &(oid){nunique});
-               BATsetprop_nolock(b, GDK_UNIQUE_ESTIMATE, TYPE_dbl, 
&(dbl){nunique});
+               BATsetprop_nolock(b, GDK_UNIQUE_ESTIMATE, TYPE_dbl, 
&(dbl){(dbl)nunique});
                BATsetprop_nolock(b, GDK_HASH_BUCKETS, TYPE_oid, 
&(oid){nbucket});
        }
        if (b->theap) {
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -342,11 +342,13 @@ string_reader(logger *lg, BAT *b, lng nr
                sz = (size_t)SZ;
                char *buf = lg->buf;
                if (lg->bufsize < sz) {
-                       lg->buf = buf = GDKrealloc(buf, sz);
+                       if (!(buf = GDKrealloc(lg->buf, sz)))
+                               return LOG_ERR;
+                       lg->buf = buf;
                        lg->bufsize = sz;
                }
 
-               if (!buf || mnstr_read(lg->input_log, buf, sz, 1) != 1)
+               if (mnstr_read(lg->input_log, buf, sz, 1) != 1)
                        return LOG_EOF;
                /* handle strings */
                char *t = buf;
@@ -2363,7 +2365,7 @@ string_writer(logger *lg, BAT *b, lng of
        size_t bufsz = lg->bufsize, resize = 0;
        BUN end = (BUN)(offset + nr);
        char *buf = lg->buf;
-       gdk_return res = GDK_FAIL;
+       gdk_return res = GDK_SUCCEED;
 
        if (!buf)
                return GDK_FAIL;
@@ -2372,11 +2374,11 @@ string_writer(logger *lg, BAT *b, lng of
        for ( ; p < end; ) {
                size_t sz = 0;
                if (resize) {
-                       lg->buf = buf = GDKrealloc(buf, resize);
-                       if (!buf) {
+                       if (!(buf = GDKrealloc(lg->buf, resize))) {
                                res = GDK_FAIL;
                                break;
                        }
+                       lg->buf = buf;
                        lg->bufsize = bufsz = resize;
                        resize = 0;
                }
@@ -2394,8 +2396,10 @@ string_writer(logger *lg, BAT *b, lng of
                                sz += len;
                        }
                }
-               if (sz && buf && mnstr_writeLng(lg->output_log, (lng) sz) && 
mnstr_write(lg->output_log, buf, sz, 1) == 1)
-                       res = GDK_SUCCEED;
+               if (sz && (!mnstr_writeLng(lg->output_log, (lng) sz) || 
mnstr_write(lg->output_log, buf, sz, 1) != 1)) {
+                       res = GDK_FAIL;
+                       break;
+               }
        }
        bat_iterator_end(&bi);
        return res;
diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -320,25 +320,29 @@ OPTpushselectImplementation(Client cntxt
 
                        /* rewrite batalgebra.like + [theta]select -> 
likeselect */
                        if (getModuleId(p) == algebraRef && p->retc == 1 &&
-                                       (getFunctionId(p) == selectRef || 
getFunctionId(p) == thetaselectRef)) {
+                               (getFunctionId(p) == selectRef || 
getFunctionId(p) == thetaselectRef)) {
                                int var = getArg(p, 1);
                                InstrPtr q = mb->stmt[vars[var]]; /* BEWARE: 
the optimizer may not add or remove statements ! */
 
                                if (isLikeOp(q) &&
-                                               !isaBatType(getArgType(mb, q, 
2)) && /* pattern is a value */
-                                               !isaBatType(getArgType(mb, q, 
3)) && /* escape is a value */
-                                               !isaBatType(getArgType(mb, q, 
4)) && /* isensitive flag is a value */
-                                               strcmp(getVarName(mb, 
getArg(q,0)), getVarName(mb, getArg(p,1))) == 0 /* the output variable from 
batalgebra.like is the input one for [theta]select */) {
+                                       !isaBatType(getArgType(mb, q, 2)) && 
isVarConstant(mb, getArg(q, 2)) && /* pattern is a value */
+                                       isVarConstant(mb, getArg(q, 3)) && /* 
escape is a value */
+                                       isVarConstant(mb, getArg(q, 4)) && /* 
isensitive flag is a value */
+                                       strcmp(getVarName(mb, getArg(q,0)), 
getVarName(mb, getArg(p,1))) == 0 /* the output variable from batalgebra.like 
is the input one for [theta]select */) {
                                        int has_cand = (getArgType(mb, p, 2) == 
newBatType(TYPE_oid)), offset = 0, anti = (getFunctionId(q)[0] == 'n');
                                        bit ignore_case = 
*(bit*)getVarValue(mb, getArg(q, 4)), selectok = TRUE;
 
                                        /* TODO at the moment we cannot convert 
if the select statement has NULL semantics
                                                we can convert it into VAL is 
NULL or PATTERN is NULL or ESCAPE is NULL
                                        */
-                                       if (getFunctionId(p) == selectRef) {
+                                       if (getFunctionId(p) == selectRef && 
isVarConstant(mb, getArg(p, 2 + has_cand)) &&
+                                               isVarConstant(mb, getArg(p, 3 + 
has_cand)) && isVarConstant(mb, getArg(p, 4 + has_cand)) &&
+                                               isVarConstant(mb, getArg(p, 5 + 
has_cand)) && isVarConstant(mb, getArg(p, 6 + has_cand)) &&
+                                               (p->argc < (has_cand ? 9 : 8) 
|| isVarConstant(mb, getArg(p, 7 + has_cand)))) {
                                                bit low = 
*(bit*)getVarValue(mb, getArg(p, 2 + has_cand)), high = *(bit*)getVarValue(mb, 
getArg(p, 3 + has_cand));
                                                bit li = *(bit*)getVarValue(mb, 
getArg(p, 4 + has_cand)), hi = *(bit*)getVarValue(mb, getArg(p, 5 + has_cand));
-                                               bit santi = 
*(bit*)getVarValue(mb, getArg(p, 6 + has_cand)), sunknown = (p->argc == 
(has_cand ? 9 : 8)) ? 0 : *(bit*)getVarValue(mb, getArg(p, 7 + has_cand));
+                                               bit santi = 
*(bit*)getVarValue(mb, getArg(p, 6 + has_cand));
+                                               bit sunknown = (p->argc == 
(has_cand ? 9 : 8)) ? 0 : *(bit*)getVarValue(mb, getArg(p, 7 + has_cand));
 
                                                /* semantic or not symmetric 
cases, it cannot be converted */
                                                if (is_bit_nil(low) || 
is_bit_nil(li) || is_bit_nil(santi) || low != high || li != hi || sunknown)
@@ -351,7 +355,8 @@ OPTpushselectImplementation(Client cntxt
                                                        anti = !anti;
                                                if (santi)
                                                        anti = !anti;
-                                       } else if (getFunctionId(p) == 
thetaselectRef) {
+                                       } else if (getFunctionId(p) == 
thetaselectRef &&
+                                                          isVarConstant(mb, 
getArg(p, 3)) && isVarConstant(mb, getArg(p, 4))) {
                                                bit truth_value = 
*(bit*)getVarValue(mb, getArg(p, 3));
                                                str comparison = 
(str)getVarValue(mb, getArg(p, 4));
 
@@ -364,6 +369,8 @@ OPTpushselectImplementation(Client cntxt
                                                        anti = !anti;
                                                else if (strcmp(comparison, 
"==") != 0)
                                                        selectok = FALSE;
+                                       } else {
+                                               selectok = FALSE;
                                        }
 
                                        if (selectok) {
diff --git a/sql/ChangeLog.Jul2021 b/sql/ChangeLog.Jul2021
--- a/sql/ChangeLog.Jul2021
+++ b/sql/ChangeLog.Jul2021
@@ -1,3 +1,7 @@
 # ChangeLog file for sql
 # This file is updated with Maddlog
 
+* Wed Jul 28 2021 Sjoerd Mullender <sjo...@acm.org>
+- Since STREAM tables support is removed, left over STREAM tables are
+  dropped from the catalog.
+
diff --git a/sql/storage/bat/bat_logger.c b/sql/storage/bat/bat_logger.c
--- a/sql/storage/bat/bat_logger.c
+++ b/sql/storage/bat/bat_logger.c
@@ -2416,6 +2416,138 @@ bl_postversion(void *Store, old_logger *
                        bat_destroy(b1);
                        bat_destroy(b3);
                }
+
+               {
+                       /* drop STREAM TABLEs
+                        * these tables don't actually have a disk presence, 
only
+                        * one in the catalog (so that's why we drop them and 
don't
+                        * convert them); we drop them by marking the relevant 
rows
+                        * in various catalog tables as deleted */
+                       BAT *dt = temp_descriptor(logger_find_bat(lg, 2067)); 
/* sys._tables */
+                       BAT *tt = temp_descriptor(logger_find_bat(lg, 2072)); 
/* sys._tables.type */
+                       if (dt == NULL || tt == NULL) {
+                               bat_destroy(dt);
+                               bat_destroy(tt);
+                               return GDK_FAIL;
+                       }
+                       BAT *cands = BATmaskedcands(0, BATcount(dt), dt, false);
+                       if (cands == NULL) {
+                               bat_destroy(dt);
+                               bat_destroy(tt);
+                               return GDK_FAIL;
+                       }
+                       BAT *strm = BATselect(tt, cands, &(sht){4}, NULL, true, 
true, false);
+                       bat_destroy(cands);
+                       bat_destroy(tt);
+                       if (strm == NULL) {
+                               bat_destroy(dt);
+                               return GDK_FAIL;
+                       }
+                       if (strm->batCount > 0) {
+                               for (BUN p = 0; p < strm->batCount; p++)
+                                       mskSetVal(dt, BUNtoid(strm, p), true);
+                               bat_destroy(dt);
+                               BAT *ids = COLnew(0, TYPE_int, 0, TRANSIENT);
+                               BAT *ti = temp_descriptor(logger_find_bat(lg, 
2068)); /* sys._tables.id */
+                               if (ids == NULL || ti == NULL) {
+                                       bat_destroy(ids);
+                                       bat_destroy(ti);
+                                       bat_destroy(strm);
+                                       return GDK_FAIL;
+                               }
+                               struct {
+                                       int id, tabid, dels; /* id, table_id 
and deleted rows */
+                               } foreign[10] = {
+                                       /* the first 7 entries are references 
to the table id
+                                        * the first column non-zero means the 
ids get collected */
+                                       {   0, 2049, 2047}, /* 
sys.table_partitions.table_id */
+                                       {   0, 2054, 2053}, /* 
sys.range_partitions.table_id */
+                                       {   0, 2060, 2059}, /* 
sys.value_partitions.table_id */
+                                       {2077, 2082, 2076}, /* 
sys._columns.table_id */
+                                       {2088, 2089, 2087}, /* 
sys.keys.table_id */
+                                       {2095, 2096, 2094}, /* 
sys.idxs.table_id */
+                                       {2100, 2102, 2099}, /* 
sys.triggers.table_id */
+
+                                       /* the remaining 3 are references to 
collected object ids */
+                                       {   0, 2111, 2110}, /* sys.objects.id */
+                                       {   0, 2064, 2063}, /* 
sys.dependencies.id */
+                                       {   0, 2065, 2063}, /* 
sys.dependencies.depend_id */
+                               };
+
+                               for (int i = 0; i < 10; i++) {
+                                       if (i == 7) {
+                                               /* change gear: we now need to 
delete the
+                                                * collected ids from 
sys.objects */
+                                               bat_destroy(ti);
+                                               ti = ids;
+                                               ids = NULL;
+                                               bat_destroy(strm);
+                                               strm = NULL;
+                                       }
+                                       BAT *ct = 
temp_descriptor(logger_find_bat(lg, foreign[i].tabid));
+                                       BAT *dc = 
temp_descriptor(logger_find_bat(lg, foreign[i].dels));
+                                       if (ct == NULL || dc == NULL) {
+                                               bat_destroy(ids);
+                                               bat_destroy(strm);
+                                               bat_destroy(ti);
+                                               bat_destroy(ct);
+                                               bat_destroy(dc);
+                                               return GDK_FAIL;
+                                       }
+                                       cands = BATmaskedcands(0, BATcount(dc), 
dc, false);
+                                       if (cands == NULL) {
+                                               bat_destroy(ids);
+                                               bat_destroy(strm);
+                                               bat_destroy(ti);
+                                               bat_destroy(ct);
+                                               bat_destroy(dc);
+                                               return GDK_FAIL;
+                                       }
+                                       BAT *strc = BATintersect(ct, ti, cands, 
strm, false, false, BUN_NONE);
+                                       bat_destroy(cands);
+                                       if (strc == NULL) {
+                                               bat_destroy(ids);
+                                               bat_destroy(strm);
+                                               bat_destroy(ti);
+                                               bat_destroy(ct);
+                                               bat_destroy(dc);
+                                               return GDK_FAIL;
+                                       }
+                                       for (BUN p = 0; p < strc->batCount; p++)
+                                               mskSetVal(dc, BUNtoid(strc, p), 
true);
+                                       if (foreign[i].id != 0) {
+                                               BAT *ci = 
temp_descriptor(logger_find_bat(lg, foreign[i].id));
+                                               if (ci == NULL) {
+                                                       bat_destroy(ids);
+                                                       bat_destroy(strc);
+                                                       bat_destroy(ct);
+                                                       bat_destroy(dc);
+                                                       bat_destroy(strm);
+                                                       bat_destroy(ti);
+                                                       return GDK_FAIL;
+                                               }
+                                               if (BATappend(ids, ci, strc, 
false) != GDK_SUCCEED) {
+                                                       bat_destroy(ids);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to