Update of /cvsroot/monetdb/pathfinder/runtime
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv1387/pathfinder/runtime
Modified Files:
pf_support.mx
Log Message:
For Henning & PFtijah:
made merged_union() (and thus multi_merged_union())
also recognize and handle reverse-sortedness,
i.e., in case the leading columns of all tables
are reverse-sorted, the result wil be reverse-sorted;
in case the leading columns of all tables
are sorted, the result will be sorted.
U pf_support.mx
Index: pf_support.mx
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/runtime/pf_support.mx,v
retrieving revision 1.336
retrieving revision 1.337
diff -u -d -r1.336 -r1.337
--- pf_support.mx 18 Jun 2009 10:52:00 -0000 1.336
+++ pf_support.mx 14 Oct 2009 17:46:37 -0000 1.337
@@ -140,7 +140,7 @@
"PARAMETERS:
Even number of BAT[oid,any] with dense heads and pairs of equal tail type;
all odd BATs must be head-aligned and all even BATs must be head-aligned;
-first two BATs must be sorted on tail values.
+first two BATs must be (reverse-)sorted on tail values.
DESCRIPTION:
Merges pairs of bats according to the order as defined by the first pair's
tails."
@(
@@ -157,7 +157,7 @@
BAT[void,BAT t[void,BAT c[VoID,any]]]:
a void-headed BAT of n void-headed BATs t such that each BAT t represents a
relational table t of m columns c, each represented by a dense-headed BAT c;
-the first column of each table must be sorted.
+the first column of each table must be (reverse-)sorted.
DESCRIPTION:
Merges the n relational tables t according to the value-order as defined by the
first columns of all tables."
@@ -6216,7 +6216,7 @@
oid hsqb[ntabs];
BUN Bcnt[ntabs], inc[2];
int t, c, var, fix, non_empty[ntabs+1];
- bit concat01 = FALSE, concat10 = FALSE, void_fix = FALSE;
+ bit concat01 = FALSE, concat10 = FALSE, void_fix = FALSE, reverse =
FALSE;
bte *w = NULL, *ww[2], *wt, *ws[2];
BUN res_count = 0, h = 0;
@@ -6232,12 +6232,26 @@
*res = NULL;
/* check arguments */
- for (t=0; t<ntabs; t++) {
- if (BATcount(b[t][0])>1 && !(BATtordered(b[t][0])&1)) {
- GDKerror("merged_union: tail of first BAT/column of
table %d must be sorted.\n", t+1);
- return GDK_FAIL;
- }
- }
+ for (t=0; t<ntabs && BATcount(b[t][0]) <= 1; t++);
+ if (t<ntabs && !(BATtordered(b[t][0])&1) && !(reverse =
(BATtordered(b[t][0]) == GDK_SORTED_REV))) {
+ GDKerror("merged_union: tail of first BAT/column of table %d
must be (reverse-)sorted.\n", t+1);
+ return GDK_FAIL;
+ }
+ if (reverse) {
+ for (; t<ntabs; t++) {
+ if (BATcount(b[t][0])>1 && !(BATtordered(b[t][0]) ==
GDK_SORTED_REV)) {
+ GDKerror("merged_union: tail of first
BAT/column of table %d must be reverse-sorted.\n", t+1);
+ return GDK_FAIL;
+ }
+ }
+ } else {
+ for (; t<ntabs; t++) {
+ if (BATcount(b[t][0])>1 && !(BATtordered(b[t][0])&1)) {
+ GDKerror("merged_union: tail of first
BAT/column of table %d must be sorted.\n", t+1);
+ return GDK_FAIL;
+ }
+ }
+ }
for (t=0; t<ntabs; t++) {
mat[t] = FALSE;
@@ -6375,21 +6389,40 @@
/* merge-union the first BATs/columns; regard and preserve tail-order */
concat01 = (cnt[0]==0 || cnt[1]==0);
concat10 = FALSE;
- if (BATtordered(src[0])&BATtordered(src[1])&1 || (BATtordered(src[0])&1
&& cnt[1]==1) || (cnt[0]==1 && BATtordered(src[1])&1) ) {
- if (!concat01) {
- concat01 =
@4_LE(b...@2(srci[0],BUNlast(src[0])-1),b...@3(srci[1],BUNfirst(src[1])),@1);
- }
- if (!concat01) {
- concat10 =
@4_LT(b...@3(srci[1],BUNlast(src[1])-1),b...@2(srci[0],BUNfirst(src[0])),@1);
- }
- }
- if (!concat01 && !concat10) {
- while ((idx[0] < cnt[0]) && (idx[1] < cnt[1])) {
-
@:merged_union_0(@1,@2,0,@4_LE(b...@2(srci[0],csr[0]),b...@3(srci[1],csr[1]),@1))@
- if (idx[0] < cnt[0]) {
-
@:merged_union_0(@1,@3,1,@4_GT(b...@2(srci[0],csr[0]),b...@3(srci[1],csr[1]),@1))@
- }
- }
+ if (reverse) {
+ if ((BATtordered(src[0]) == GDK_SORTED_REV &&
BATtordered(src[1]) == GDK_SORTED_REV) || (BATtordered(src[0]) ==
GDK_SORTED_REV && cnt[1]==1) || (cnt[0]==1 && BATtordered(src[1]) ==
GDK_SORTED_REV) ) {
+ if (!concat01) {
+ concat01 =
@4_GE(b...@2(srci[0],BUNlast(src[0])-1),b...@3(srci[1],BUNfirst(src[1])),@1);
+ }
+ if (!concat01) {
+ concat10 =
@4_GT(b...@3(srci[1],BUNlast(src[1])-1),b...@2(srci[0],BUNfirst(src[0])),@1);
+ }
+ }
+ if (!concat01 && !concat10) {
+ while ((idx[0] < cnt[0]) && (idx[1] < cnt[1])) {
+
@:merged_union_0(@1,@2,0,@4_GE(b...@2(srci[0],csr[0]),b...@3(srci[1],csr[1]),@1))@
+ if (idx[0] < cnt[0]) {
+
@:merged_union_0(@1,@3,1,@4_LT(b...@2(srci[0],csr[0]),b...@3(srci[1],csr[1]),@1))@
+ }
+ }
+ }
+ } else {
+ if (BATtordered(src[0])&BATtordered(src[1])&1 ||
(BATtordered(src[0])&1 && cnt[1]==1) || (cnt[0]==1 && BATtordered(src[1])&1) ) {
+ if (!concat01) {
+ concat01 =
@4_LE(b...@2(srci[0],BUNlast(src[0])-1),b...@3(srci[1],BUNfirst(src[1])),@1);
+ }
+ if (!concat01) {
+ concat10 =
@4_LT(b...@3(srci[1],BUNlast(src[1])-1),b...@2(srci[0],BUNfirst(src[0])),@1);
+ }
+ }
+ if (!concat01 && !concat10) {
+ while ((idx[0] < cnt[0]) && (idx[1] < cnt[1])) {
+
@:merged_union_0(@1,@2,0,@4_LE(b...@2(srci[0],csr[0]),b...@3(srci[1],csr[1]),@1))@
+ if (idx[0] < cnt[0]) {
+
@:merged_union_0(@1,@3,1,@4_GT(b...@2(srci[0],csr[0]),b...@3(srci[1],csr[1]),@1))@
+ }
+ }
+ }
}
/* get remaining BUNs */
if (!concat10) {
@@ -6461,7 +6494,7 @@
BATsetcount(tgt, (dst[0] - BUNfirst(tgt)));
if (!tgt->batDirty) tgt->batDirty = TRUE;
BATkey(BATmirror(tgt),FALSE);
- tgt->tsorted = GDK_SORTED;
+ tgt->tsorted = (reverse ? GDK_SORTED_REV : GDK_SORTED);
tgt->tdense = FALSE;
if (void_fix) {
BBPunfix(src[0]->batCacheid);
@@ -6574,7 +6607,10 @@
BATkey(bn[c],TRUE);
BATkey(BATmirror(bn[c]),(res_count < 2));
bn[c]->hsorted = GDK_SORTED;
- if (c == 0 || res_count < 2) {
+ if (c == 0) {
+ bn[c]->tsorted = (reverse ? GDK_SORTED_REV :
GDK_SORTED);
+ } else
+ if (res_count < 2) {
bn[c]->tsorted = GDK_SORTED;
} else
if (non_empty[ntabs] == 1) {
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins