Changeset: b2b8dee457bb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b2b8dee457bb
Modified Files:
sql/backends/monet5/sql_subquery.c
sql/server/rel_unnest.c
Branch: sq2default
Log Message:
restored the all/nil implementation fixes
diffs (138 lines):
diff --git a/sql/backends/monet5/sql_subquery.c
b/sql/backends/monet5/sql_subquery.c
--- a/sql/backends/monet5/sql_subquery.c
+++ b/sql/backends/monet5/sql_subquery.c
@@ -138,14 +138,19 @@ SQLall(ptr ret, const bat *bid)
const void *n = ATOMnilptr(b->ttype);
BATiter bi = bat_iterator(b);
r = BUNlast(b);
- p = BUNtail(bi, 0);
ocmp = ATOMcompare(b->ttype);
- for (q = 1; q < r; q++) {
+ for (q = 0; q < r; q++) { /* find first non nil */
+ p = BUNtail(bi, q);
+ if (ocmp(n, p) != 0)
+ break;
+ }
+ for (; q < r; q++) {
const void *c = BUNtail(bi, q);
- if (ocmp(p, c) != 0) {
- if (ocmp(n, c) != 0)
- p = ATOMnilptr(b->ttype);
- break;
+ if (ocmp(p, c) != 0) { /* values != */
+ if (ocmp(n, c) != 0) { /* and not nil */
+ p = n;
+ break;
+ }
}
}
}
@@ -191,6 +196,7 @@ SQLall_grp(bat *ret, const bat *bid, con
ssize_t p, *pos = NULL;
int error = 0, has_nil = 0;
int (*ocmp) (const void *, const void *);
+ const void *nilp;
(void)no_nil;
if ((l = BATdescriptor(*bid)) == NULL) {
@@ -206,6 +212,7 @@ SQLall_grp(bat *ret, const bat *bid, con
throw(SQL, "sql.all =", SQLSTATE(HY005) "Cannot access column
descriptor");
}
li = bat_iterator(l);
+ nilp = ATOMnilptr(l->ttype);
ocmp = ATOMcompare(l->ttype);
if (BATcount(g) > 0) {
BUN q, o, s, offset = 0;
@@ -226,14 +233,17 @@ SQLall_grp(bat *ret, const bat *bid, con
oid id = *(oid*)BUNtail(gi, s);
if (pos[id] == -2)
continue;
- else if (pos[id] == -1)
- pos[id] = q;
- else {
+ else if (pos[id] == -1) {
+ const void *lv = BUNtail(li, q);
+ if (ocmp(nilp, lv) != 0) /* not nil */
+ pos[id] = q;
+ } else {
const void *lv = BUNtail(li, q);
const void *rv = BUNtail(li, pos[id]);
- if (ocmp(lv, rv) != 0)
- pos[id] = -2;
+ if (ocmp(lv, rv) != 0) /* values are different
*/
+ if (ocmp(nilp, rv) != 0) /* and not nil
*/
+ pos[id] = -2;
}
}
}
@@ -246,7 +256,6 @@ SQLall_grp(bat *ret, const bat *bid, con
throw(SQL, "sql.all =", SQLSTATE(HY001) MAL_MALLOC_FAIL);
}
- const void *nilp = ATOMnilptr(l->ttype);
for (p = 0; p < (ssize_t)BATcount(e) && !error; p++) {
const void *v = nilp;
if (pos[p] >= 0) {
@@ -285,7 +294,7 @@ SQLnil(bit *ret, const bat *bid)
*ret = FALSE;
if (BATcount(b) == 0)
*ret = bit_nil;
- else {
+ if (BATcount(b) > 0) {
BUN q, o;
int (*ocmp) (const void *, const void *);
BATiter bi = bat_iterator(b);
@@ -311,7 +320,6 @@ SQLnil_grp(bat *ret, const bat *bid, con
BAT *l, *g, *e, *res;
bit F = FALSE;
BUN offset = 0;
- bit has_nil = 0;
(void)no_nil;
if ((l = BATdescriptor(*bid)) == NULL) {
@@ -352,15 +360,14 @@ SQLnil_grp(bat *ret, const bat *bid, con
if (ret[id] != TRUE) {
if (ocmp(lv, nilp) == 0) {
- ret[id] = bit_nil;
- has_nil = 1;
+ ret[id] = TRUE;
}
}
}
}
res->hseqbase = g->hseqbase;
- res->tnil = has_nil != 0;
- res->tnonil = has_nil == 0;
+ res->tnil = 0;
+ res->tnonil = 1;
res->tsorted = res->trevsorted = 0;
res->tkey = 0;
BBPunfix(l->batCacheid);
@@ -389,10 +396,12 @@ SQLall_cmp(bit *ret, const bit *cmp, con
*ret = TRUE;
if (*nr == bit_nil) /* empty -> TRUE */
*ret = TRUE;
- else if (*cmp == FALSE)
+ else if (*cmp == FALSE || (*cmp == bit_nil && !*nl && !*nr))
*ret = FALSE;
else if (*nl == TRUE || *nr == TRUE)
*ret = bit_nil;
+ else
+ *ret = *cmp;
return MAL_SUCCEED;
}
diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c
--- a/sql/server/rel_unnest.c
+++ b/sql/server/rel_unnest.c
@@ -1830,6 +1830,8 @@ rewrite_anyequal(mvc *sql, sql_rel *rel,
re = exp_label(sql->sa, re,
++sql->label); /* unique name */
list_hash_clear(rsq->exps);
re = exp_ref(sql->sa, re);
+ } else if (has_label(re)) {
+ re = exp_ref(sql->sa, re);
}
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list