Changeset: ed08ba0b1ffa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ed08ba0b1ffa
Modified Files:
monetdb5/modules/atoms/str.c
sql/rel.txt
sql/server/rel_distribute.c
sql/storage/bat/bat_storage.c
Branch: default
Log Message:
optimize (bat)string to lower/upper handling
for temporary tables use bat to be appended directly when possible (ie on empty
tables)
diffs (202 lines):
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -3344,6 +3344,27 @@ str_case_hash_unlock(bool upper)
MT_rwlock_rdunlock(&b->thashlock);
}
+static const char upper2lower[128] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
+ 104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
+ 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
+ 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
+ 126,127
+};
+static const char lower2upper[128] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 93, 94, 95, 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
+ 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,
+ 126,127
+};
+
static inline str
convertCase(BAT *from, BAT *to, str *buf, size_t *buflen, const char *src,
const char *malfunc)
@@ -3359,51 +3380,44 @@ convertCase(BAT *from, BAT *to, str *buf
/* the from and to bats are not views */
assert(from->tbaseoff == 0);
assert(to->tbaseoff == 0);
- CHECK_STR_BUFFER_LENGTH(buf, buflen, len + 1, malfunc);
+
+ CHECK_STR_BUFFER_LENGTH(buf, buflen, 2 * len + 1, malfunc);
+ /* use len*2 because only case changing code points exists which change
from length 2 to 3 */
dst = *buf;
+
while (src < end) {
- int c;
-
- UTF8_GETCHAR(c, src);
- if (c < 192) { /* the first 191 characters in
unicode are trivial to convert */
- /* for ASCII characters we don't need to do a hash
lookup */
- if (lower_to_upper) {
- if ('a' <= c && c <= 'z')
- c += 'A' - 'a';
+ if (lower_to_upper) {
+ for (; src < end && (src[0] & 0x80) == 0; )
+ *dst++ = lower2upper[*src++];
+ } else {
+ for (; src < end && (src[0] & 0x80) == 0; )
+ *dst++ = upper2lower[*src++];
+ }
+ if (src < end) { /* fall back code for complex codepoints */
+ int c;
+
+ UTF8_GETCHAR(c, src);
+ if (c < 192) { /* the first 191
characters in unicode are trivial to convert */
+ /* for ASCII characters we don't need to do a
hash lookup */
+ if (lower_to_upper) {
+ if ('a' <= c && c <= 'z')
+ c += 'A' - 'a';
+ } else {
+ if (c <= 'Z' && 'A' <= c)
+ c += 'a' - 'A';
+ }
} else {
- if ('A' <= c && c <= 'Z')
- c += 'a' - 'A';
- }
- } else {
- /* use hash, even though BAT is sorted */
- for (BUN hb = HASHget(h, hash_int(h, &c));
- hb != BUN_NONE; hb = HASHgetlink(h, hb)) {
- if (c == fromb[hb]) {
- c = tob[hb];
- break;
+ /* use hash, even though BAT is sorted */
+ for (BUN hb = HASHget(h, hash_int(h, &c));
+ hb != BUN_NONE; hb =
HASHgetlink(h, hb)) {
+ if (c == fromb[hb]) {
+ c = tob[hb];
+ break;
+ }
}
}
+ UTF8_PUTCHAR(c, dst);
}
- if (dst + UTF8_CHARLEN(c) > *buf + len) {
- /* doesn't fit, so allocate more space;
- * also allocate enough for the rest of the
- * source */
- size_t off = dst - *buf;
- size_t nextlen = (len += 4 + (end - src)) + 1;
-
- /* Don't use CHECK_STR_BUFFER_LENGTH here, because it
- * does GDKmalloc instead of GDKrealloc and data could
be lost */
- if (nextlen > *buflen) {
- size_t newlen = ((nextlen + 1023) & ~1023);
/* align to a multiple of 1024 bytes */
- str newbuf = GDKrealloc(*buf, newlen);
- if (!newbuf)
- throw(MAL, malfunc, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- *buf = newbuf;
- *buflen = newlen;
- }
- dst = *buf + off;
- }
- UTF8_PUTCHAR(c, dst);
}
*dst = 0;
return MAL_SUCCEED;
diff --git a/sql/rel.txt b/sql/rel.txt
--- a/sql/rel.txt
+++ b/sql/rel.txt
@@ -110,7 +110,7 @@ e_atom (card ATOM)
or
-> r parameter ( ->r = sql_var_name -> { ->name variable name,
->sname schema of the variable }, ->type = subtype, ->flag = level)
or
- -> f list of atom expressions
+ -> f list of atom expressions, represents set of values
or
-> numbered variable ( ->flag = nr, ->type = subtype)
diff --git a/sql/server/rel_distribute.c b/sql/server/rel_distribute.c
--- a/sql/server/rel_distribute.c
+++ b/sql/server/rel_distribute.c
@@ -54,7 +54,7 @@ has_remote_or_replica( sql_rel *rel )
case op_insert:
case op_update:
case op_delete:
- return has_remote_or_replica( rel->l ) ||
has_remote_or_replica( rel->r );
+ return has_remote_or_replica( rel->l) || has_remote_or_replica(
rel->r );
case op_project:
case op_select:
case op_groupby:
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -2071,7 +2071,7 @@ update_idx(sql_trans *tr, sql_idx * i, v
}
static int
-delta_append_bat(sql_trans *tr, sql_delta **batp, sqlid id, BUN offset, BAT
*offsets, BAT *i, char *storage_type)
+delta_append_bat(sql_trans *tr, sql_delta **batp, sqlid id, BUN offset, BAT
*offsets, BAT *i, char *storage_type, bool istemp)
{
BAT *b, *oi = i;
int err = 0;
@@ -2114,7 +2114,13 @@ delta_append_bat(sql_trans *tr, sql_delt
bat_destroy(oi);
return LOG_ERR;
}
- if (!offsets && offset == b->hseqbase+BATcount(b)) {
+ if (istemp && !offsets && offset == 0 && BATcount(b) == 0 &&
bat->cs.ucnt == 0) {
+ bat_set_access(i, BAT_READ);
+ if (bat->cs.bid)
+ temp_destroy(bat->cs.bid);
+ transfer_to_systrans(i);
+ bat->cs.bid = temp_create(i);
+ } else if (!offsets && offset == b->hseqbase+BATcount(b)) {
if (BATappend(b, oi, NULL, true) != GDK_SUCCEED)
err = 1;
} else if (!offsets) {
@@ -2264,7 +2270,7 @@ dup_storage( sql_trans *tr, storage *oba
}
static int
-append_col_execute(sql_trans *tr, sql_delta **delta, sqlid id, BUN offset, BAT
*offsets, void *incoming_data, BUN cnt, int tt, char *storage_type)
+append_col_execute(sql_trans *tr, sql_delta **delta, sqlid id, BUN offset, BAT
*offsets, void *incoming_data, BUN cnt, int tt, char *storage_type, bool isnew)
{
int ok = LOG_OK;
@@ -2274,7 +2280,7 @@ append_col_execute(sql_trans *tr, sql_de
BAT *bat = incoming_data;
if (BATcount(bat))
- ok = delta_append_bat(tr, delta, id, offset, offsets,
bat, storage_type);
+ ok = delta_append_bat(tr, delta, id, offset, offsets,
bat, storage_type, isnew);
} else {
ok = delta_append_val(tr, delta, id, offset, offsets,
incoming_data, cnt, storage_type, tt);
}
@@ -2299,7 +2305,7 @@ append_col(sql_trans *tr, sql_column *c,
assert(delta->cs.st == ST_DEFAULT || delta->cs.st == ST_DICT ||
delta->cs.st == ST_FOR);
odelta = delta;
- if ((res = append_col_execute(tr, &delta, c->base.id, offset, offsets,
data, cnt, tpe, c->storage_type)) != LOG_OK)
+ if ((res = append_col_execute(tr, &delta, c->base.id, offset, offsets,
data, cnt, tpe, c->storage_type, isTempTable(c->t))) != LOG_OK)
return res;
if (odelta != delta) {
delta->next = odelta;
@@ -2331,7 +2337,7 @@ append_idx(sql_trans *tr, sql_idx *i, BU
assert(delta->cs.st == ST_DEFAULT);
- res = append_col_execute(tr, &delta, i->base.id, offset, offsets, data,
cnt, tpe, NULL);
+ res = append_col_execute(tr, &delta, i->base.id, offset, offsets, data,
cnt, tpe, NULL, isTempTable(i->t));
return res;
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]