Changeset: fc64ecd8ee88 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fc64ecd8ee88
Modified Files:
clients/Tests/exports.stable.out
clients/mapiclient/dump.c
gdk/gdk.h
gdk/gdk_align.c
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_bbp.c
gdk/gdk_hash.c
gdk/gdk_join.c
gdk/gdk_logger.c
gdk/gdk_private.h
gdk/gdk_project.c
gdk/gdk_select.c
gdk/gdk_string.c
sql/backends/monet5/sql_cat.c
sql/include/sql_catalog.h
sql/server/rel_schema.c
sql/server/sql_mvc.c
sql/server/sql_mvc.h
sql/server/sql_parser.y
sql/server/sql_tokens.h
sql/storage/bat/bat_storage.c
sql/storage/sql_catalog.c
sql/storage/store.c
Branch: ustr
Log Message:
Implemented column option DISTINCT STRING COLUMN qname in table create.
diffs (truncated from 1213 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -113,7 +113,7 @@ gdk_return BATclear(BAT *b, bool force);
void BATcommit(BAT *b, BUN size);
BAT *BATconstant(oid hseq, int tt, const void *val, BUN cnt, role_t role);
BAT *BATconvert(BAT *b, BAT *s, int tp, uint8_t scale1, uint8_t scale2,
uint8_t precision);
-gdk_return BATconvert2ustr(BAT *b) __attribute__((__warn_unused_result__));
+gdk_return BATconvert2ustr(BAT *b, BAT *bu)
__attribute__((__warn_unused_result__));
BUN BATcount_no_nil(BAT *b, BAT *s);
gdk_return BATdel(BAT *b, BAT *d) __attribute__((__warn_unused_result__));
BAT *BATdense(oid hseq, oid tseq, BUN cnt)
__attribute__((__warn_unused_result__));
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -998,13 +998,26 @@ dump_column_definition(Mapi mid, stream
}
space = dump_type(mid, sqlf, c_type, c_type_digits,
c_type_scale, hashge);
if (strcmp(c_null, "false") == 0) {
- mnstr_printf(sqlf, "%*s NOT NULL",
- CAP(13 - space), "");
+ mnstr_printf(sqlf, "%*s NOT NULL", CAP(13 - space), "");
space = 13;
}
- if (c_storage && strcmp(c_storage, "USTR") == 0) {
- mnstr_printf(sqlf, "%*s STORAGE '%s'",
- CAP(13 - space), "",
c_storage);
+ if (c_storage && strncmp(c_storage, "USTR", 4) == 0) {
+ char q[128];
+ int sid, uid;
+ sscanf(c_storage, "USTR %d %d", &sid, &uid);
+ snprintf(q, sizeof(q), "SELECT s.name, o.name FROM
sys.schemas s, sys.objects o WHERE s.id = %d AND o.nr = s.id AND o.id = %d",
sid, uid);
+ MapiHdl h = mapi_query(mid, q);
+ if (h != NULL) {
+ if (mapi_fetch_row(h) != 0) {
+ const char *sname = mapi_fetch_field(h,
0);
+ const char *uname = mapi_fetch_field(h,
1);
+ mnstr_printf(sqlf, "%*s DISTINCT STRING
COLUMN ",
+ CAP(13 -
space), "");
+ dquoted_print(sqlf, sname, ".");
+ dquoted_print(sqlf, uname, NULL);
+ }
+ mapi_close_handle(h);
+ }
space = 13;
}
@@ -1961,7 +1974,7 @@ dump_table_storage(Mapi mid, const char
snprintf(query, maxquerylen,
"SELECT name, storage FROM sys._columns "
- "WHERE storage NOT LIKE 'USTR' "
+ "WHERE storage NOT LIKE 'USTR%%' "
"AND table_id = (SELECT id FROM sys._tables WHERE name
= '%s' "
"AND schema_id = (SELECT id FROM sys.schemas WHERE
name = '%s'))",
t, s);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -404,7 +404,7 @@ typedef struct BAT {
bool tsorted:1; /* column is sorted in ascending order */
bool trevsorted:1; /* column is sorted in descending order */
bool tascii:1; /* string column is fully ASCII (7 bit) */
- bool ustr:1; /* use ustrbat */
+ bat ustr; /* use ustr bat */
BUN tnokey[2]; /* positions that prove key==FALSE */
BUN tnosorted; /* position that proves sorted==FALSE */
BUN tnorevsorted; /* position that proves revsorted==FALSE */
@@ -619,8 +619,8 @@ typedef struct BATiter {
vhdirty:1,
copiedtodisk:1,
transient:1,
- ascii:1,
- ustr:1;
+ ascii:1;
+ bat ustr;
restrict_t restricted:2;
#ifndef NDEBUG
bool locked:1;
@@ -789,7 +789,7 @@ gdk_export BAT *BATdense(oid hseq, oid t
__attribute__((__warn_unused_result__));
gdk_export gdk_return BATextend(BAT *b, BUN newcap)
__attribute__((__warn_unused_result__));
-gdk_export gdk_return BATconvert2ustr(BAT *b)
+gdk_export gdk_return BATconvert2ustr(BAT *b, BAT *bu)
__attribute__((__warn_unused_result__));
/* internal */
@@ -1245,16 +1245,14 @@ gdk_export void GDKclrerr(void);
*/
__attribute__((__warn_unused_result__))
static inline gdk_return
-tfastins_nocheckVAR(BAT *b, BUN p, const void *v)
+tfastins_nochecknolockVAR(BAT *b, BUN p, const void *v)
{
var_t d;
gdk_return rc;
assert(b->tbaseoff == 0);
assert(b->theap->parentid == b->batCacheid);
- MT_lock_set(&b->theaplock);
rc = ATOMputVAR(b, &d, v);
if (rc != GDK_SUCCEED) {
- MT_lock_unset(&b->theaplock);
return rc;
}
if (d != 0 &&
@@ -1263,7 +1261,6 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
/* doesn't fit in current heap, upgrade it */
rc = GDKupgradevarheap(b, d, 0, MAX(p, b->batCount));
if (rc != GDK_SUCCEED) {
- MT_lock_unset(&b->theaplock);
return rc;
}
}
@@ -1289,8 +1286,17 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
default:
MT_UNREACHABLE();
}
+ return GDK_SUCCEED;
+}
+
+__attribute__((__warn_unused_result__))
+static inline gdk_return
+tfastins_nocheckVAR(BAT *b, BUN p, const void *v)
+{
+ MT_lock_set(&b->theaplock);
+ gdk_return rc = tfastins_nochecknolockVAR(b, p, v);
MT_lock_unset(&b->theaplock);
- return GDK_SUCCEED;
+ return rc;
}
__attribute__((__warn_unused_result__))
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -206,6 +206,8 @@ VIEWcreate(oid seq, BAT *b, BUN l, BUN h
BBPretain(bn->theap->parentid);
if (bn->tvheap)
BBPretain(bn->tvheap->parentid);
+ if (bn->ustr)
+ BBPfix(bn->ustr);
TRC_DEBUG(ALGO, ALGOBATFMT " " BUNFMT "," BUNFMT " -> " ALGOBATFMT "\n",
ALGOBATPAR(b), l, h, ALGOBATPAR(bn));
return bn;
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -160,6 +160,7 @@ BATcreatedesc(oid hseq, int tt, bool hea
.ttype = tt,
.tkey = true,
+ .tvkey = tt == TYPE_str,
.tnonil = true,
.tnil = false,
.tsorted = ATOMlinear(tt),
@@ -809,9 +810,12 @@ COLcopy2(BAT *b, int tt, bool writable,
}
if (b->ustr &&
mayshare &&
- role == PERSISTENT &&
- BATconvert2ustr(bn) != GDK_SUCCEED) {
- goto bunins_failed;
+ role == PERSISTENT) {
+ BAT *bu = BATdescriptor(b->ustr);
+ gdk_return rc = BATconvert2ustr(bn, bu);
+ BBPreclaim(bu);
+ if (rc != GDK_SUCCEED)
+ goto bunins_failed;
}
if (bn->tvheap != NULL && bn->tvheap->base == NULL && !mayshare) {
/* this combination can happen since the last
@@ -840,6 +844,7 @@ COLcopy2(BAT *b, int tt, bool writable,
if (HEAPextend(bn->tvheap, bi.vhfree, true) !=
GDK_SUCCEED)
goto bunins_failed;
memcpy(bn->tvheap->base, bi.vh->base,
bi.vhfree);
+ bn->tvkey = bi.vkey;
bn->tvheap->free = bi.vhfree;
bn->tvheap->dirty = true;
bn->tascii = bi.ascii;
@@ -1938,8 +1943,8 @@ BUNfnd(BAT *b, const void *v)
}
var_t off = 0;
if (b->ustr) {
- BAT *u = getUstrBat();
- if (u == NULL || (r = BUNfnd(u, v)) == BUN_NONE)
+ BAT *u = BBP_desc(b->ustr);
+ if ((r = BUNfnd(u, v)) == BUN_NONE)
return r;
bi = bat_iterator(u);
off = VarHeapVal(bi.base, r, bi.width);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -158,6 +158,7 @@ insert_string_bat(BAT *b, BATiter *ni, s
/* vheaps are already shared, continue doing so: we just
* need to append the offsets */
toff = 0;
+ b->tvkey |= ni->vkey;
MT_thread_setalgorithm("shared vheap");
} else if (b->ustr) {
MT_thread_setalgorithm("individual inserts into ustr");
@@ -170,6 +171,7 @@ insert_string_bat(BAT *b, BATiter *ni, s
HEAPincref(ni->vh);
b->tvheap = ni->vh;
b->tascii = ni->ascii;
+ b->tvkey = ni->vkey;
MT_lock_unset(&b->theaplock);
BBPretain(ni->vh->parentid);
if (bid != b->batCacheid)
@@ -231,6 +233,7 @@ insert_string_bat(BAT *b, BATiter *ni, s
b->tvheap->free = toff + ni->vhfree;
b->tvheap->dirty = true;
b->tascii &= ni->ascii;
+ b->tvkey = ni->vkey && toff == 0;
MT_lock_unset(&b->theaplock);
}
}
@@ -569,6 +572,7 @@ append_varsized_bat(BAT *b, BATiter *ni,
b->trevsorted = ni->revsorted;
b->tnorevsorted = ni->norevsorted;
b->tkey = ni->key;
+ b->tvkey = ni->vkey;
b->tnokey[0] = ni->nokey[0];
b->tnokey[1] = ni->nokey[1];
b->tminpos = ni->minpos;
@@ -977,6 +981,7 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool
b->tnorevsorted = 0;
}
b->tkey = ni.key;
+ b->tvkey = ni.vkey;
if (ci.ncand == BATcount(n)) {
b->tnokey[0] = ni.nokey[0];
b->tnokey[1] = ni.nokey[1];
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -420,6 +420,15 @@ vheapinit(BAT *b, const char *buf, unsig
TRC_CRITICAL(GDK, "invalid format for BBP.dir on line %d",
lineno);
return -1;
}
+ if (b->ustr) {
+ assert(bbpversion > GDKLIBRARY_USTR);
+ if (free == 0 || free >= N_BBPINIT * BBPINIT) {
+ TRC_CRITICAL(GDK, "ustr ID (%" PRIu64 ") out of allowed
range, on line %d", free, lineno);
+ return -1;
+ }
+ b->ustr = (bat) free;
+ return n;
+ }
if (b->batCount == 0)
free = 0;
if (b->ttype >= 0 &&
@@ -559,7 +568,7 @@ heapinit(BAT *b, const char *buf,
b->tnonil = (properties & 0x0400) != 0;
b->tnil = (properties & 0x0800) != 0;
b->tascii = (properties & 0x1000) != 0;
- b->ustr = (bbpversion <= GDKLIBRARY_USTR) ? false : (properties &
0x2000) != 0;
+ b->ustr = (bbpversion <= GDKLIBRARY_USTR) ? 0 : (properties & 0x2000)
!= 0;
b->tvkey = (bbpversion <= GDKLIBRARY_USTR) ? false : (properties &
0x4000) != 0;
b->tnosorted = (BUN) nosorted;
b->tnorevsorted = (BUN) norevsorted;
@@ -591,7 +600,7 @@ heapinit(BAT *b, const char *buf,
b->tmaxpos = (BUN) maxpos;
else
b->tmaxpos = BUN_NONE;
- if (t && var && !b->ustr) {
+ if (t && var) {
t = vheapinit(b, buf + n, bbpversion, filename, lineno);
if (t < 0)
return t;
@@ -1897,27 +1906,25 @@ BBPinit(bool allow_hge_upgrade, bool no_
/* add free bats to free list in such a way that low numbered
* ones are at the head of the list; also record whether we have
* a ustr bat */
- bool seenustr = false;
for (bat i = (bat) ATOMIC_GET(&BBPsize) - 1; i > 0; i--) {
BAT *b = BBP_desc(i);
if (b->batCacheid == 0) {
BBP_next(i) = BBP_free;
BBP_free = i;
BBP_nfree++;
- } else {
- seenustr |= b->ustr;
+ } else if (b->ustr) {
+ BAT *u = BBP_desc(b->ustr);
+ if (u->batCacheid == 0 ||
+ u->ttype != TYPE_str ||
+ u->ustr != 0 ||
+ !u->tvkey) {
+ TRC_CRITICAL(GDK, "incorrect reference to ustr
bat from " ALGOBATFMT, ALGOBATPAR(b));
+ ATOMIC_SET(&GDKdebug, dbg);
+ return GDK_FAIL;
+ }
}
}
- if (seenustr && getUstrBat() == NULL) {
-#ifdef GDKLIBRARY_HASHASH
- GDKfree(hashbats);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]