Changeset: 6cd501a905c3 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6cd501a905c3 Modified Files: monetdb5/modules/mal/joinpath.c Branch: default Log Message:
Revert chain join code The initial thought that avoiding the intermediates in simple oid-chain joins does not materialize in sf10, sf100. It is even somewhat slower, most likely due to the interference of pages from the first argument being swapped out when you traverse the dependencies. diffs (134 lines): diff --git a/monetdb5/modules/mal/joinpath.c b/monetdb5/modules/mal/joinpath.c --- a/monetdb5/modules/mal/joinpath.c +++ b/monetdb5/modules/mal/joinpath.c @@ -150,96 +150,6 @@ ALGjoinCost(Client cntxt, BAT *l, BAT *r return cost; } -/* - * The joinChain assumes a list of OID columns ending in a projection column. - * It is built from leftfetchjoin operations, which allows for easy chaining. - * No intermediates are needed and not multistep cost-based evaluation - */ - -#define MAXCHAINDEPTH 256 - -static BAT * -ALGjoinChain(Client cntxt, int top, BAT **joins) -{ - BAT *bn = NULL; - oid lo, hi, oc; - BATiter iter[MAXCHAINDEPTH]; - int i, pcol= top -1, td = 1, ts = 1; - BUN cnt=0, cap=0, empty=0, size[MAXCHAINDEPTH]; - ssize_t offset[MAXCHAINDEPTH]; - const void *v; - - //#undef ALGODEBUG - //#define ALGODEBUG if(1) - (void) cntxt; - - for ( i =0; i< top ; i++){ - if( (cnt = BATcount(joins[i]) ) > cap) - cap = BATcount(joins[i]); - empty += cnt == 0; - iter[i] = bat_iterator(joins[i]); - size[i] = BATcount(joins[i]); - offset[i] = BUNfirst(joins[i])-joins[i]->hseqbase; - ALGODEBUG { - mnstr_printf(cntxt->fdout,"#%d types [%d, %d] "BUNFMT" "SSZFMT" \n",i, joins[i]->htype, joins[i]->ttype, size[i], offset[i]); - } - if (i<(top-1)) - td &= joins[i]->tdense; - if (i<(top-1)) - ts &= joins[i]->tsorted; - } - - bn = BATnew( TYPE_void, joins[pcol]->ttype?joins[pcol]->ttype:TYPE_oid, cap, TRANSIENT); - if( bn == NULL){ - GDKerror("joinChain" MAL_MALLOC_FAIL); - return NULL; - } - /* be optimistic, inherit the properties */ - BATsettrivprop(bn); - BATseqbase(bn, 0); - if (empty) - return bn; - - bn->tkey = td&&joins[pcol]->tkey; - bn->tdense = 0; - bn->tsorted = ts&&joins[pcol]->tsorted; - bn->trevsorted = 0; - bn->T->nil = 0; - bn->T->nonil = joins[pcol]->T->nonil; - - cnt = 0; - for (lo = 0, hi = lo + BATcount(joins[0]); lo < hi; lo++) { - oc = *(oid *) BUNtail(iter[0], lo); - for(i = 1; i < pcol; i++) - if (oc + offset[i] < size[i]) { - v = BUNtail(iter[i], (BUN) (oc + offset[i])); - oc = *(oid*) v; - if (oc == oid_nil) - goto bunins_failed; - } - - if (i != pcol) - continue; - // update the join result and keep track of properties - if (oc + offset[pcol] < size[pcol]){ - v = BUNtail(iter[pcol], (BUN) (oc + offset[pcol])); - bunfastapp(bn,v); - cnt++; - } - bunins_failed: - ; - } - BATsetcount(bn, cnt); - bn->hrevsorted = (BATcount(bn) <=1); - - // release the chain - for ( i =0; i< top ; i++) - BBPunfix(joins[i]->batCacheid); - - if (bn && !(bn->batDirty&2)) BATsetaccess(bn, BAT_READ); - - return bn; -} static BAT * ALGjoinPathBody(Client cntxt, int top, BAT **joins, int flag) @@ -362,7 +272,7 @@ ALGjoinPathBody(Client cntxt, int top, B str ALGjoinPath(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { - int i,top=0, chain = 1, empty = 0; + int i,top=0, empty = 0; bat *bid; bat *r = getArgReference_bat(stk, pci, 0); BAT *b, **joins = (BAT**)GDKmalloc(pci->argc*sizeof(BAT*)); @@ -393,14 +303,11 @@ ALGjoinPath(Client cntxt, MalBlkPtr mb, empty += BATcount(b) == 0; joins[top++] = b; } - /* detect easy left-right oid chain joins */ - chain = BATcount(joins[0]) < BATcount(joins[top-1]) && top < MAXCHAINDEPTH; - chain = 0; // disabled for the moment, because it is not robust yet ALGODEBUG{ char *ps; ps = instruction2str(mb, 0, pci, LIST_MAL_ALL); - fprintf(stderr,"#joinpath [%s] %s\n", (ps ? ps : ""), chain?"chain":"diverse"); + fprintf(stderr,"#joinpath %s\n", (ps ? ps : "")); GDKfree(ps); } if ( empty){ @@ -415,8 +322,6 @@ ALGjoinPath(Client cntxt, MalBlkPtr mb, BATsettrivprop(b); } else if (getFunctionId(pci) == leftjoinPathRef) { b = ALGjoinPathBody(cntxt,top,joins, 0); - } else if (chain && top < MAXCHAINDEPTH) { - b = ALGjoinChain(cntxt,top,joins); } else { b = ALGjoinPathBody(cntxt,top,joins, 3); } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list