Changeset: 49ed353f273d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=49ed353f273d Added Files: monetdb5/modules/mal/bitcandidates.c monetdb5/modules/mal/bitcandidates.h monetdb5/modules/mal/bitcandidates.mal monetdb5/optimizer/Tests/BCLexample.malC monetdb5/optimizer/opt_bitcandidates.c monetdb5/optimizer/opt_bitcandidates.h Branch: compressedcandidates Log Message:
Framework for bit-candidate lists The (de-)compress of candidates framework. Next step is to actually compress them. diffs (233 lines): diff --git a/monetdb5/modules/mal/bitcandidates.c b/monetdb5/modules/mal/bitcandidates.c new file mode 100644 --- /dev/null +++ b/monetdb5/modules/mal/bitcandidates.c @@ -0,0 +1,43 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +#include "monetdb_config.h" +#include "bitcandidates.h" +#include "mal.h" +#include "mal_instruction.h" +#include "mal_interpreter.h" + +str +BCLcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + bat *ret = getArgReference_bat(stk,pci,0); + bat *val = getArgReference_bat(stk,pci,1); + BAT *b; + (void) cntxt; + (void) mb; + b = BATdescriptor(*val); + if( b == NULL) + throw(MAL,"compress",INTERNAL_BAT_ACCESS); + BBPkeepref(*ret = *val); + return MAL_SUCCEED; +} + +str +BCLdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + bat *ret = getArgReference_bat(stk,pci,0); + bat *val = getArgReference_bat(stk,pci,1); + BAT *b; + (void) cntxt; + (void) mb; + b = BATdescriptor(*val); + if( b == NULL) + throw(MAL,"decompress",INTERNAL_BAT_ACCESS); + BBPkeepref(*ret = *val); + return MAL_SUCCEED; +} diff --git a/monetdb5/modules/mal/bitcandidates.h b/monetdb5/modules/mal/bitcandidates.h new file mode 100644 --- /dev/null +++ b/monetdb5/modules/mal/bitcandidates.h @@ -0,0 +1,17 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +#ifndef _BITCANDIDATES_ +#define _BITCANDIDATES_ +#include "mal.h" +#include "mal_client.h" +#include "mal_interpreter.h" + +mal_export str BCLcompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +mal_export str BCLdecompress(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); +#endif diff --git a/monetdb5/modules/mal/bitcandidates.mal b/monetdb5/modules/mal/bitcandidates.mal new file mode 100644 --- /dev/null +++ b/monetdb5/modules/mal/bitcandidates.mal @@ -0,0 +1,15 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + +module candidates; + +pattern compress(b:bat[:oid]):bat[:oid] +address BCLcompress +comment "Compress the bat into a bitvector"; + +pattern decompress(b:bat[:oid]):bat[:oid] +address BCLdecompress +comment "Compress the bat into a bitvector"; diff --git a/monetdb5/optimizer/Tests/BCLexample.malC b/monetdb5/optimizer/Tests/BCLexample.malC new file mode 100644 --- /dev/null +++ b/monetdb5/optimizer/Tests/BCLexample.malC @@ -0,0 +1,8 @@ +function f(); + a := bat.new(:int); + C_2:= algebra.select(a,nil:bat[:oid], 0,10,true,true,false); + C_3:= algebra.select(a, C_2, 0,10,true,true,false); + io.print(C_2); +end f; +optimizer.bitcandidates("user","f"); +mdb.list("user","f"); diff --git a/monetdb5/optimizer/opt_bitcandidates.c b/monetdb5/optimizer/opt_bitcandidates.c new file mode 100644 --- /dev/null +++ b/monetdb5/optimizer/opt_bitcandidates.c @@ -0,0 +1,102 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +/* + * Use bit compressed candidate lists. + */ + +#include "monetdb_config.h" +#include "mal_instruction.h" +#include "opt_bitcandidates.h" + +str +OPTbitcandidatesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + int i, j, k, actions =0, limit=0, slimit=0; + InstrPtr *old, p,q; + int *alias = 0; + lng usec = GDKusec(); + char buf[256]; + + (void) cntxt; + (void) stk; + (void) pci; + + limit = mb->stop; + slimit = mb->ssize; + old = mb->stmt; + + // first check number of Candidate use cases + for (k= i = 0; i < mb->stop; i++) { + p = old[i]; + for(j=0; j< p->argc; j++) + k += isVarCList(mb, getArg(p,j)) > 0; + } + if ( k == 0) + goto wrapup; + + alias = (int*) GDKzalloc( ( k + mb->vsize) * sizeof(int)); + if( alias == NULL) + throw(MAL, "optimizer.bitcandidates", MAL_MALLOC_FAIL); + for( i = 0; i < mb->vtop ; i++) + alias[i] = i; + + if ( newMalBlkStmt(mb,mb->ssize + k) < 0){ + GDKfree(alias); + throw(MAL, "optimizer.bitcandidates", MAL_MALLOC_FAIL); + } + + for (i = 0; i < limit; i++) { + p = old[i]; + for(j = p->retc; j< p->argc; j++){ + // decompress before use + if ( isVarCList(mb, getArg(p,j)) && getArg(p,j) != alias[getArg(p,j)] ){ + q= newFcnCall(mb,candidatesRef,decompressRef); + getArg(q,0) = getArg(p,j); + q= pushArgument(mb,q, alias[getArg(p,j)]); + alias[getArg(p,j)] = getArg(p,j); + } + } + pushInstruction(mb,p); + for(j=0; j< p->retc; j++){ + // compress after creation, avoid this step when you immediately can use it + if ( isVarCList(mb, getArg(p,j)) ){ + k = newTmpVariable(mb,getArgType(mb,p,j)); + q= newFcnCall(mb,candidatesRef,compressRef); + setVarType(mb,getArg(q,0), getArgType(mb,p,j)); + q= pushArgument(mb,q, k); + alias[getArg(p,j)] = getArg(q,0); + getArg(p,j) = k; + actions++; + } + } + } + for( ; i<slimit; i++) + if( old[i]) + freeInstruction(old[i]); +#ifdef _OPT_BITCANDIDATES_DEBUG_ + fprintf(stderr,"#result of bitcandidates\n"); + fprintFunction(stderr,mb, 0, LIST_MAL_ALL); +#endif + +wrapup: + GDKfree(alias); + /* Defense line against incorrect plans */ + if( actions){ + chkTypes(cntxt->usermodule, mb, FALSE); + chkFlow(mb); + chkDeclarations(mb); + } + /* keep all actions taken as a post block comment */ + usec = GDKusec()- usec; + snprintf(buf,256,"%-20s actions=%d time=" LLFMT " usec","bitcandidates", actions, usec); + newComment(mb,buf); + addtoMalBlkHistory(mb); + + return MAL_SUCCEED; +} diff --git a/monetdb5/optimizer/opt_bitcandidates.h b/monetdb5/optimizer/opt_bitcandidates.h new file mode 100644 --- /dev/null +++ b/monetdb5/optimizer/opt_bitcandidates.h @@ -0,0 +1,18 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +#ifndef _OPT_BITCANDIDATES_ +#define _OPT_BITCANDIDATES_ + +#include "opt_prelude.h" +#include "opt_support.h" +#include "mal_exception.h" + +mal_export str OPTbitcandidatesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); + +#endif _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list