MonetDB: distinct_from - Implemented "nil_matches" for thetajoin...

2024-03-22 Thread Sjoerd Mullender via checkin-list
Changeset: 988026412964 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/988026412964
Modified Files:
gdk/gdk_join.c
sql/test/2024/Tests/distinct_from.test
sql/test/2024/Tests/groupby_primary_key_project_unique_key.test
Branch: distinct_from
Log Message:

Implemented "nil_matches" for thetajoin when condition is not "=".


diffs (224 lines):

diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3697,7 +3697,8 @@ joincost(BAT *r, BUN lcount, struct cand
 #define MASK_NE(MASK_LT | MASK_GT)
 
 static gdk_return
-thetajoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, int opcode, 
BUN estimate, const char *reason, lng t0)
+thetajoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, int opcode,
+ BUN estimate, bool nil_matches, const char *reason, lng t0)
 {
struct canditer lci, rci;
const char *lvals, *rvals;
@@ -3737,23 +3738,29 @@ thetajoin(BAT **r1p, BAT **r2p, BAT *l, 
 
if (BATtvoid(l)) {
if (!BATtdensebi(&li)) {
-   /* trivial: nils don't match anything */
-   bat_iterator_end(&li);
-   bat_iterator_end(&ri);
-   return nomatch(r1p, r2p, NULL, l, r, &lci,
-  0, false, false, __func__, t0);
+   if (!nil_matches) {
+   /* trivial: nils don't match anything */
+   bat_iterator_end(&li);
+   bat_iterator_end(&ri);
+   return nomatch(r1p, r2p, NULL, l, r, &lci,
+  0, false, false, __func__, t0);
+   }
+   } else {
+   loff = (lng) l->tseqbase - (lng) l->hseqbase;
}
-   loff = (lng) l->tseqbase - (lng) l->hseqbase;
}
if (BATtvoid(r)) {
if (!BATtdensebi(&ri)) {
-   /* trivial: nils don't match anything */
-   bat_iterator_end(&li);
-   bat_iterator_end(&ri);
-   return nomatch(r1p, r2p, NULL, l, r, &lci,
-  0, false, false, __func__, t0);
+   if (!nil_matches) {
+   /* trivial: nils don't match anything */
+   bat_iterator_end(&li);
+   bat_iterator_end(&ri);
+   return nomatch(r1p, r2p, NULL, l, r, &lci,
+  0, false, false, __func__, t0);
+   }
+   } else {
+   roff = (lng) r->tseqbase - (lng) r->hseqbase;
}
-   roff = (lng) r->tseqbase - (lng) r->hseqbase;
}
 
BUN maxsize = joininitresults(r1p, r2p, NULL, lci.ncand, rci.ncand, 
false, false,
@@ -3782,18 +3789,18 @@ thetajoin(BAT **r1p, BAT **r2p, BAT *l, 
lo = canditer_next(&lci);
if (lvals)
vl = VALUE(l, lo - l->hseqbase);
-   else
+   else if (!BATtdensebi(&li))
lval = (oid) ((lng) lo + loff);
nr = 0;
-   if (cmp(vl, nil) != 0) {
+   if (nil_matches || cmp(vl, nil) != 0) {
canditer_reset(&rci);
TIMEOUT_LOOP(rci.ncand, qry_ctx) {
ro = canditer_next(&rci);
if (rvals)
vr = VALUE(r, ro - r->hseqbase);
-   else
+   else if (!BATtdensebi(&ri))
rval = (oid) ((lng) ro + roff);
-   if (cmp(vr, nil) == 0)
+   if (!nil_matches && cmp(vr, nil) == 0)
continue;
c = cmp(vl, vr);
if (!((opcode & MASK_LT && c < 0) ||
@@ -4437,7 +,7 @@ BATthetajoin(BAT **r1p, BAT **r2p, BAT *
if (joinparamcheck(l, r, NULL, sl, sr, __func__) != GDK_SUCCEED)
return GDK_FAIL;
 
-   return thetajoin(r1p, r2p, l, r, sl, sr, opcode, estimate,
+   return thetajoin(r1p, r2p, l, r, sl, sr, opcode, estimate, nil_matches,
 __func__, t0);
 }
 
@@ -5063,14 +5070,14 @@ BATrangejoin(BAT **r1p, BAT **r2p, BAT *
if (!anti)
return nomatch(r1p, r2p, NULL, l, rl, &lci, 0, false, 
false,
   __func__, t0);
-   return thetajoin(r1p, r2p, l, rh, sl, sr, MASK_GT, estimate,
+   return thetajoin(r1p, r2p, l, rh, sl, sr, MASK_GT, estimate, 
false,
 __func__, t0);
   

MonetDB: distinct_from - allow IS NOT DISTINCT FROM in a join co...

2024-03-22 Thread Yunus Koning via checkin-list
Changeset: a24a58b8ca90 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a24a58b8ca90
Modified Files:
sql/server/rel_select.c
sql/server/sql_parser.y
Branch: distinct_from
Log Message:

allow IS NOT DISTINCT FROM in a join condition


diffs (113 lines):

diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -1730,7 +1730,7 @@ rel_select_push_compare_exp_down(mvc *sq
 }
 
 static sql_rel *
-rel_compare_exp_(sql_query *query, sql_rel *rel, sql_exp *ls, sql_exp *rs, 
sql_exp *rs2, int type, int anti, int quantifier, int f, int symmetric)
+rel_compare_exp_(sql_query *query, sql_rel *rel, sql_exp *ls, sql_exp *rs, 
sql_exp *rs2, int type, int anti, int quantifier, int f, int symmetric, int 
is_semantics)
 {
mvc *sql = query->sql;
sql_exp *e = NULL;
@@ -1758,6 +1758,7 @@ rel_compare_exp_(sql_query *query, sql_r
if (rel_convert_types(sql, rel, rel, &ls, &rs, 1, 
type_equal_no_any) < 0)
return NULL;
e = exp_compare(sql->sa, ls, rs, type);
+   if (is_semantics) set_semantics(e);
} else {
assert(rs2);
if (rel_convert_types(sql, rel, rel, &ls, &rs, 1, 
type_equal_no_any) < 0)
@@ -1783,7 +1784,7 @@ rel_compare_exp_(sql_query *query, sql_r
 }
 
 static sql_rel *
-rel_compare_exp(sql_query *query, sql_rel *rel, sql_exp *ls, sql_exp *rs, char 
*compare_op, int reduce, int quantifier, int need_not, int f)
+rel_compare_exp(sql_query *query, sql_rel *rel, sql_exp *ls, sql_exp *rs, char 
*compare_op, int reduce, int quantifier, int need_not, int f, int is_semantics)
 {
mvc *sql = query->sql;
comp_type type = cmp_equal;
@@ -1816,11 +1817,11 @@ rel_compare_exp(sql_query *query, sql_re
}
type = compare_str2type(compare_op);
assert(type != cmp_filter);
-   return rel_compare_exp_(query, rel, ls, rs, NULL, type, need_not, 
quantifier, f, 0);
+   return rel_compare_exp_(query, rel, ls, rs, NULL, type, need_not, 
quantifier, f, 0, is_semantics);
 }
 
 static sql_rel *
-rel_compare(sql_query *query, sql_rel *rel, symbol *sc, symbol *lo, symbol 
*ro, char *compare_op, int f, exp_kind k, int quantifier)
+rel_compare(sql_query *query, sql_rel *rel, symbol *sc, symbol *lo, symbol 
*ro, char *compare_op, int f, exp_kind k, int quantifier, int is_semantics)
 {
mvc *sql = query->sql;
sql_exp *rs = NULL, *ls;
@@ -1884,7 +1885,7 @@ rel_compare(sql_query *query, sql_rel *r
return sql_error(sql, ERR_GROUPBY, SQLSTATE(42000) 
"SELECT: cannot use non GROUP BY column '%s.%s' in query results without an 
aggregate function", exp_relname(rs), exp_name(rs));
return sql_error(sql, ERR_GROUPBY, SQLSTATE(42000) "SELECT: 
cannot use non GROUP BY column in query results without an aggregate function");
}
-   return rel_compare_exp(query, rel, ls, rs, compare_op, k.reduce, 
quantifier, need_not, f);
+   return rel_compare_exp(query, rel, ls, rs, compare_op, k.reduce, 
quantifier, need_not, f, is_semantics);
 }
 
 static sql_exp*
@@ -2703,11 +2704,19 @@ rel_logical_exp(sql_query *query, sql_re
symbol *ro = n->next->next->data.sym;
char *compare_op = n->next->data.sval;
int quantifier = 0;
+   int is_semantics = 0;
 
if (n->next->next->next)
quantifier = n->next->next->next->data.i_val + 1;
-   assert(quantifier == 0 || quantifier == 1 || quantifier == 2);
-   return rel_compare(query, rel, sc, lo, ro, compare_op, f, ek, 
quantifier);
+   assert(quantifier == 0 || quantifier == 1 || quantifier == 2 || 
quantifier == 3 || quantifier == 4);
+
+   if (quantifier >= 3) {
+   quantifier = 0;
+   is_semantics = 1;
+   }
+
+   /* [NOT] DISTINCT FROM */
+   return rel_compare(query, rel, sc, lo, ro, compare_op, f, ek, 
quantifier, is_semantics);
}
/* Set Member ship */
case SQL_IN:
@@ -2777,7 +2786,7 @@ rel_logical_exp(sql_query *query, sql_re
(re2 = exp_check_type(sql, &super, rel, re2, type_equal)) 
== NULL)
return NULL;
 
-   return rel_compare_exp_(query, rel, le, re1, re2, 3, sc->token 
== SQL_NOT_BETWEEN ? 1 : 0, 0, f, symmetric);
+   return rel_compare_exp_(query, rel, le, re1, re2, 3, sc->token 
== SQL_NOT_BETWEEN ? 1 : 0, 0, f, symmetric, 0);
}
case SQL_IS_NULL:
case SQL_IS_NOT_NULL:
@@ -5457,7 +5466,7 @@ join_on_column_name(sql_query *query, sq
return sql_error(sql, ERR_AMBIGUOUS, 
SQLSTATE(42000) "NATURAL JOIN: common column name '%s' appears more than once 
in left table", rname);
 
found = 1;
-   if (!(rel = rel

MonetDB: ascii-flag - Merge with default branch.

2024-03-22 Thread Sjoerd Mullender via checkin-list
Changeset: f5d791884514 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f5d791884514
Removed Files:
monetdb5/modules/atoms/Tests/asciify.test
monetdb5/modules/atoms/Tests/endswith.test
monetdb5/modules/kernel/Tests/batstr_asciify.test
Modified Files:
monetdb5/modules/atoms/Tests/All
monetdb5/modules/kernel/Tests/All
sql/test/strings/Tests/All
sql/test/strings/Tests/asciify.test
sql/test/strings/Tests/batstr_asciify.test
sql/test/strings/Tests/endswith.test
Branch: ascii-flag
Log Message:

Merge with default branch.


diffs (truncated from 1030 to 300 lines):

diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1206,6 +1206,9 @@ BATrange(BATiter *bi, const void *tl, co
if (tl == NULL && th == NULL)
return range_contains; /* looking for everything */
 
+   if (VIEWtparent(bi->b))
+   pb = BATdescriptor(VIEWtparent(bi->b));
+
/* keep locked while we look at the property values */
MT_lock_set(&bi->b->theaplock);
if (bi->minpos != BUN_NONE)
@@ -1221,8 +1224,7 @@ BATrange(BATiter *bi, const void *tl, co
}
bool keep = false;  /* keep lock on parent bat? */
if (minprop == NULL || maxprop == NULL) {
-   if (VIEWtparent(bi->b) &&
-   (pb = BATdescriptor(VIEWtparent(bi->b))) != NULL) {
+   if (pb != NULL) {
MT_lock_set(&pb->theaplock);
if (minprop == NULL && (minprop = BATgetprop_nolock(pb, 
GDK_MIN_BOUND)) != NULL) {
keep = true;
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -280,15 +280,16 @@ dump_threads(void)
char buf[1024];
thread_lock();
for (struct mtthread *t = mtthreads; t; t = t->next) {
+   MT_Lock *lk = t->lockwait;
+   MT_Sema *sm = t->semawait;
+   MT_Cond *cn = t->condwait;
+   struct mtthread *jn = t->joinwait;
int pos = snprintf(buf, sizeof(buf),
-  "%s, tid %zu, waiting for %s, working on 
%.200s",
+  "%s, tid %zu, waiting for %s%s, working on 
%.200s",
   t->threadname,
   t->tid,
-  t->lockwait ? t->lockwait->name :
-  t->semawait ? t->semawait->name :
-  t->condwait ? t->condwait->name :
-  t->joinwait ? t->joinwait->threadname :
-  "nothing",
+  lk ? "lock " : sm ? "semaphore " : cn ? 
"condvar " : jn ? "thread " : "",
+  lk ? lk->name : sm ? sm->name : cn ? 
cn->name : jn ? jn->threadname : "nothing",
   ATOMIC_GET(&t->exited) ? "exiting" :
   t->working ? t->working : "nothing");
 #ifdef LOCK_OWNER
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -498,7 +498,6 @@ typedef struct MT_Lock {
 
 #define MT_lock_try(l) (pthread_mutex_trylock(&(l)->lock) == 0 && 
(_DBG_LOCK_LOCKER(l), true))
 
-#ifdef LOCK_STATS
 #define MT_lock_set(l) \
do {\
_DBG_LOCK_COUNT_0(l);   \
@@ -511,14 +510,6 @@ typedef struct MT_Lock {
_DBG_LOCK_LOCKER(l);\
_DBG_LOCK_COUNT_2(l);   \
} while (0)
-#else
-#define MT_lock_set(l) \
-   do {\
-   pthread_mutex_lock(&(l)->lock); \
-   _DBG_LOCK_LOCKER(l);\
-   } while (0)
-#endif
-
 #define MT_lock_unset(l)   \
do {\
_DBG_LOCK_UNLOCKER(l);  \
diff --git a/monetdb5/modules/atoms/Tests/All b/monetdb5/modules/atoms/Tests/All
--- a/monetdb5/modules/atoms/Tests/All
+++ b/monetdb5/modules/atoms/Tests/All
@@ -33,13 +33,3 @@ jsonrender
 
 uuid00
 strappend
-
-startswith
-endswith
-contains
-asciify
-startswith_join
-endswith_join
-contains_join
-
-ts_and_tstz_to_str_bug
diff --git a/monetdb5/modules/kernel/Tests/All 
b/monetdb5/modules/kernel/Tests/All
--- a/monetdb5/modules/kernel/Tests/All
+++ b/monetdb5/modules/kernel/Tests/All
@@ -3,8 +3,3 @@ TriBool
 batstr
 math
 select
-
-batstr_asciify
-batstr_startswith
-batstr_endswith
-batstr_contains
diff --git a/monetdb5/modules/mal/Tests/All b/monetdb5/modules/mal/Tests/All
--- a/monetdb5/modules/mal/Tests/All
+++ b/monetdb5/modules/mal/Tests/All
@@ -52,6 +52,3 @@ or