Changeset: 7d5c7c3d054a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7d5c7c3d054a
Modified Files:
gdk/gdk_batop.c
gdk/gdk_orderidx.c
monetdb5/modules/mal/orderidx.c
sql/common/sql_mem.c
sql/include/sql_mem.h
sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.SQL.py
sql/test/BugTracker-2017/Tests/oidx-on-strings.Bug-6202.stable.err
sql/test/orderidx/Tests/oidx_all_types.stable.err
sql/test/orderidx/Tests/oidx_all_types.stable.out
testing/Mtest.py.in
Branch: default
Log Message:
Merge with Jul2017 branch.
diffs (truncated from 481 to 300 lines):
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1353,6 +1353,11 @@ BATsort(BAT **sorted, BAT **order, BAT *
GDKerror("BATsort: b must exist\n");
return GDK_FAIL;
}
+ if (!ATOMlinear(b->ttype)) {
+ GDKerror("BATsort: type %s cannot be sorted\n",
+ ATOMname(b->ttype));
+ return GDK_FAIL;
+ }
if (o != NULL &&
(ATOMtype(o->ttype) != TYPE_oid || /* oid tail */
BATcount(o) != BATcount(b) || /* same size as b */
diff --git a/gdk/gdk_orderidx.c b/gdk/gdk_orderidx.c
--- a/gdk/gdk_orderidx.c
+++ b/gdk/gdk_orderidx.c
@@ -155,72 +155,41 @@ persistOIDX(BAT *b)
gdk_return
BATorderidx(BAT *b, int stable)
{
- Heap *m;
- oid *restrict mv;
- oid seq;
- BUN p, q;
- BAT *bn = NULL;
-
if (BATcheckorderidx(b))
return GDK_SUCCEED;
- MT_lock_set(&GDKhashLock(b->batCacheid));
- if (b->torderidx) {
- MT_lock_unset(&GDKhashLock(b->batCacheid));
- return GDK_SUCCEED;
- }
- if ((m = createOIDXheap(b, stable)) == NULL) {
- MT_lock_unset(&GDKhashLock(b->batCacheid));
- return GDK_FAIL;
- }
-
- mv = (oid *) m->base + ORDERIDXOFF;
-
- seq = b->hseqbase;
- for (p = 0, q = BATcount(b); p < q; p++)
- mv[p] = seq + p;
-
if (!BATtdense(b)) {
- /* we need to sort a copy of the column so as not to
- * change the original */
- bn = COLcopy(b, b->ttype, TRUE, TRANSIENT);
- if (bn == NULL) {
- HEAPfree(m, 1);
- GDKfree(m);
- MT_lock_unset(&GDKhashLock(b->batCacheid));
+ BAT *on;
+ if (BATsort(NULL, &on, NULL, b, NULL, NULL, 0, stable) !=
GDK_SUCCEED)
return GDK_FAIL;
- }
- if (stable) {
- if (GDKssort(Tloc(bn, 0), mv,
- bn->tvheap ? bn->tvheap->base : NULL,
- BATcount(bn), Tsize(bn), SIZEOF_OID,
- bn->ttype) != GDK_SUCCEED) {
- HEAPfree(m, 1);
- GDKfree(m);
- MT_lock_unset(&GDKhashLock(b->batCacheid));
- BBPunfix(bn->batCacheid);
- return GDK_FAIL;
+ assert(BATcount(b) == BATcount(on));
+ if (on->tdense) {
+ /* if the order bat is dense, the input was
+ * sorted and we don't need an order index */
+ assert(b->tnosorted == 0);
+ if (!b->tsorted) {
+ b->tsorted = 1;
+ b->tnosorted = 0;
+ b->batDirtydesc = 1;
}
} else {
- GDKqsort(Tloc(bn, 0), mv,
- bn->tvheap ? bn->tvheap->base : NULL,
- BATcount(bn), Tsize(bn), SIZEOF_OID,
- bn->ttype);
+ /* BATsort quite possibly already created the
+ * order index, but just to be sure... */
+ MT_lock_set(&GDKhashLock(b->batCacheid));
+ if (b->torderidx == NULL) {
+ Heap *m;
+ if ((m = createOIDXheap(b, stable)) == NULL) {
+
MT_lock_unset(&GDKhashLock(b->batCacheid));
+ return GDK_FAIL;
+ }
+ memcpy((oid *) m->base + ORDERIDXOFF, Tloc(on,
0), BATcount(on) * sizeof(oid));
+ b->torderidx = m;
+ b->batDirtydesc = 1;
+ persistOIDX(b);
+ }
+ MT_lock_unset(&GDKhashLock(b->batCacheid));
}
- /* we must unfix after releasing the lock since we
- * might get deadlock otherwise (we're holding a lock
- * based on b->batCacheid; unfix tries to get a lock
- * based on bn->batCacheid, usually but (crucially)
- * not always a different lock) */
+ BBPunfix(on->batCacheid);
}
-
- b->torderidx = m;
- b->batDirtydesc = TRUE;
- persistOIDX(b);
- MT_lock_unset(&GDKhashLock(b->batCacheid));
-
- if (bn)
- BBPunfix(bn->batCacheid);
-
return GDK_SUCCEED;
}
@@ -343,6 +312,22 @@ GDKmergeidx(BAT *b, BAT**a, int n_ar)
if (BATcheckorderidx(b))
return GDK_SUCCEED;
+ switch (ATOMstorage(b->ttype)) {
+ case TYPE_bte:
+ case TYPE_sht:
+ case TYPE_int:
+ case TYPE_lng:
+#ifdef HAVE_HGE
+ case TYPE_hge:
+#endif
+ case TYPE_flt:
+ case TYPE_dbl:
+ break;
+ default:
+ GDKerror("GDKmergeidx: type %s not supported.\n",
+ ATOMname(b->ttype));
+ return GDK_FAIL;
+ }
MT_lock_set(&GDKhashLock(b->batCacheid));
if (b->torderidx) {
MT_lock_unset(&GDKhashLock(b->batCacheid));
@@ -403,7 +388,6 @@ GDKmergeidx(BAT *b, BAT**a, int n_ar)
#endif
case TYPE_flt: BINARY_MERGE(flt); break;
case TYPE_dbl: BINARY_MERGE(dbl); break;
- case TYPE_str:
default:
/* TODO: support strings, date, timestamps etc. */
assert(0);
diff --git a/monetdb5/modules/mal/orderidx.c b/monetdb5/modules/mal/orderidx.c
--- a/monetdb5/modules/mal/orderidx.c
+++ b/monetdb5/modules/mal/orderidx.c
@@ -48,6 +48,9 @@ OIDXcreateImplementation(Client cntxt, i
return MAL_SUCCEED;
switch (ATOMbasetype(b->ttype)) {
+ case TYPE_void:
+ /* trivially supported */
+ return MAL_SUCCEED;
case TYPE_bte:
case TYPE_sht:
case TYPE_int:
@@ -57,35 +60,33 @@ OIDXcreateImplementation(Client cntxt, i
#endif
case TYPE_flt:
case TYPE_dbl:
- break;
- case TYPE_str:
- /* TODO: support strings etc. */
- case TYPE_void:
- case TYPE_ptr:
+ if (GDKnr_threads > 1 && BATcount(b) >= 2 * MIN_PIECE &&
(GDKdebug & FORCEMITOMASK) == 0)
+ break;
+ /* fall through */
default:
- throw(MAL, "bat.orderidx", TYPE_NOT_SUPPORTED);
+ if (BATorderidx(b, 1) != GDK_SUCCEED)
+ throw(MAL, "bat.orderidx", TYPE_NOT_SUPPORTED);
+ return MAL_SUCCEED;
}
- if( pieces < 0 ){
+ if( pieces <= 0 ){
if (GDKnr_threads <= 1) {
pieces = 1;
+ } else if (GDKdebug & FORCEMITOMASK) {
+ /* we want many pieces, even tiny ones */
+ if (BATcount(b) < 4)
+ pieces = 1;
+ else if (BATcount(b) / 2 < (BUN) GDKnr_threads)
+ pieces = (int) (BATcount(b) / 2);
+ else
+ pieces = GDKnr_threads;
} else {
- if (GDKdebug & FORCEMITOMASK) {
- /* we want many pieces, even tiny ones */
- if (BATcount(b) < 4)
- pieces = 1;
- else if (BATcount(b) / 2 < (BUN) GDKnr_threads)
- pieces = (int) (BATcount(b) / 2);
- else
- pieces = GDKnr_threads;
- } else {
- if (BATcount(b) < 2 * MIN_PIECE)
- pieces = 1;
- else if (BATcount(b) / MIN_PIECE < (BUN)
GDKnr_threads)
- pieces = (int) (BATcount(b) /
MIN_PIECE);
- else
- pieces = GDKnr_threads;
- }
+ if (BATcount(b) < 2 * MIN_PIECE)
+ pieces = 1;
+ else if (BATcount(b) / MIN_PIECE < (BUN) GDKnr_threads)
+ pieces = (int) (BATcount(b) / MIN_PIECE);
+ else
+ pieces = GDKnr_threads;
}
} else if (BATcount(b) < (BUN) pieces || BATcount(b) < MIN_PIECE) {
pieces = 1;
diff --git a/sql/common/sql_mem.c b/sql/common/sql_mem.c
--- a/sql/common/sql_mem.c
+++ b/sql/common/sql_mem.c
@@ -72,16 +72,16 @@ sql_allocator *sa_reset( sql_allocator *
#undef sa_realloc
#undef sa_alloc
-char *sa_realloc( sql_allocator *sa, void *p, size_t sz, size_t oldsz )
+void *sa_realloc( sql_allocator *sa, void *p, size_t sz, size_t oldsz )
{
- char *r = sa_alloc(sa, sz);
+ void *r = sa_alloc(sa, sz);
- memcpy(r, (char*)p, oldsz);
+ memcpy(r, p, oldsz);
return r;
}
#define round16(sz) ((sz+15)&~15)
-char *sa_alloc( sql_allocator *sa, size_t sz )
+void *sa_alloc( sql_allocator *sa, size_t sz )
{
char *r;
sz = round16(sz);
@@ -118,9 +118,9 @@ char *sa_alloc( sql_allocator *sa, size_
}
#undef sa_zalloc
-char *sa_zalloc( sql_allocator *sa, size_t sz )
+void *sa_zalloc( sql_allocator *sa, size_t sz )
{
- char *r = sa_alloc(sa, sz);
+ void *r = sa_alloc(sa, sz);
if (r)
memset(r, 0, sz);
diff --git a/sql/include/sql_mem.h b/sql/include/sql_mem.h
--- a/sql/include/sql_mem.h
+++ b/sql/include/sql_mem.h
@@ -62,9 +62,9 @@ typedef struct sql_allocator {
extern sql_allocator *sa_create(void);
extern sql_allocator *sa_reset( sql_allocator *sa );
-extern char *sa_alloc( sql_allocator *sa, size_t sz );
-extern char *sa_zalloc( sql_allocator *sa, size_t sz );
-extern char *sa_realloc( sql_allocator *sa, void *ptr, size_t sz, size_t osz
);
+extern void *sa_alloc( sql_allocator *sa, size_t sz );
+extern void *sa_zalloc( sql_allocator *sa, size_t sz );
+extern void *sa_realloc( sql_allocator *sa, void *ptr, size_t sz, size_t osz
);
extern void sa_destroy( sql_allocator *sa );
extern char *sa_strndup( sql_allocator *sa, const char *s, size_t l);
extern char *sa_strdup( sql_allocator *sa, const char *s);
diff --git a/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.SQL.py
b/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.SQL.py
--- a/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.SQL.py
+++ b/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.SQL.py
@@ -5,6 +5,10 @@ except ImportError:
import process
def main():
+ if time.daylight and time.gmtime(time.time()).tm_isdst:
+ zone = time.altzone
+ else:
+ zone = time.timezone
sys.stderr.write('#client\n')
sys.stderr.flush()
clt = process.client('sql', user = 'monetdb', passwd = 'monetdb',
@@ -16,5 +20,13 @@ def main():
out, err = clt.communicate(sqlcommand)
sys.stdout.write(out)
sys.stderr.write(err)
+ clt = process.client('sql', user = 'monetdb', passwd = 'monetdb',
+ stdin = process.PIPE,
+ stdout = process.PIPE, stderr = process.PIPE)
+ out, err = clt.communicate('select localtime();')
+ sys.stdout.write('#Python says: %s; current time zone %d\n' %
(currenttime, zone))
+ for line in out.split('\n'):
+ if line:
+ sys.stdout.write('#MonetDB says: %s\n' % line)
main()
diff --git a/sql/test/BugTracker-2017/Tests/oidx-on-strings.Bug-6202.stable.err
b/sql/test/BugTracker-2017/Tests/oidx-on-strings.Bug-6202.stable.err
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list