MonetDB: returning - nest modify relations instead using attr list

2024-10-03 Thread Yunus Koning via checkin-list
Changeset: 0711f13f3fc4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0711f13f3fc4
Modified Files:
sql/backends/monet5/rel_bin.c
sql/include/sql_relation.h
sql/server/rel_optimize_others.c
sql/server/rel_updates.c
sql/test/2024/Tests/returning.test
Branch: returning
Log Message:

nest modify relations instead using attr list


diffs (truncated from 331 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
@@ -5352,7 +5352,7 @@ rel2bin_insert(backend *be, sql_rel *rel
if (!insert)
return NULL;
 
-   if (rel->attr) {
+   if (rel->returning) {
list* il = sa_list(sql->sa);
sql_rel* inner = rel->l;
assert(inner->op == op_basetable);
@@ -5362,21 +5362,7 @@ rel2bin_insert(backend *be, sql_rel *rel
stmt*   s   = stmt_rename(be, ce, ins);// label 
each insert statement with the corresponding col exp label
append(il, s);
}
-   stmt* inserts2 = stmt_list(be, il);
-
-   list* rl = sa_list(sql->sa);
-   for (n = rel->attr->h; n; n = n->next) {
-   sql_exp *exp = n->data;
-   stmt *s = exp_bin(be, exp, inserts2, NULL, NULL, NULL, 
NULL, NULL, 0, 0, 0);
-   if (!exp_name(exp))
-   exp_label(sql->sa, exp, ++sql->label);
-   if (exp_name(exp)) {
-   s = stmt_rename(be, exp, s);
-   s->label = exp->alias.label;
-   }
-   append(rl, s);
-   }
-   returning = stmt_list(be, rl);
+   returning = stmt_list(be, il);
sql->type = Q_TABLE;
}
 
@@ -6427,7 +6413,7 @@ rel2bin_update(backend *be, sql_rel *rel
}
 
stmt* returning = NULL;
-   if (rel->attr) {
+   if (rel->returning) {
sql_rel* b = rel->l;
int refcnt = b->ref.refcnt; // HACK: forces recalculation of 
base columns since they are assumed to be updated
b->ref.refcnt = 1;
@@ -6435,25 +6421,6 @@ rel2bin_update(backend *be, sql_rel *rel
b->ref.refcnt = refcnt;
returning->cand = tids;
returning = subrel_project(be, returning, refs, b);
-   list *pl = sa_list(sql->sa);
-   if (pl == NULL)
-   return NULL;
-   stmt *psub = stmt_list(be, pl);
-   if (psub == NULL)
-   return NULL;
-   for (node *en = rel->attr->h; en; en = en->next) {
-   sql_exp *exp = en->data;
-   stmt *s = exp_bin(be, exp, returning, NULL, NULL, NULL, 
NULL, NULL, 0, 0, 0);
-
-   if (!exp_name(exp))
-   exp_label(sql->sa, exp, ++sql->label);
-   s = stmt_rename(be, exp, s);
-   s->label = exp->alias.label;
-   list_append(pl, s);
-   }
-   stmt_set_nrcols(psub);
-   returning = psub;
-   returning = subrel_project(be, returning, refs, NULL);
sql->type = Q_TABLE;
}
 
@@ -6703,7 +6670,7 @@ static stmt *
 rel2bin_delete(backend *be, sql_rel *rel, list *refs)
 {
mvc *sql = be->mvc;
-   stmt *stdelete = NULL, *tids = NULL, *s = NULL;
+   stmt *stdelete = NULL, *tids = NULL, *returning = NULL;
sql_rel *tr = rel->l;
sql_table *t = NULL;
 
@@ -6721,19 +6688,13 @@ rel2bin_delete(backend *be, sql_rel *rel
tids = rows->op4.lval->h->data; /* TODO this should be the 
candidate list instead */
}
 
-   if (rel->attr) {
-   sql_rel* inner = rel->l;
-   if (rel_is_ref(inner)) {
-   s = refs_find_rel(refs, inner);
-   if (s)
-   s->cand = tids;
-   }
-
-   sql_rel* ret = rel_project(sql->sa, inner, rel->attr);
-   s = subrel_bin(be, ret, refs);
-   s = subrel_project(be, s, refs, rel);
+   if (rel->returning) {
+   returning = subrel_bin(be, rel->l, refs);
+   returning->cand = tids;
+   returning = subrel_project(be, returning, refs, rel->l);
sql->type = Q_TABLE;
}
+
stdelete = sql_delete(be, t, tids);
if (sql->cascade_action)
sql->cascade_action = NULL;
@@ -6742,7 +6703,7 @@ rel2bin_delete(backend *be, sql_rel *rel
 
if (rel->r && !rel_predicates(be, rel->r))
return NULL;
-   return s?s:stdelete;
+   return returning?returning:stdelete;
 }
 
 struct tablelist {
@@ -7580,17 +7541,

MonetDB: Aug2024 - Correct typo

2024-10-03 Thread Martin van Dinther via checkin-list
Changeset: a62032f034ae for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a62032f034ae
Modified Files:
clients/mapilib/mapi.c
Branch: Aug2024
Log Message:

Correct typo


diffs (12 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -519,7 +519,7 @@
  * zero is returned upon encountering an error or when the database value
  * is NULL; this can be analyzed in using @code{mapi\_error()}.
  *
- * @item size_t mapi_fetch_fiels_len(MapiHdl hdl, int fnr)
+ * @item size_t mapi_fetch_field_len(MapiHdl hdl, int fnr)
  *
  * Return the length of the C-string representation excluding trailing NULL
  * byte of the value.  Zero is returned upon encountering an error, when the
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - In sys.storage(), report hash size even if ha...

2024-10-03 Thread Sjoerd Mullender via checkin-list
Changeset: fbfa13791072 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fbfa13791072
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk_hash.c
gdk/gdk_hash.h
sql/backends/monet5/sql.c
Branch: default
Log Message:

In sys.storage(), report hash size even if hash not loaded.


diffs (87 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -351,6 +351,7 @@ void *GDKzalloc(size_t size) __attribute
 void HASHdestroy(BAT *b);
 BUN HASHlist(Hash *h, BUN i);
 BUN HASHprobe(const Hash *h, const void *v);
+size_t HASHsize(BAT *b);
 void HEAP_free(Heap *heap, var_t block);
 gdk_return HEAP_initialize(Heap *heap, size_t nbytes, size_t nprivate, int 
alignment);
 var_t HEAP_malloc(BAT *b, size_t nbytes);
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -562,6 +562,40 @@ BATcheckhash(BAT *b)
return h != NULL;
 }
 
+/* figure out size of the hash (sum of the sizes of the two hash files)
+ * without loading them */
+size_t
+HASHsize(BAT *b)
+{
+   size_t sz = 0;
+   MT_rwlock_rdlock(&b->thashlock);
+   if (b->thash == NULL) {
+   sz = 0;
+   } else if (b->thash != (Hash *) 1) {
+   sz = b->thash->heaplink.size + b->thash->heapbckt.size;
+   } else {
+   int farmid = BBPselectfarm(b->batRole, b->ttype, hashheap);
+   if (farmid >= 0) {
+   const char *nme = BBP_physical(b->batCacheid);
+   char *fname = GDKfilepath(farmid, BATDIR, nme, 
"thashb");
+   if (fname != NULL) {
+   struct stat st;
+   if (stat(fname, &st) == 0) {
+   sz = (size_t) st.st_size;
+   fname[strlen(fname) - 1] = 'l';
+   if (stat(fname, &st) == 0)
+   sz += (size_t) st.st_size;
+   else
+   sz = 0;
+   }
+   GDKfree(fname);
+   }
+   }
+   }
+   MT_rwlock_rdunlock(&b->thashlock);
+   return sz;
+}
+
 static void
 BAThashsave_intern(BAT *b, bool dosync)
 {
diff --git a/gdk/gdk_hash.h b/gdk/gdk_hash.h
--- a/gdk/gdk_hash.h
+++ b/gdk/gdk_hash.h
@@ -37,6 +37,7 @@ gdk_export gdk_return BAThash(BAT *b);
 gdk_export void HASHdestroy(BAT *b);
 gdk_export BUN HASHprobe(const Hash *h, const void *v);
 gdk_export BUN HASHlist(Hash *h, BUN i);
+gdk_export size_t HASHsize(BAT *b);
 
 #define BUN2 2
 #define BUN4 4
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
@@ -4188,15 +4188,11 @@ sql_storage_appendrow(BAT *bs, const cha
if (BUNappend(heap, &sz, false) != GDK_SUCCEED)
goto bailout1;
 
-   MT_rwlock_rdlock(&bs->thashlock);
-   /* one lock, two values: hash size, and
-* whether we (may) have a hash */
-   sz = hashinfo(bs->thash, bs->batCacheid);
-   bitval = bs->thash != NULL;
-   MT_rwlock_rdunlock(&bs->thashlock);
+   sz = (lng) HASHsize(bs);
if (BUNappend(indices, &sz, false) != GDK_SUCCEED)
goto bailout1;
 
+   bitval = sz > 0;
if (BUNappend(phash, &bitval, false) != GDK_SUCCEED)
goto bailout1;
 
___
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org


MonetDB: default - Merge with Aug2024 branch.

2024-10-03 Thread Sjoerd Mullender via checkin-list
Changeset: 827ec6d8453c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/827ec6d8453c
Modified Files:
sql/backends/monet5/sql.c
testing/tlstester.py
Branch: default
Log Message:

Merge with Aug2024 branch.


diffs (truncated from 364 to 300 lines):

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
@@ -4137,6 +4137,102 @@ SQLoptimizersUpdate(Client cntxt, MalBlk
throw(SQL, "updateOptimizer", SQLSTATE(0A000) PROGRAM_NYI);
 }
 
+static str
+sql_storage_appendrow(BAT *bs, const char *sname, const char *tname, const 
char *cname,
+ int access, const char *tpname,
+ BAT *sch, BAT *tab, BAT *col, BAT 
*type, BAT *loc,
+ BAT *cnt, BAT *atom, BAT *size, BAT 
*heap, BAT *indices,
+ BAT *phash, BAT *sort, BAT *imprints, 
BAT *mode,
+ BAT *revsort, BAT *key, BAT *oidx)
+{
+   BATiter bsi = bat_iterator(bs);
+   lng sz;
+   int w;
+   bit bitval;
+
+   if (BUNappend(sch, sname, false) != GDK_SUCCEED ||
+   BUNappend(tab, tname, false) != GDK_SUCCEED ||
+   BUNappend(col, cname, false) != GDK_SUCCEED)
+   goto bailout1;
+   if (access == TABLE_WRITABLE) {
+   if (BUNappend(mode, "writable", false) != GDK_SUCCEED)
+   goto bailout1;
+   } else if (access == TABLE_APPENDONLY) {
+   if (BUNappend(mode, "appendonly", false) != GDK_SUCCEED)
+   goto bailout1;
+   } else if (access == TABLE_READONLY) {
+   if (BUNappend(mode, "readonly", false) != GDK_SUCCEED)
+   goto bailout1;
+   } else {
+   if (BUNappend(mode, str_nil, false) != GDK_SUCCEED)
+   goto bailout1;
+   }
+   if (BUNappend(type, tpname, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   sz = bsi.count;
+   if (BUNappend(cnt, &sz, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   if (BUNappend(loc, BBP_physical(bs->batCacheid), false) != GDK_SUCCEED)
+   goto bailout1;
+   w = bsi.width;
+   if (BUNappend(atom, &w, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   sz = (lng) bsi.hfree;
+   if (BUNappend(size, &sz, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   sz = bsi.vhfree;
+   if (BUNappend(heap, &sz, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   MT_rwlock_rdlock(&bs->thashlock);
+   /* one lock, two values: hash size, and
+* whether we (may) have a hash */
+   sz = hashinfo(bs->thash, bs->batCacheid);
+   bitval = bs->thash != NULL;
+   MT_rwlock_rdunlock(&bs->thashlock);
+   if (BUNappend(indices, &sz, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   if (BUNappend(phash, &bitval, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   sz = 0;
+   if (BUNappend(imprints, &sz, false) != GDK_SUCCEED)
+   goto bailout1;
+   bitval = bsi.sorted;
+   if (!bitval && bsi.nosorted == 0)
+   bitval = bit_nil;
+   if (BUNappend(sort, &bitval, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   bitval = bsi.revsorted;
+   if (!bitval && bsi.norevsorted == 0)
+   bitval = bit_nil;
+   if (BUNappend(revsort, &bitval, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   bitval = bsi.key;
+   if (!bitval && bsi.nokey[0] == 0 && bsi.nokey[1] == 0)
+   bitval = bit_nil;
+   if (BUNappend(key, &bitval, false) != GDK_SUCCEED)
+   goto bailout1;
+
+   MT_lock_set(&bs->batIdxLock);
+   sz = bs->torderidx && bs->torderidx != (Heap *) 1 ? bs->torderidx->free 
: 0;
+   MT_lock_unset(&bs->batIdxLock);
+   if (BUNappend(oidx, &sz, false) != GDK_SUCCEED)
+   goto bailout1;
+   bat_iterator_end(&bsi);
+   return MAL_SUCCEED;
+  bailout1:
+   bat_iterator_end(&bsi);
+   throw(SQL, "sql.storage", GDK_EXCEPTION);
+}
+
 /*
  * Inspection of the actual storage footprint is a recurring question of users.
  * This is modelled as a generic SQL table producing function.
@@ -4148,13 +4244,10 @@ str
 sql_storage(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
BAT *sch, *tab, *col, *type, *loc, *cnt, *atom, *size, *heap, *indices, 
*phash, *sort, *imprints, *mode, *revsort, *key, *oidx, *bs = NULL;
-   BATiter bsi = bat_iterator(NULL);
mvc *m = NULL;
str msg = MAL_SUCCEED;
sql_trans *tr;
node *ncol;
-   int w;
-   bit bitval;
bat *rsch = getArgReference_bat(stk, pci, 0);
bat *rtab = getArgReference_bat(stk, pci, 1);
bat *rcol = getArgReference_bat(stk, pci, 2);
@@ -4244,7 +4337,6 @@ sql

MonetDB: default - Approve upgrade code for non-hge.

2024-10-03 Thread Sjoerd Mullender via checkin-list
Changeset: 4f9711610659 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4f9711610659
Modified Files:
clients/Tests/MAL-signatures.test
sql/test/emptydb/Tests/check.stable.out
Branch: default
Log Message:

Approve upgrade code for non-hge.


diffs (34 lines):

diff --git a/clients/Tests/MAL-signatures.test 
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -38274,6 +38274,11 @@ unsafe pattern sql.transaction_rollback(
 SQLtransaction_rollback;
 A transaction statement (type can be commit,release,rollback or start)
 sql
+unclosed_result_sets
+pattern sql.unclosed_result_sets() (X_0:bat[:oid], X_1:bat[:int])
+sql_unclosed_result_sets;
+return query_id/res_id of unclosed result sets
+sql
 unionfunc
 pattern sql.unionfunc(X_0:str, X_1:str, X_2:any...):any...
 SQLunionfunc;
diff --git a/sql/test/emptydb/Tests/check.stable.out 
b/sql/test/emptydb/Tests/check.stable.out
--- a/sql/test/emptydb/Tests/check.stable.out
+++ b/sql/test/emptydb/Tests/check.stable.out
@@ -2805,6 +2805,7 @@ select 'null in fkeys.delete_action', de
 [ "sys.functions", "sys",  "tracelog", "SYSTEM",   "create 
function sys.tracelog() returns table (ticks bigint, stmt string, event string) 
external name sql.dump_trace;", "sql",  "MAL",  "Function returning a table",   
false,  false,  false,  true,   NULL,   "ticks","bigint",   63, 
0,  "out",  "stmt", "varchar",  0,  0,  "out",  "event",
"varchar",  0,  0,  "out",  NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL
]
 [ "sys.functions", "sys",  "truncate", "SYSTEM",   "stringleft",   
"str",  "Internal C",   "Scalar function",  false,  false,  false,  false,  
NULL,   "res_0","varchar",  0,  0,  "out",  "arg_1",
"varchar",  0,  0,  "in",   "arg_2","int",  31, 0,  
"in",   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL]
 [ "sys.functions", "sys",  "ucase","SYSTEM",   "toUpper",  
"str",  "Internal C",   "Scalar function",  false,  false,  false,  false,  
NULL,   "res_0","varchar",  0,  0,  "out",  "arg_1",
"varchar",  0,  0,  "in",   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL]
+[ "sys.functions", "sys",  "unclosed_result_sets", "SYSTEM",   "create 
function sys.unclosed_result_sets() returns table(\"query_id\" oid, \"res_id\" 
int) external name sql.unclosed_result_sets;",   "sql",  "MAL",  "Function 
returning a table",   false,  false,  false,  true,   NULL,   "query_id", 
"oid",  63, 0,  "out",  "res_id",   "int",  31, 0,  "out",  
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   
NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL
]
 [ "sys.functions", "sys",  "upper","SYSTEM",   "toUpper",  
"str",  "Internal C",   "Scalar function",  false,  false,  false,  false,  
NULL,   "res_0","varchar",  0,  0,  "out",  "arg_1