Changeset: 0d3d886c54c3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0d3d886c54c3
Modified Files:
sql/server/rel_rel.c
Branch: iso
Log Message:
Merged with Jul2021
diffs (truncated from 4215 to 300 lines):
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -329,6 +329,36 @@ log_read_id(logger *lg, log_id *id)
#endif
static log_return
+string_reader(logger *lg, BAT *b, lng nr)
+{
+ int sz = 0;
+ log_return res = LOG_OK;
+
+ if (mnstr_readInt(lg->input_log, &sz) != 1)
+ return LOG_EOF;
+ char *buf = GDKmalloc(sz);
+
+ if (!buf || mnstr_read(lg->input_log, buf, sz, 1) != 1) {
+ GDKfree(buf);
+ return LOG_EOF;
+ }
+ /* handle strings */
+ if (b) {
+ char *t = buf;
+ for(int i=0; i<nr && res == LOG_OK; i++) {
+ if (BUNappend(b, t, true) != GDK_SUCCEED)
+ res = LOG_ERR;
+ /* find next */
+ while(*t)
+ t++;
+ t++;
+ }
+ }
+ GDKfree(buf);
+ return res;
+}
+
+static log_return
log_read_updates(logger *lg, trans *tr, logformat *l, log_id id, lng offset)
{
log_return res = LOG_OK;
@@ -427,6 +457,9 @@ log_read_updates(logger *lg, trans *tr,
if (r && BUNappendmulti(r, t,
cnt, true) != GDK_SUCCEED)
res = LOG_ERR;
}
+ } else if (tpe == TYPE_str) {
+ /* efficient string */
+ res = string_reader(lg, r, nr);
} else {
for (; res == LOG_OK && nr > 0; nr--) {
size_t tlen = lg->bufsize;
@@ -487,6 +520,9 @@ log_read_updates(logger *lg, trans *tr,
break;
}
}
+ } else if (tpe == TYPE_str) {
+ /* efficient string */
+ res = string_reader(lg, r, nr);
} else {
for (; res == LOG_OK && nr > 0; nr--) {
size_t tlen = lg->bufsize;
@@ -2297,6 +2333,33 @@ log_constant(logger *lg, int type, ptr v
}
static gdk_return
+string_writer(logger *lg, BAT *b, lng offset, lng nr)
+{
+ int sz = 0;
+ BUN end = (BUN)(offset + nr);
+
+ BATiter bi = bat_iterator(b);
+ for(BUN p = (BUN)offset; p < end; p++) {
+ char *s = BUNtail(bi, p);
+ sz += strlen(s)+1; /* we need a seperator */
+ }
+ char *buf = GDKmalloc(sz), *dst = buf;
+ if (buf) {
+ for(BUN p = (BUN)offset; p < end; p++) {
+ char *s = BUNtail(bi, p);
+ strcpy(dst, s);
+ dst += strlen(s)+1;
+ }
+ }
+ gdk_return res = GDK_FAIL;
+ if (buf && mnstr_writeInt(lg->output_log, (int) sz) &&
mnstr_write(lg->output_log, buf, sz, 1) == 1)
+ res = GDK_SUCCEED;
+ GDKfree(buf);
+ bat_iterator_end(&bi);
+ return res;
+}
+
+static gdk_return
internal_log_bat(logger *lg, BAT *b, log_id id, lng offset, lng cnt, int
sliced)
{
bte tpe = find_type(lg, b->ttype);
@@ -2323,7 +2386,6 @@ internal_log_bat(logger *lg, BAT *b, log
return GDK_SUCCEED;
}
- BATiter bi = bat_iterator(b);
gdk_return (*wt) (const void *, stream *, size_t) =
BATatoms[b->ttype].atomWrite;
if (is_row)
@@ -2340,6 +2402,7 @@ internal_log_bat(logger *lg, BAT *b, log
if (sliced)
offset = 0;
if (b->ttype == TYPE_msk) {
+ BATiter bi = bat_iterator(b);
if (offset % 32 == 0) {
if (!mnstr_writeIntArray(lg->output_log, (int *) ((char
*) bi.base + offset / 32), (size_t) ((nr + 31) / 32)))
ok = GDK_FAIL;
@@ -2354,24 +2417,31 @@ internal_log_bat(logger *lg, BAT *b, log
}
}
}
+ bat_iterator_end(&bi);
} else if (b->ttype < TYPE_str && !isVIEW(b)) {
+ BATiter bi = bat_iterator(b);
const void *t = BUNtail(bi, (BUN)offset);
ok = wt(t, lg->output_log, (size_t)nr);
+ bat_iterator_end(&bi);
+ } else if (b->ttype == TYPE_str) {
+ /* efficient string writes */
+ ok = string_writer(lg, b, offset, nr);
} else {
+ BATiter bi = bat_iterator(b);
BUN end = (BUN)(offset+nr);
for (p = (BUN)offset; p < end && ok == GDK_SUCCEED; p++) {
const void *t = BUNtail(bi, p);
ok = wt(t, lg->output_log, 1);
}
+ bat_iterator_end(&bi);
}
if (lg->debug & 1)
fprintf(stderr, "#Logged %d " LLFMT " inserts\n", id, nr);
bailout:
- bat_iterator_end(&bi);
if (ok != GDK_SUCCEED) {
const char *err = mnstr_peek_error(lg->output_log);
TRC_CRITICAL(GDK, "write failed%s%s\n", err ? ": " : "", err ?
err : "");
@@ -2498,6 +2568,9 @@ log_delta(logger *lg, BAT *uid, BAT *uva
if (uval->ttype == TYPE_msk) {
if (!mnstr_writeIntArray(lg->output_log, vi.base,
(BUNlast(uval) + 31) / 32))
ok = GDK_FAIL;
+ } else if (uval->ttype == TYPE_str) {
+ /* efficient string writes */
+ ok = string_writer(lg, uval, 0, nr);
} else {
for (p = 0; p < BUNlast(uid) && ok == GDK_SUCCEED; p++) {
const void *val = BUNtail(vi, p);
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -1248,7 +1248,7 @@ BATgroupstr_group_concat(BAT *b, BAT *g,
} \
} else { /* sep case */ \
assert(sep != NULL); \
- sl = BUNtvar(bis, m); \
+ sl = BUNtvar(sepi, m); \
\
if (!strNil(sb)) { \
next_group_length += strlen(sb);
\
@@ -1300,7 +1300,7 @@ BATgroupstr_group_concat(BAT *b, BAT *g,
empty = false; \
} else { /* sep case */ \
assert(sep != NULL); \
- sl = BUNtvar(bis, m); \
+ sl = BUNtvar(sepi, m); \
\
if (strNil(sb)) \
continue; \
@@ -1343,7 +1343,7 @@ BATgroupstr_group_concat(BAT *b, BAT *g,
nsep = (str) separator;
\
} else { /* sep case */ \
assert(sep != NULL);
\
- nsep = BUNtvar(bis, j);
\
+ nsep = BUNtvar(sepi,
j); \
} \
if (!strNil(nsep)) \
slice_length +=
strlen(nsep); \
@@ -1414,28 +1414,34 @@ gdk_return
GDKanalytical_str_group_concat(BAT *r, BAT *p, BAT *o, BAT *b, BAT *sep, BAT
*s, BAT *e, const char *restrict separator, int frame_type)
{
bool has_nils = false, empty;
- oid i = 0, j = 0, k = 0, cnt = BATcount(b), *restrict start = s ?
(oid*)Tloc(s, 0) : NULL, *restrict end = e ? (oid*)Tloc(e, 0) : NULL;
- bit *np = p ? Tloc(p, 0) : NULL, *op = o ? Tloc(o, 0) : NULL;
- BATiter bi, bis = (BATiter) {0};
+ BATiter pi = bat_iterator(p);
+ BATiter oi = bat_iterator(o);
+ BATiter bi = bat_iterator(b);
+ BATiter sepi = bat_iterator(sep);
+ BATiter si = bat_iterator(s);
+ BATiter ei = bat_iterator(e);
+ oid i = 0, j = 0, k = 0, cnt = BATcount(b), *restrict start = si.base,
*restrict end = ei.base;
+ bit *np = pi.base, *op = oi.base;
str sb, sl, single_str = NULL, next_single_str;
size_t separator_length = 0, next_group_length, max_group_length = 0,
next_length, offset;
assert((sep && !separator && BATcount(b) == BATcount(sep)) || (!sep &&
separator));
if (b->ttype != TYPE_str || r->ttype != TYPE_str || (sep && sep->ttype
!= TYPE_str)) {
GDKerror("only string type is supported\n");
+ bat_iterator_end(&pi);
+ bat_iterator_end(&oi);
+ bat_iterator_end(&bi);
+ bat_iterator_end(&sepi);
+ bat_iterator_end(&si);
+ bat_iterator_end(&ei);
return GDK_FAIL;
}
if (sep && BATcount(sep) == 1) { /* Only one element in sep */
- bi = bat_iterator(sep);
- separator = BUNtvar(bi, 0);
- bat_iterator_end(&bi);
+ separator = BUNtvar(sepi, 0);
sep = NULL;
}
- bi = bat_iterator(b);
- if (sep)
- bis = bat_iterator(sep);
- else
+ if (sep == NULL)
separator_length = strlen(separator);
if (cnt > 0) {
@@ -1457,24 +1463,33 @@ GDKanalytical_str_group_concat(BAT *r, B
}
}
+ bat_iterator_end(&pi);
+ bat_iterator_end(&oi);
bat_iterator_end(&bi);
- if (sep)
- bat_iterator_end(&bis);
+ bat_iterator_end(&sepi);
+ bat_iterator_end(&si);
+ bat_iterator_end(&ei);
GDKfree(single_str);
BATsetcount(r, cnt);
r->tnonil = !has_nils;
r->tnil = has_nils;
return GDK_SUCCEED;
allocation_error:
+ bat_iterator_end(&pi);
+ bat_iterator_end(&oi);
bat_iterator_end(&bi);
- if (sep)
- bat_iterator_end(&bis);
+ bat_iterator_end(&sepi);
+ bat_iterator_end(&si);
+ bat_iterator_end(&ei);
GDKfree(single_str);
return GDK_FAIL;
notimplemented:
+ bat_iterator_end(&pi);
+ bat_iterator_end(&oi);
bat_iterator_end(&bi);
- if (sep)
- bat_iterator_end(&bis);
+ bat_iterator_end(&sepi);
+ bat_iterator_end(&si);
+ bat_iterator_end(&ei);
GDKerror("str_group_concat not yet implemented for current row until
unbounded case\n");
return GDK_FAIL;
}
diff --git a/gdk/gdk_subquery.c b/gdk/gdk_subquery.c
--- a/gdk/gdk_subquery.c
+++ b/gdk/gdk_subquery.c
@@ -14,7 +14,7 @@
#define SQLall_grp_imp(TYPE) \
do { \
- const TYPE *restrict vals = (const TYPE *) Tloc(l, 0); \
+ const TYPE *restrict vals = (const TYPE *) li.base; \
TYPE *restrict rp = (TYPE *) Tloc(res, 0); \
while (ncand > 0) { \
ncand--; \
@@ -75,6 +75,8 @@ BATall_grp(BAT *l, BAT *g, BAT *e, BAT *
if ((res = BATconstant(ngrp == 0 ? 0 : min, l->ttype, nilp,
ngrp, TRANSIENT)) == NULL)
goto alloc_fail;
} else {
+ BATiter li;
+
if ((res = COLnew(min, l->ttype, ngrp, TRANSIENT)) == NULL)
goto alloc_fail;
if ((oids = GDKmalloc(ngrp * sizeof(oid))) == NULL)
@@ -88,6 +90,7 @@ BATall_grp(BAT *l, BAT *g, BAT *e, BAT *
else
gids = (const oid *) Tloc(g, 0);
+ li = bat_iterator(l);
switch (ATOMbasetype(l->ttype)) {
case TYPE_bte:
SQLall_grp_imp(bte);
@@ -115,7 +118,6 @@ BATall_grp(BAT *l, BAT *g, BAT *e, BAT *
default: {
int (*ocmp) (const void *, const void *) =
ATOMcompare(l->ttype);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list