Changeset: ebb791914f05 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ebb791914f05
Modified Files:
        sql/backends/monet5/sql.c
Branch: dict
Log Message:

merged with default


diffs (truncated from 668 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -637,7 +637,7 @@
 [ "bat",       "getRole",      "command bat.getRole(X_0:bat[:any_1]):str ",    
"BKCgetRole;",  "Returns the rolename of the head column of a BAT."     ]
 [ "bat",       "getSequenceBase",      "command 
bat.getSequenceBase(X_0:bat[:any_1]):oid ",    "BKCgetSequenceBase;",  "Get the 
sequence base for the void column of a BAT."   ]
 [ "bat",       "getSize",      "command bat.getSize(X_0:bat[:any_1]):lng ",    
"BKCgetSize;",  "Calculate the actual size of the BAT descriptor, heaps, hashes 
and imprint indices in bytes\nrounded to the memory page size (see 
bbp.getPageSize())." ]
-[ "bat",       "getVHeapSize", "command bat.getVHeapSize(X_0:bat[:any_1]):lng 
",       "BKCgetVHeapSize;",     "Calculate the vheap size for string bats"     
 ]
+[ "bat",       "getVHeapSize", "command bat.getVHeapSize(X_0:bat[:any_1]):lng 
",       "BKCgetVHeapSize;",     "Calculate the vheap size for varsized bats"   
 ]
 [ "bat",       "getorderidx",  "pattern 
bat.getorderidx(X_0:bat[:any_1]):bat[:oid] ",  "OIDXgetorderidx;",     "Return 
the order index if it exists"   ]
 [ "bat",       "hasorderidx",  "pattern bat.hasorderidx(X_0:bat[:any_1]):bit 
",        "OIDXhasorderidx;",     "Return true if order index exists"     ]
 [ "bat",       "imprints",     "command bat.imprints(X_0:bat[:bte]):void ",    
"CMDBATimprints;",      ""      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -750,7 +750,7 @@
 [ "bat",       "getRole",      "command bat.getRole(X_0:bat[:any_1]):str ",    
"BKCgetRole;",  "Returns the rolename of the head column of a BAT."     ]
 [ "bat",       "getSequenceBase",      "command 
bat.getSequenceBase(X_0:bat[:any_1]):oid ",    "BKCgetSequenceBase;",  "Get the 
sequence base for the void column of a BAT."   ]
 [ "bat",       "getSize",      "command bat.getSize(X_0:bat[:any_1]):lng ",    
"BKCgetSize;",  "Calculate the actual size of the BAT descriptor, heaps, hashes 
and imprint indices in bytes\nrounded to the memory page size (see 
bbp.getPageSize())." ]
-[ "bat",       "getVHeapSize", "command bat.getVHeapSize(X_0:bat[:any_1]):lng 
",       "BKCgetVHeapSize;",     "Calculate the vheap size for string bats"     
 ]
+[ "bat",       "getVHeapSize", "command bat.getVHeapSize(X_0:bat[:any_1]):lng 
",       "BKCgetVHeapSize;",     "Calculate the vheap size for varsized bats"   
 ]
 [ "bat",       "getorderidx",  "pattern 
bat.getorderidx(X_0:bat[:any_1]):bat[:oid] ",  "OIDXgetorderidx;",     "Return 
the order index if it exists"   ]
 [ "bat",       "hasorderidx",  "pattern bat.hasorderidx(X_0:bat[:any_1]):bit 
",        "OIDXhasorderidx;",     "Return true if order index exists"     ]
 [ "bat",       "imprints",     "command bat.imprints(X_0:bat[:bte]):void ",    
"CMDBATimprints;",      ""      ]
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -618,9 +618,11 @@ BKCgetVHeapSize(lng *tot, const bat *bid
        if ((b = BATdescriptor(*bid)) == NULL) {
                throw(MAL, "bat.getVHeapSize", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
        }
-       int _tpe= ATOMstorage((b)->ttype);
-       if (_tpe >= TYPE_str) {
-               size += b->tvheap->size;
+       if (ATOMvarsized(b->ttype)) {
+               MT_lock_set(&b->theaplock);
+               if (b->tvheap)
+                       size += b->tvheap->size;
+               MT_lock_unset(&b->theaplock);
        }
 
        *tot = size;
@@ -1251,7 +1253,7 @@ mel_func bat5_init_funcs[] = {
  command("bat", "densebat", BKCdensebat, false, "Creates a new [void,void] BAT 
of size 'sz'.", args(1,2, batarg("",oid),arg("sz",lng))),
  command("bat", "info", BKCinfo, false, "Produce a table containing 
information about a BAT in [attribute,value] format. \nIt contains all 
properties of the BAT record. ", args(2,3, 
batarg("",str),batarg("",str),batargany("b",1))),
  command("bat", "getSize", BKCgetSize, false, "Calculate the actual size of 
the BAT descriptor, heaps, hashes and imprint indices in bytes\nrounded to the 
memory page size (see bbp.getPageSize()).", args(1,2, 
arg("",lng),batargany("b",1))),
- command("bat", "getVHeapSize", BKCgetVHeapSize, false, "Calculate the vheap 
size for string bats", args(1,2, arg("",lng),batargany("b",1))),
+ command("bat", "getVHeapSize", BKCgetVHeapSize, false, "Calculate the vheap 
size for varsized bats", args(1,2, arg("",lng),batargany("b",1))),
  command("bat", "getCapacity", BKCgetCapacity, false, "Returns the current 
allocation size (in max number of elements) of a BAT.", args(1,2, 
arg("",lng),batargany("b",1))),
  command("bat", "getColumnType", BKCgetColumnType, false, "Returns the type of 
the tail column of a BAT, as an integer type number.", args(1,2, 
arg("",str),batargany("b",1))),
  command("bat", "getRole", BKCgetRole, false, "Returns the rolename of the 
head column of a BAT.", args(1,2, arg("",str),batargany("bid",1))),
diff --git a/monetdb5/modules/mal/batExtensions.c 
b/monetdb5/modules/mal/batExtensions.c
--- a/monetdb5/modules/mal/batExtensions.c
+++ b/monetdb5/modules/mal/batExtensions.c
@@ -289,8 +289,10 @@ CMDBATvacuum(bat *r, const bat *bid)
 
        if ((b = BATdescriptor(*bid)) == NULL)
                throw(MAL, "bat.vacuum", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
-       if ((bn = COLcopy(b, b->ttype, true, b->batRole)) == NULL)
+       if ((bn = COLcopy(b, b->ttype, true, b->batRole)) == NULL) {
+               BBPunfix(b->batCacheid);
                throw(MAL, "bat.vacuum", GDK_EXCEPTION);
+       }
 
        BBPkeepref(*r = bn->batCacheid);
        BBPunfix(b->batCacheid);
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -1524,7 +1524,7 @@ static str RMTbincopyto(Client cntxt, Ma
        if (BBPfix(bid) <= 0)
                throw(MAL, "remote.bincopyto", MAL_MALLOC_FAIL);
 
-       sendtheap = b->ttype != TYPE_void && b->tvarsized;
+       sendtheap = !BATtvoid(b) && b->tvarsized;
        if (isVIEW(b) && sendtheap && VIEWvtparent(b) && BATcount(b) < 
BATcount(BBP_cache(VIEWvtparent(b)))) {
                if ((b = BATdescriptor(bid)) == NULL) {
                        BBPunfix(bid);
@@ -1560,10 +1560,10 @@ static str RMTbincopyto(Client cntxt, Ma
                        BATtdense(v),
                        v->batCount,
                        BATtvoid(v) ? 0 : (size_t)v->batCount << v->tshift,
-                       sendtheap && v->batCount > 0 ? v->tvheap->free : 0
+                       sendtheap && !BATtvoid(v) && v->batCount > 0 ? 
v->tvheap->free : 0
                        );
 
-       if (v->batCount > 0) {
+       if (!BATtvoid(v) && v->batCount > 0) {
                BATiter vi = bat_iterator(v);
                mnstr_write(cntxt->fdout, /* tail */
                                        vi.base, vi.count * vi.width, 1);
@@ -1571,7 +1571,7 @@ static str RMTbincopyto(Client cntxt, Ma
                        mnstr_write(cntxt->fdout, /* theap */
                                                vi.vh->base, vi.vhfree, 1);
                bat_iterator_end(&vi);
-       }
+       }       
        /* flush is done by the calling environment (MAL) */
 
        if (b != v)
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
@@ -5078,10 +5078,13 @@ SQLstr_column_vacuum(Client cntxt, MalBl
        sql_table *t = NULL;
        sql_column *c = NULL;
 
-       if((s = mvc_bind_schema(m, sname)) == NULL)
+       if ((s = mvc_bind_schema(m, sname)) == NULL)
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(3F000) "Invalid or 
missing schema %s",sname);
-       if((t = mvc_bind_table(m, s, tname)) == NULL)
+       if ((t = mvc_bind_table(m, s, tname)) == NULL)
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(42S02) "Invalid or 
missing table %s.%s",sname,tname);
+       if (!isTable(t))
+               throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "%s '%s' is 
not persistent",
+                         TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(42S22) "Column not 
found %s.%s",sname,tname);
 
@@ -5117,7 +5120,12 @@ str_column_vacuum_callback(int argc, voi
                return GDK_FAIL;
        }
 
-       sql_trans_begin(session);
+       if (sql_trans_begin(session) < 0) {
+               TRC_ERROR((component_t) SQL, "[str_column_vacuum_callback] -- 
Failed to begin transaction!");
+               sql_session_destroy(session);
+               sa_destroy(sa);
+               return GDK_FAIL;
+       }
 
        do {
                if((s = find_sql_schema(session->tr, sname)) == NULL) {
@@ -5171,6 +5179,7 @@ SQLstr_column_auto_vacuum(Client cntxt, 
        char *tname = *getArgReference_str(stk, pci, 2);
        char *cname = *getArgReference_str(stk, pci, 3);
        int interval = *getArgReference_int(stk, pci, 4); // in sec
+       char *sname_copy = NULL, *tname_copy = NULL, *cname_copy = NULL;
 
        if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
                return msg;
@@ -5181,14 +5190,23 @@ SQLstr_column_auto_vacuum(Client cntxt, 
        sql_table *t = NULL;
        sql_column *c = NULL;
 
-       if((s = mvc_bind_schema(m, sname)) == NULL)
+       if ((s = mvc_bind_schema(m, sname)) == NULL)
                throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(3F000) 
"Invalid or missing schema %s",sname);
-       if((t = mvc_bind_table(m, s, tname)) == NULL)
+       if ((t = mvc_bind_table(m, s, tname)) == NULL)
                throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42S02) 
"Invalid or missing table %s.%s",sname,tname);
+       if (!isTable(t))
+               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "%s 
'%s' is not persistent",
+                         TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42S22) 
"Column not found %s.%s",sname,tname);
 
-       void *argv[4] = {m->store, GDKstrdup(sname), GDKstrdup(tname), 
GDKstrdup(cname)};
+       if (!(sname_copy = GDKstrdup(sname)) || !(tname_copy = 
GDKstrdup(tname)) || !(cname_copy = GDKstrdup(cname))) {
+               GDKfree(sname_copy);
+               GDKfree(tname_copy);
+               GDKfree(cname_copy);
+               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
+       }
+       void *argv[4] = {m->store, sname_copy, tname_copy, cname_copy};
 
        gdk_return res;
        if((res = gdk_add_callback("str_column_vacuum", 
str_column_vacuum_callback, 4, argv, interval)) != GDK_SUCCEED) {
@@ -5217,10 +5235,13 @@ SQLstr_column_stop_vacuum(Client cntxt, 
        sql_table *t = NULL;
        sql_column *c = NULL;
 
-       if((s = mvc_bind_schema(m, sname)) == NULL)
+       if ((s = mvc_bind_schema(m, sname)) == NULL)
                throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(3F000) 
"Invalid or missing schema %s",sname);
-       if((t = mvc_bind_table(m, s, tname)) == NULL)
+       if ((t = mvc_bind_table(m, s, tname)) == NULL)
                throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42S02) 
"Invalid or missing table %s.%s",sname,tname);
+       if (!isTable(t))
+               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "%s 
'%s' is not persistent",
+                         TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
        if ((c = mvc_bind_column(m, t, cname)) == NULL)
                throw(SQL, "sql.str_column_stop_vacuum", SQLSTATE(42S22) 
"Column not found %s.%s",sname,tname);
 
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -4219,6 +4219,15 @@ sql_update_default(Client c, mvc *sql, c
                                        "drop function sys.reverse(string);\n"
                                        "drop all function sys.fuse;\n");
 
+       /* 26_sysmon.sql */
+       pos += snprintf(buf + pos, bufsize - pos,
+                                       "create procedure sys.vacuum(sname 
string, tname string, cname string)\n"
+                                       "       external name sql.vacuum;\n"
+                                       "create procedure sys.vacuum(sname 
string, tname string, cname string, interval int)\n"
+                                       "       external name sql.vacuum;\n"
+                                       "create procedure sys.stop_vacuum(sname 
string, tname string, cname string)\n"
+                                       "       external name 
sql.stop_vacuum;\n");
+
        assert(pos < bufsize);
        printf("Running database upgrade commands:\n%s\n", buf);
        err = SQLstatementIntern(c, buf, "update", true, false, NULL);
diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -134,19 +134,22 @@ exp_print(mvc *sql, stream *fout, sql_ex
                } else if (e->flag & PSM_WHILE) {
                        mnstr_printf(fout, "while ");
                        exp_print(sql, fout, e->l, depth, refs, 0, 0);
-                       exps_print(sql, fout, e->r, depth, refs, alias, 0);
+                       exps_print(sql, fout, e->r, depth, refs, 0, 0);
+                       alias = 0;
                } else if (e->flag & PSM_IF) {
                        mnstr_printf(fout, "if ");
                        exp_print(sql, fout, e->l, depth, refs, 0, 0);
-                       exps_print(sql, fout, e->r, depth, refs, alias, 0);
+                       exps_print(sql, fout, e->r, depth, refs, 0, 0);
                        if (e->f)
-                               exps_print(sql, fout, e->f, depth, refs, alias, 
0);
+                               exps_print(sql, fout, e->f, depth, refs, 0, 0);
+                       alias = 0;
                } else if (e->flag & PSM_REL) {
                        rel_print_(sql, fout, e->l, depth+10, refs, 1);
                } else if (e->flag & PSM_EXCEPTION) {
                        mnstr_printf(fout, "except ");
                        exp_print(sql, fout, e->l, depth, refs, 0, 0);
                        mnstr_printf(fout, " error %s", (const char *) e->r);
+                       alias = 0;
                }
                break;
        }
@@ -198,11 +201,11 @@ exp_print(mvc *sql, stream *fout, sql_ex
                mnstr_printf(fout, "\"%s\".\"%s\"",
                                f->func->s?dump_escape_ident(sql->ta, 
f->func->s->base.name):"sys",
                                dump_escape_ident(sql->ta, f->func->base.name));
-               exps_print(sql, fout, e->l, depth, refs, alias, 1);
+               exps_print(sql, fout, e->l, depth, refs, 0, 1);
                if (e->r) { /* list of optional lists */
                        list *l = e->r;
                        for(node *n = l->h; n; n = n->next)
-                               exps_print(sql, fout, n->data, depth, refs, 
alias, 1);
+                               exps_print(sql, fout, n->data, depth, refs, 0, 
1);
                }
                if (e->flag && is_compare_func(f))
                        mnstr_printf(fout, " %s", e->flag==1?"ANY":"ALL");
@@ -219,7 +222,7 @@ exp_print(mvc *sql, stream *fout, sql_ex
                if (zero_if_empty(e))
                        mnstr_printf(fout, " zero if empty ");
                if (e->l)
-                       exps_print(sql, fout, e->l, depth, refs, alias, 1);
+                       exps_print(sql, fout, e->l, depth, refs, 0, 1);
                else
                        mnstr_printf(fout, "()");
        }       break;
@@ -238,25 +241,25 @@ exp_print(mvc *sql, stream *fout, sql_ex
                break;
        case e_cmp:
                if (e->flag == cmp_in || e->flag == cmp_notin) {
-                       exp_print(sql, fout, e->l, depth, refs, 0, alias);
+                       exp_print(sql, fout, e->l, depth, refs, 0, 0);
                        if (is_anti(e))
                                mnstr_printf(fout, " !");
                        cmp_print(sql, fout, e->flag);
-                       exps_print(sql, fout, e->r, depth, refs, alias, 1);
+                       exps_print(sql, fout, e->r, depth, refs, 0, 1);
                } else if (e->flag == cmp_or) {
-                       exps_print(sql, fout, e->l, depth, refs, alias, 1);
+                       exps_print(sql, fout, e->l, depth, refs, 0, 1);
                        if (is_anti(e))
                                mnstr_printf(fout, " !");
                        cmp_print(sql, fout, e->flag);
-                       exps_print(sql, fout, e->r, depth, refs, alias, 1);
+                       exps_print(sql, fout, e->r, depth, refs, 0, 1);
                } else if (e->flag == cmp_filter) {
                        sql_subfunc *f = e->f;
 
-                       exps_print(sql, fout, e->l, depth, refs, alias, 1);
+                       exps_print(sql, fout, e->l, depth, refs, 0, 1);
                        if (is_anti(e))
                                mnstr_printf(fout, " !");
                        mnstr_printf(fout, " FILTER \"%s\" ", 
dump_escape_ident(sql->ta, f->func->base.name));
-                       exps_print(sql, fout, e->r, depth, refs, alias, 1);
+                       exps_print(sql, fout, e->r, depth, refs, 0, 1);
                } else if (e->f) {
                        exp_print(sql, fout, e->r, depth+1, refs, 0, 0);
                        if (is_anti(e))
diff --git a/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test 
b/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
--- a/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
+++ b/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
@@ -15,7 +15,7 @@ project (
 | group by (
 | | table("sys"."dbg") [ "dbg"."a", "dbg"."b" ]
 | ) [ "dbg"."a" as "d" ] [ "d", "sys"."min" no nil ("dbg"."b") as "%1"."%1" ]
-) [ "d", "%1"."%1", "sys"."sql_mul"("sys"."sql_div"("%1"."%1", tinyint "2" as 
"%2"."%2"), tinyint "2") as "f" ]
+) [ "d", "%1"."%1", "sys"."sql_mul"("sys"."sql_div"("%1"."%1", tinyint "2"), 
tinyint "2") as "f" ]
 
 statement ok
 set optimizer = 'sequential_pipe'
@@ -50,7 +50,7 @@ project (
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to