Changeset: 70a87c8b1ecd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=70a87c8b1ecd
Modified Files:
monetdb5/extras/bwd/operations.c
monetdb5/extras/bwd/opt_bwd.mal
monetdb5/extras/bwd/optimizer.c
monetdb5/extras/bwd/pusher.c
Branch: bwd
Log Message:
* we have a (syntactically) correct plan for TPC-H Q1 now, most of the
operators are not implemented yet
Unterschiede (gekürzt von 313 auf 300 Zeilen):
diff --git a/monetdb5/extras/bwd/operations.c b/monetdb5/extras/bwd/operations.c
--- a/monetdb5/extras/bwd/operations.c
+++ b/monetdb5/extras/bwd/operations.c
@@ -633,6 +633,10 @@ str BWDtmark(int *res, int *bid, oid *ba
return returnValue;
}
+str BWDmirror(int *res, int *bid, oid *base){
+ throw(MAL, "not implemented yet: %s", __func__);
+}
+
str BWDUselectInclusiveApproximate(int *result, int *bid, ptr low, ptr high,
bit *lin, bit *rin, Client context){
return uselect(result, bid, low, *lin?">=":">", high, *rin?"<=":"<",
context);
@@ -863,6 +867,37 @@ str BWDSemijoinRefine(int *res, int *lid
}
}
+
+
+
+str BWDBatADDsignalApproximate(bat *ret, bat *bid1, bat *bid2){
+ //TODO: implement me (easy)
+ return MAL_SUCCEED;
+}
+
+extern str CMDbatADDsignal(bat *ret, bat *bid1, bat *bid2);
+
+str BWDBatADDsignalRefine(bat *ret, bat *bid1, bat *bid2, bat *approx){
+ //TODO: implement me (easy)
+ return CMDbatADDsignal(ret, bid1, bid2);
+}
+
+
+
+str BWDBatSUBsignalApproximate(bat *ret, bat *bid1, bat *bid2){
+ //TODO: implement me (easy)
+ return MAL_SUCCEED;
+}
+
+extern str CMDbatSUBsignal(bat *ret, bat *bid1, bat *bid2);
+
+str BWDBatSUBsignalRefine(bat *ret, bat *bid1, bat *bid2, bat *approx){
+ //TODO: implement me (easy)
+ return CMDbatSUBsignal(ret, bid1, bid2);
+}
+
+
+
str BWDBatMULsignalApproximate(bat *ret, bat *bid1, bat *bid2){
//TODO: implement me (easy)
return MAL_SUCCEED;
@@ -887,6 +922,16 @@ str BWDSelectNotNilRefine(int *result, i
}
+str BWDGroupedSumApproximate(int *retid,int *bid, int *gid, int *eid){
+ throw(MAL, "not implemented yet: %s", __func__);
+
+}
+
+str BWDGroupedSumRefine(int *retid,int *bid, int *gid, int *eid, bat* approx){
+ throw(MAL, "not implemented yet: %s", __func__);
+
+}
+
str BWDSumApproximate(lng* res, int *bid) {
//TODO: implement me (easy)
return MAL_SUCCEED;
@@ -901,4 +946,17 @@ str bwd_export_value_wrap(Client cntxt,
//TODO: implement me (no idea how we do this)
return MAL_SUCCEED;
}
-
+
+/*///////////////////////////// Joins /////////////////////////////*/
+str BWDjoinApproximate(int *ret, int *lid, int *rid ){
+ throw(MAL, "not implemented yet: %s", __func__);
+}
+
+str BWDjoinRefine(int *ret, int *lid, int *rid, bat* approx ){
+ throw(MAL, "not implemented yet: %s", __func__);
+}
+
+
+str BWDMulticolumnGroupApproximate(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci){
+ throw(MAL, "not implemented yet: %s", __func__);
+}
diff --git a/monetdb5/extras/bwd/opt_bwd.mal b/monetdb5/extras/bwd/opt_bwd.mal
--- a/monetdb5/extras/bwd/opt_bwd.mal
+++ b/monetdb5/extras/bwd/opt_bwd.mal
@@ -61,6 +61,7 @@ function filter{inline} (tupleIds:bat[:o
end filter;
+#################### Calc ####################
command multiplyapproximate(b1:bat[:oid,:any_1],b2:bat[:oid,:any_1])
:bat[:oid,:any_1]
address BWDBatMULsignalApproximate
comment "Return B1 * B2, signal error on overflow";
@@ -69,6 +70,59 @@ command multiplyrefine(b1:bat[:oid,:any_
address BWDBatMULsignalRefine
comment "Return B1 * B2, signal error on overflow";
+
+
+command addapproximate(b1:bat[:oid,:any_1],b2:bat[:oid,:any_1])
:bat[:oid,:any_1]
+address BWDBatADDsignalApproximate
+comment "Approximate B1 + B2, signal error on overflow";
+
+command addrefine(b1:bat[:oid,:any_1],b2:bat[:oid,:any_1],
approximation:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address BWDBatADDsignalRefine
+comment "Refine B1 + B2, signal error on overflow";
+
+
+command addapproximate(b1:any_1,b2:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address BWDBatADDsignalApproximate
+comment "Approximate B1 + B2, signal error on overflow";
+
+command addrefine(b1:any_1,b2:bat[:oid,:any_1],
approximation:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address BWDBatADDsignalRefine
+comment "Refine B1 + B2, signal error on overflow";
+
+
+
+
+pattern subtractapproximate(b1:bat[:oid,:any_1],b2:bat[:oid,:any_1])
:bat[:oid,:any_1]
+address BWDBatSUBsignalApproximate
+comment "Approximate B1 + B2, signal error on overflow";
+
+pattern subtractrefine(b1:bat[:oid,:any_1],b2:bat[:oid,:any_1],
approximation:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address BWDBatSUBsignalRefine
+comment "Refine B1 + B2, signal error on overflow";
+
+
+pattern subtractapproximate(b1:any_1, b2:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address BWDBatSUBsignalApproximate
+comment "Approximate B1 + B2, signal error on overflow";
+
+pattern subtractrefine(b1:any_1, b2:bat[:oid,:any_1],
approximation:bat[:oid,:any_1]) :bat[:oid,:any_1]
+address BWDBatSUBsignalRefine
+comment "Refine B1 + B2, signal error on overflow";
+
+
+#################### Selections ####################
+
+command joinapproximate( left:bat[:any_1,:any_2], right:bat[:any_2,:any_3])
+ :bat[:any_1,:any_3]
+address BWDjoinApproximate;
+
+command joinrefine( left:bat[:any_1,:any_2], right:bat[:any_2,:any_3],
approximation:bat[:any_1,:any_3])
+ :bat[:any_1,:any_3]
+address BWDjoinRefine;
+
+
+#################### Selections ####################
+
command selectNotNilapproximate(b:bat[:any_1,:any_2]):bat[:any_1,:any_2]
address BWDSelectNotNilApproximate
comment "Select all not-nil values";
@@ -86,6 +140,25 @@ command sumrefine (b:bat[:any_1,:int], a
address BWDSumRefine
comment "Gives the sum of all tail values.";
+command sumapproximate (b:bat[:oid,:int], g:bat[:oid,:oid],e:bat[:oid,:any_1])
:bat[:oid,:int]
+address BWDGroupedSumApproximate
+comment "Approximates the grouped sum of all tail values.";
+
+command sumrefine (b:bat[:oid,:int], g:bat[:oid,:oid],e:bat[:oid,:any_1],
approximation:bat[:oid,:int]) :bat[:oid,:int]
+address BWDGroupedSumRefine
+comment "Refines the grouped sum of all tail values.";
+
+
+pattern
multicolumnsapproximate(l:bat[:oid,:any]...)(grp:bat[:oid,:any],ext:bat[:oid,:any])
+address BWDMulticolumnGroupApproximate
+comment "Approximate a group index over multiple columns.";
+
+pattern
multicolumnsrefine(l:bat[:oid,:any]...)(grp:bat[:oid,:any],ext:bat[:oid,:any])
+address BWDMulticolumnGroupApproximate
+comment "Refine a group index over multiple columns. (interface should be more
like: l:bat[:oid,:any],...,grp:bat[:oid,:any],ext:bat[:oid,:any])";
+
+
+
pattern exportValue{unsafe}(qtype:int, tname:str, name:str, typename:str,
digits:int, scale:int, eclass:int, val:any_1, w:str):void
address bwd_export_value_wrap
comment "export a single value onto the stream s";
@@ -106,6 +179,10 @@ comment "Produces a BAT with fresh uniqu
the tail that starts at base (i.e. [base,..base+b.count()-1] )
and also propagates the head approximation";
+command mirror(b:bat[:any_1,:any_2]) :bat[:any_1,:any_1]
+address BWDmirror
+comment "Returns the head-mirror image of a BAT (two head columns) while
preserving the head approximation properties.";
+
pattern rsColumn{unsafe}(rs:int, tname:str, name:str, typename:str,
digits:int, scale:int, col:bat[:oid,:any_1] ) :void
address bwd_result_column_wrap
comment "Add the column to the approximate table query result";
diff --git a/monetdb5/extras/bwd/optimizer.c b/monetdb5/extras/bwd/optimizer.c
--- a/monetdb5/extras/bwd/optimizer.c
+++ b/monetdb5/extras/bwd/optimizer.c
@@ -13,7 +13,7 @@
#pragma mark Utility Functions
static inline const char* deoperatify(char* subject){
- static const char* operatorMapping[] = {"*", "multiply"};
+ static const char* operatorMapping[] = {"*", "multiply", "+", "add",
"-", "subtract"};
uint i;
for ( i = 0; i < sizeof(operatorMapping)/sizeof(operatorMapping[0]);
i+=2)
if (!strcmp(operatorMapping[i], subject))
@@ -37,7 +37,8 @@ static inline int OPTBWDImplementation(C
for (i = 0; i < instructionCount; ++i) {
////////////////////////////// propagate approximations
//////////////////////////////
if((oldProgram[i]->modname == batRef && oldProgram[i]->fcnname
== reverseRef) ||
- (oldProgram[i]->modname == algebraRef &&
oldProgram[i]->fcnname == markTRef)){
+ (oldProgram[i]->modname == algebraRef &&
oldProgram[i]->fcnname == markTRef) ||
+ (oldProgram[i]->modname == batRef &&
oldProgram[i]->fcnname == mirrorRef)){
InstrPtr approximationReverse;
approximations[getDestVar(oldProgram[i])] =
newTmpVariable(malBlock, getDestType(malBlock, oldProgram[i]));
approximationReverse = copyInstruction(oldProgram[i]);
@@ -46,6 +47,8 @@ static inline int OPTBWDImplementation(C
pushInstruction(malBlock, approximationReverse);
if(oldProgram[i]->modname == algebraRef &&
oldProgram[i]->fcnname == markTRef)
rename_function(approximationReverse, "bwd",
markTRef, &actions, client);
+ if(oldProgram[i]->modname == batRef &&
oldProgram[i]->fcnname == mirrorRef)
+ rename_function(approximationReverse, "bwd",
mirrorRef, &actions, client);
}
@@ -74,15 +77,16 @@ static inline int OPTBWDImplementation(C
setDestType(malBlock, approximateLeftjoin,
getArgType(malBlock, oldProgram[i], 2));
approximations[getDestVar(oldProgram[i])] =
approximations[getArg(oldProgram[i], 2)];
pushInstruction(malBlock, approximateLeftjoin);
- }else
- ////////////////////////////// rewrite operators
//////////////////////////////
- if(match_function(oldProgram[i], algebraRef, thetauselectRef)
+ }else if(match_function(oldProgram[i], algebraRef,
thetauselectRef)
|| oldProgram[i]->modname == batcalcRef
|| match_function(oldProgram[i], algebraRef,
uselectRef)
|| match_function(oldProgram[i], algebraRef,
semijoinRef)
|| match_function(oldProgram[i], algebraRef,
selectNotNilRef)
- || match_function(oldProgram[i], "aggr", "sum")
+ || match_function(oldProgram[i], groupRef,
multicolumnsRef)
+ || match_function(oldProgram[i], algebraRef, joinRef)
+ || match_function(oldProgram[i], aggrRef, sumRef)
|| match_function(oldProgram[i], algebraRef,
leftjoinRef)) {
+ ////////////////////////////// rewrite operators
//////////////////////////////
if (getTailType(getDestType(malBlock, oldProgram[i]))
== TYPE_lng){ //TODO: implement bwd for longs
if(isaBatType(getDestType(malBlock,
oldProgram[i])))
@@ -92,16 +96,21 @@ static inline int OPTBWDImplementation(C
}
- }
- approximations[getDestVar(oldProgram[i])] =
newTmpVariable(malBlock, getDestType(malBlock, oldProgram[i]));
+ }
+ {
+ int j = 0;
+ for (; j < oldProgram[i]->retc; ++j)
+ approximations[getArg(oldProgram[i],
j)] = newTmpVariable(malBlock, getArgType(malBlock, oldProgram[i], j));
+ }
{
InstrPtr approximateLeftjoin =
newInstruction(malBlock, ASSIGNsymbol);
char functionNameBuffer[512];
int j;
snprintf(functionNameBuffer, 512,
"%sapproximate", deoperatify(oldProgram[i]->fcnname));
rename_function(approximateLeftjoin, "bwd",
functionNameBuffer, (int[]){0}, client);
- setDestVar(approximateLeftjoin,
approximations[getDestVar(oldProgram[i])]);
- for (j = 1; j < oldProgram[i]->argc; ++j) {
+ for (j = 0; j < oldProgram[i]->retc; ++j)
+ approximateLeftjoin =
pushReturn(malBlock, approximateLeftjoin, approximations[getArg(oldProgram[i],
j)]);
+ for (; j < oldProgram[i]->argc; ++j) {
if(isaBatType(getArgType(malBlock,
oldProgram[i], j)))
approximateLeftjoin =
pushArgument(malBlock, approximateLeftjoin,
approximations[getArg(oldProgram[i], j)]);
else
@@ -116,10 +125,13 @@ static inline int OPTBWDImplementation(C
char functionNameBuffer[512];
snprintf(functionNameBuffer, 512, "%srefine",
deoperatify(oldProgram[i]->fcnname));
rename_function(refineLeftjoin, "bwd",
functionNameBuffer, (int[]){0}, client);
- setDestVar(refineLeftjoin,
getDestVar(oldProgram[i]));
- for (j = 1; j < oldProgram[i]->argc; ++j)
+ for (j = 0; j < oldProgram[i]->retc; ++j)
+ refineLeftjoin = pushReturn(malBlock,
refineLeftjoin, getArg(oldProgram[i], j));
+ for (; j < oldProgram[i]->argc; ++j)
refineLeftjoin = pushArgument(malBlock,
refineLeftjoin, getArg(oldProgram[i], j));
- refineLeftjoin = pushArgument(malBlock,
refineLeftjoin, approximations[getDestVar(oldProgram[i])]);
+ for (j = 0; j < oldProgram[i]->retc; ++j)
+ /* refineLeftjoin =
pushReturn(malBlock, refineLeftjoin, getArg(oldProgram[i], j)); */
+ refineLeftjoin = pushArgument(malBlock,
refineLeftjoin, approximations[getArg(oldProgram[i], j)]);
pushInstruction(malBlock, refineLeftjoin);
}
} else {
diff --git a/monetdb5/extras/bwd/pusher.c b/monetdb5/extras/bwd/pusher.c
--- a/monetdb5/extras/bwd/pusher.c
+++ b/monetdb5/extras/bwd/pusher.c
@@ -46,7 +46,8 @@ static inline int OPTBWDPusherImplementa
variableProducers[k] = 0;
}
- pushInstruction(malBlock, oldProgram[i++]);
+ if(i < instructionCount)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list