Changeset: 28506f7448e2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/28506f7448e2 Modified Files: sql/backends/monet5/sql.c Branch: histograms Log Message:
Merged with default diffs (truncated from 473 to 300 lines): diff --git a/gdk/ChangeLog.Jan2022 b/gdk/ChangeLog.Jan2022 --- a/gdk/ChangeLog.Jan2022 +++ b/gdk/ChangeLog.Jan2022 @@ -1,3 +1,7 @@ # ChangeLog file for GDK # This file is updated with Maddlog +* Tue Mar 29 2022 Sjoerd Mullender <[email protected]> +- Improved speed of projection (BATproject) on varsized bats by sharing + the data heap (vheap). + diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c --- a/gdk/gdk_atoms.c +++ b/gdk/gdk_atoms.c @@ -426,10 +426,45 @@ TYPE##ToStr(char **dst, size_t *len, con return snprintf(*dst, *len, FMT, FMTCAST *src); \ } -#define num10(x) GDKisdigit(x) +static const bool xdigit[256] = { + false,false,false,false,false,false,false,false, /* NUL-BEL */ + false,false,false,false,false,false,false,false, /* BS-SI */ + false,false,false,false,false,false,false,false, /* DLE-ETB */ + false,false,false,false,false,false,false,false, /* CAN-US */ + false,false,false,false,false,false,false,false, /* SPACE-'\'' */ + false,false,false,false,false,false,false,false, /* '('-'/' */ + true, true, true, true, true, true, true, true, /* '0'-'7' */ + true, true, false,false,false,false,false,false, /* '8'-'?' */ + false,true, true, true, true, true, true, false, /* '@'-'G' */ + false,false,false,false,false,false,false,false, /* 'H'-'O' */ + false,false,false,false,false,false,false,false, /* 'P'-'W' */ + false,false,false,false,false,false,false,false, /* 'X'-'_' */ + false,true, true, true, true, true, true, false, /* '`'-'g' */ + false,false,false,false,false,false,false,false, /* 'h'-'o' */ + false,false,false,false,false,false,false,false, /* 'p'-'w' */ + false,false,false,false,false,false,false,false, /* 'x'-DEL */ + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, + false,false,false,false,false,false,false,false, +}; + +#define num10(x) ((x) >= '0' && (x) <= '9') #define base10(x) ((x) - '0') -#define num16(x) isxdigit((unsigned char) (x)) +#define num16(x) xdigit[(unsigned char) (x)] #define base16(x) (((x) >= 'a' && (x) <= 'f') ? ((x) - 'a' + 10) : ((x) >= 'A' && (x) <= 'F') ? ((x) - 'A' + 10) : (x) - '0') #define mult16(x) ((x) << 4) @@ -1210,7 +1245,7 @@ OIDfromStr(const char *src, size_t *len, if (external && strncmp(p, "nil", 3) == 0) return (ssize_t) (p - src) + 3; - if (GDKisdigit(*p)) { + if (*p >= '0' && *p <= '9') { #if SIZEOF_OID == SIZEOF_INT pos = intFromStr(p, &l, &uip, external); #else @@ -1220,7 +1255,7 @@ OIDfromStr(const char *src, size_t *len, return pos; if (p[pos] == '@') { pos++; - while (GDKisdigit(p[pos])) + while (p[pos] >= '0' && p[pos] <= '9') pos++; } if (ui >= 0) { @@ -1291,7 +1326,7 @@ UUIDfromString(const char *svalue, size_ if (*s == '-') s++; } - if (isdigit((unsigned char) *s)) + if (*s >= '0' && *s <= '9') u.u[i] = *s - '0'; else if ('a' <= *s && *s <= 'f') u.u[i] = *s - 'a' + 10; @@ -1302,7 +1337,7 @@ UUIDfromString(const char *svalue, size_ s++; j++; u.u[i] <<= 4; - if (isdigit((unsigned char) *s)) + if (*s >= '0' && *s <= '9') u.u[i] |= *s - '0'; else if ('a' <= *s && *s <= 'f') u.u[i] |= *s - 'a' + 10; @@ -1562,10 +1597,15 @@ BLOBfromstr(const char *instr, size_t *l /* count hexits and check for hexits/space */ for (i = nitems = 0; instr[i]; i++) { - if (isxdigit((unsigned char) instr[i])) + if (xdigit[(unsigned char) instr[i]]) nitems++; - else if (!isspace((unsigned char) instr[i])) { - GDKerror("Illegal char (not a hexadecimal digit) in blob\n"); + else if (instr[i] != ' ' && + instr[i] != '\n' && + instr[i] != '\t' && + instr[i] != '\r' && + instr[i] != '\f' && + instr[i] != '\v') { + GDKerror("Illegal char in blob\n"); return -1; } } @@ -1593,7 +1633,7 @@ BLOBfromstr(const char *instr, size_t *l char res = 0; for (;;) { - if (isdigit((unsigned char) *s)) { + if (*s >= '0' && *s <= '9') { res = *s - '0'; } else if (*s >= 'A' && *s <= 'F') { res = 10 + *s - 'A'; @@ -1609,7 +1649,7 @@ BLOBfromstr(const char *instr, size_t *l s++; res <<= 4; for (;;) { - if (isdigit((unsigned char) *s)) { + if (*s >= '0' && *s <= '9') { res += *s - '0'; } else if (*s >= 'A' && *s <= 'F') { res += 10 + *s - 'A'; 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 @@ -1209,15 +1209,16 @@ str mvc_bind_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int upd = (pci->argc == 7 || pci->argc == 9); - BAT *b = NULL, *bn; + BAT *b = NULL; bat *bid = getArgReference_bat(stk, pci, 0); - int coltype = getBatType(getArgType(mb, pci, 0)); mvc *m = NULL; str msg; - const char *sname = *getArgReference_str(stk, pci, 2 + upd); - const char *tname = *getArgReference_str(stk, pci, 3 + upd); - const char *cname = *getArgReference_str(stk, pci, 4 + upd); - int access = *getArgReference_int(stk, pci, 5 + upd); + const char *sname = *getArgReference_str(stk, pci, 2 + upd); + const char *tname = *getArgReference_str(stk, pci, 3 + upd); + const char *cname = *getArgReference_str(stk, pci, 4 + upd); + const int access = *getArgReference_int(stk, pci, 5 + upd); + + const bool partitioned_access = pci->argc == (8 + upd) && getArgType(mb, pci, 6 + upd) == TYPE_int; /* This doesn't work with quick access for now... */ assert(access != QUICK); @@ -1232,103 +1233,71 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb throw(SQL, "sql.bind", SQLSTATE(42000) "%s '%s' is not persistent", TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name); sql_column *c = mvc_bind_column(m, t, cname); - b = mvc_bind(m, sname, tname, cname, access); - if (b && b->ttype && b->ttype != coltype) { - BBPunfix(b->batCacheid); - throw(SQL,"sql.bind",SQLSTATE(42000) "Column type mismatch %s.%s.%s",sname,tname,cname); - } - if (b) { - if (pci->argc == (8 + upd) && getArgType(mb, pci, 6 + upd) == TYPE_int) { - BUN cnt = store->storage_api.count_col(m->session->tr, c, 0), psz; - /* partitioned access */ - int part_nr = *getArgReference_int(stk, pci, 6 + upd); - int nr_parts = *getArgReference_int(stk, pci, 7 + upd); - - if (access == 0) { - BUN l, h; - psz = cnt ? (cnt / nr_parts) : 0; - l = part_nr * psz; - if (l > cnt) - l = cnt; - h = (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz); - if (h > cnt) - h = cnt; - bn = BATslice(b, l, h); - if(bn == NULL) { - BBPunfix(b->batCacheid); - throw(SQL, "sql.bind", GDK_EXCEPTION); - } - BAThseqbase(bn, l); - } else { - /* BAT b holds the UPD_ID bat */ - oid l, h; - cnt = store->storage_api.count_col(m->session->tr, c, 0); - psz = cnt ? (cnt / nr_parts) : 0; - l = part_nr * psz; - if (l > cnt) - l = cnt; - h = (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz); - if (h > cnt) - h = cnt; - h--; - bn = BATselect(b, NULL, &l, &h, true, true, false); - if(bn == NULL) { - BBPunfix(b->batCacheid); - throw(SQL, "sql.bind", GDK_EXCEPTION); - } + + if (partitioned_access) { + /* partitioned access */ + int part_nr = *getArgReference_int(stk, pci, 6 + upd); + int nr_parts = *getArgReference_int(stk, pci, 7 + upd); + BUN cnt = store->storage_api.count_col(m->session->tr, c, 0), psz; + oid l, h; + psz = cnt ? (cnt / nr_parts) : 0; + l = part_nr * psz; + if (l > cnt) + l = cnt; + h = (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz); + if (h > cnt) + h = cnt; + + if (upd) { + sql_updates* updates = store->storage_api.bind_updates(m->session->tr, c); + + if (!updates) + throw(SQL,"sql.bind",SQLSTATE(HY005) "Cannot access the update columns"); + BAT *ui = updates->ui; + BAT *uv = updates->uv; + GDKfree(updates); + + h--; + BAT* bn = BATselect(ui, NULL, &l, &h, true, true, false); + if(bn == NULL) { + BBPunfix(ui->batCacheid); + BBPunfix(uv->batCacheid); + throw(SQL, "sql.bind", GDK_EXCEPTION); } - BBPunfix(b->batCacheid); - b = bn; - } else if (upd) { - BAT *uv = mvc_bind(m, sname, tname, cname, RD_UPD_VAL); + bat *uvl = getArgReference_bat(stk, pci, 1); - if (uv == NULL) { - BBPunfix(b->batCacheid); - throw(SQL,"sql.bind",SQLSTATE(HY005) "Cannot access the update column %s.%s.%s", - sname,tname,cname); - } - *bid = b->batCacheid; - BBPkeepref(b); - *uvl = uv->batCacheid; - BBPkeepref(uv); - return MAL_SUCCEED; - } - if (upd) { - bat *uvl = getArgReference_bat(stk, pci, 1); - - if (BATcount(b)) { - BAT *uv = mvc_bind(m, sname, tname, cname, RD_UPD_VAL); - BAT *ui = mvc_bind(m, sname, tname, cname, RD_UPD_ID); + if (BATcount(bn)) { BAT *id; BAT *vl; if (ui == NULL || uv == NULL) { bat_destroy(uv); bat_destroy(ui); - BBPunfix(b->batCacheid); + BBPunfix(bn->batCacheid); throw(SQL,"sql.bind",SQLSTATE(HY005) "Cannot access the insert column %s.%s.%s", sname, tname, cname); } - id = BATproject(b, ui); - vl = BATproject(b, uv); + assert(uv->batCount == ui->batCount); + id = BATproject(bn, ui); + vl = BATproject(bn, uv); bat_destroy(ui); bat_destroy(uv); if (id == NULL || vl == NULL) { - BBPunfix(b->batCacheid); + BBPunfix(bn->batCacheid); bat_destroy(id); bat_destroy(vl); throw(SQL, "sql.bind", GDK_EXCEPTION); } if ( BATcount(id) != BATcount(vl)){ - BBPunfix(b->batCacheid); + BBPunfix(bn->batCacheid); bat_destroy(id); bat_destroy(vl); throw(SQL, "sql.bind", SQLSTATE(0000) "Inconsistent BAT count"); } + BBPkeepref(id); + BBPkeepref(vl); *bid = id->batCacheid; - BBPkeepref(id); _______________________________________________ checkin-list mailing list -- [email protected] To unsubscribe send an email to [email protected]
