Changeset: c9b55e0fdd95 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c9b55e0fdd95 Modified Files: gdk/gdk_batop.c Branch: Jul2017 Log Message:
More reuse of order index + cleanup after failure. diffs (66 lines): diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c --- a/gdk/gdk_batop.c +++ b/gdk/gdk_batop.c @@ -1457,7 +1457,7 @@ BATsort(BAT **sorted, BAT **order, BAT * } else { pb = b; } - if (g == NULL && groups == NULL && o == NULL && !reverse && + if (g == NULL && o == NULL && !reverse && pb != NULL && BATcheckorderidx(pb) && /* if we want a stable sort, the order index must be * stable, if we don't want stable, we don't care */ @@ -1473,12 +1473,28 @@ BATsort(BAT **sorted, BAT **order, BAT * on->tnonil = 1; on->tsorted = on->trevsorted = 0; on->tdense = 0; - if (sorted) { + if (sorted || groups) { bn = BATproject(on, b); if (bn == NULL) goto error; bn->tsorted = 1; - *sorted = bn; + if (groups) { + if (BATgroup_internal(groups, NULL, NULL, bn, NULL, g, NULL, NULL, 1) != GDK_SUCCEED) + goto error; + if (sorted && + (*groups)->tkey && + g == NULL) { + /* if new groups bat is key + * and since there is no input + * groups bat, we know the + * result bat is key */ + bn->tkey = 1; + } + } + if (sorted) + *sorted = bn; + else + BBPunfix(bn->batCacheid); } if (order) *order = on; @@ -1495,6 +1511,7 @@ BATsort(BAT **sorted, BAT **order, BAT * BBPunfix(bn->batCacheid); bn = b; } + pb = NULL; } else { bn = COLcopy(b, b->ttype, TRUE, TRANSIENT); } @@ -1635,8 +1652,13 @@ BATsort(BAT **sorted, BAT **order, BAT * ords, bn->tvheap ? bn->tvheap->base : NULL, BATcount(bn), Tsize(bn), ords ? sizeof(oid) : 0, - bn->ttype, reverse, stable) != GDK_SUCCEED)) + bn->ttype, reverse, stable) != GDK_SUCCEED)) { + if (m != NULL) { + HEAPfree(m, 1); + GDKfree(m); + } goto error; + } bn->tsorted = !reverse; bn->trevsorted = reverse; if (m != NULL) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list