📄 opt_emptyset.c
字号:
#line 94 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"#include "mal_config.h"#include "opt_emptySet.h"#include "opt_aliases.h"#include "opt_deadcode.h"#include "mal_interpreter.h" /* for showErrors() */#include "mal_builder.h"#define propagate(X) {p->token= ASSIGNsymbol; setVarUsed(mb,getArg(p,1),TRUE); \ getArg(p,1)= getArg(p,X); p->argc = 2; p->fcn = 0; actions++;\ p->typechk=TYPE_UNKNOWN; p->fcn= NULL; \ if(getArgType(mb,p,0)== getArgType(mb,p,X)){\ setModuleId(p,NULL); setFunctionId(p,NULL); } \ else {actions++;setModuleId(p,NULL); setFunctionId(p,NULL); alias[getArg(p,0)]= getArg(p,1); } }#line 111 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"static intESevaluate(MalBlkPtr mb, char *empty){ int i, j, actions = 0; InstrPtr p; str likeRef = getName("like", 4); str existRef = getName("exist", 5); str uniqueRef = getName("unique", 6); str suniqueRef = getName("sunique", 7); str kuniqueRef = getName("kunique", 7); str intersectRef = getName("intersect", 9); str sintersectRef = getName("sintersect", 10); str kintersectRef = getName("kintersect", 10); str fragmentRef = getName("fragment", 8); int *alias; int limit = mb->stop, ctop=0; InstrPtr *old = mb->stmt, *constraints; newMalBlkStmt(mb, mb->stop); /* a new statement stack */ constraints= (InstrPtr *) alloca(sizeof(InstrPtr)*limit); alias = (int*) alloca(sizeof(int)*mb->vtop); for(i=0;i<mb->vtop; i++) alias[i]=i; /* Symbolic evaluation of the empty BAT variables */ /* by looking at empty BAT arguments */ for (i = 0; i < limit; i++) { char *f; p = old[i]; pushInstruction(mb,p); if( p->token == ENDsymbol){ for(i++; i<limit; i++) pushInstruction(mb,old[i]); break; } for(j=0; j<p->argc; j++) p->argv[j]= alias[getArg(p,j)];#line 154 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx" f = getFunctionId(p); if (getModuleId(p) == sqlRef && empty[getArg(p,0)] && (f == bindRef || f == bindidxRef || f == binddbatRef)){ InstrPtr q;#line 163 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx" if( f == bindRef) { for( j=ctop-1; j>=0; j--){ q= constraints[j]; if( strcmp(getVarConstant(mb,getArg(q,1)).val.sval, getVarConstant(mb,getArg(p,1)).val.sval)==0 && strcmp(getVarConstant(mb,getArg(q,2)).val.sval, getVarConstant(mb,getArg(p,2)).val.sval)==0 && getVarConstant(mb,getArg(p,4)).val.ival<=2 && /* no updates etc */ getVarConstant(mb,getArg(q,4)).val.ival == getVarConstant(mb,getArg(p,4)).val.ival ) /* don't generate the assertion */ goto ignoreConstraint; } q = newStmt1(mb, constraintsRef, "emptySet"); q = pushArgument(mb, q, getArg(p,0) ); constraints[ctop++]= p; } ignoreConstraint: continue; } for (j = p->retc; j < p->argc; j++) { if (empty[getArg(p, j)]) { /* decode operations */ if (getModuleId(p)== algebraRef) { if (f == existRef) { /* always false */ setModuleId(p, NULL); setFunctionId(p, NULL); p->argc = 1; p->token = ASSIGNsymbol; pushBit(mb, p, FALSE); actions++; break; } if ( f == selectRef || f == tuniqueRef || f == likeRef || f == sortRef || f == sortTailRef || f == sortHTRef || f == sortTHRef || f == uniqueRef || f == suniqueRef || f == kuniqueRef || f == intersectRef || f == semijoinRef || f == sintersectRef || f == kintersectRef || f == fragmentRef ){ /* result is empty */ propagate(1); break; } if ( f == differenceRef || f == kdifferenceRef ) { propagate(1); break; } if ( f == sunionRef || f == kunionRef || f == unionRef) { /* copy non-empty argument */ if( j == 1) { propagate(2); } else { propagate(1); } break; } } } } } GDKfree(old); if( actions) { clrAllTypes(mb); /* force a complete resolve */ }#ifdef DEBUG_OPT_EMPTYSET printf("FINAL STAGE errors=%d\n", mb->errors); printFunction(GDKout, mb, LIST_MAL_ALL);#endif return actions;}#line 253 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"intOPTemptySetImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ char *empty; int i; int *rows; PropertySet ps; empty = (char *) alloca(mb->vsize * sizeof(char)); memset(empty,0,mb->vsize); (void) stk; (void) p;#ifdef DEBUG_OPT_EMPTYSET printf("ESoptimizer called, collect empty sets and process them\n"); printFunction(GDKout, mb, LIST_MAL_ALL);#endif for (i = 0; i < mb->vtop; i++) { ps = getVarProperties(mb, i); if ( (rows= (int*) getPropertyValue(ps, "rows")) && *rows == 0) {#ifdef DEBUG_OPT_EMPTYSET stream_printf(GDKout, "START emptyset optimizer %d", i);#endif empty[i] = 1; } }#ifdef DEBUG_OPT_EMPTYSET stream_printf(GDKout, "\n");#endif return ESevaluate(mb, empty);}#line 289 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"#line 287 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"/* #define _DEBUG_OPTIMIZER_*/str OPTemptySet(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ str modnme; str fcnnme; Module scope=NULL; Symbol s= NULL; lng clk= GDKusec(); int actions = 0; optimizerInit(); if( p ) removeInstruction(mb, p);#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"apply emptySet\n"); printFunction(GDKout,mb,LIST_MAL_ALL);#endif if( p && p->argc > 1 && getFunctionId(p) != multiplexRef){#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"locate function emptySet\n");#endif if( getArgType(mb,p,1) != TYPE_str || getArgType(mb,p,2) != TYPE_str || !isConstant(mb,getArg(p,1)) || !isConstant(mb,getArg(p,2)) ) { char buf[1024]; snprintf(buf,1024, "Optimizer requires constant string arguments\n"); throw(MAL, "optimizer.emptySet",buf); } if( stk != 0){ modnme= (str)getArgValue(stk,p,1); fcnnme= (str)getArgValue(stk,p,2); } else { modnme= getArgDefault(mb,p,1); fcnnme= getArgDefault(mb,p,2); } scope = findModule(MCgetClient()->nspace,putName(modnme,strlen(modnme)) ); if( scope) s= findSymbolInModule(scope,putName(fcnnme,strlen(fcnnme))); if( s == NULL) { char buf[1024]; snprintf(buf,1024, "Could not find %s.%s\n",modnme,fcnnme); throw(MAL, "optimizer.emptySet",buf); }#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"emptySet %s %d\n",modnme,fcnnme);#endif mb = s->def; stk= 0; } if( mb->errors ) return MAL_SUCCEED; addtoMalBlkHistory(mb); actions= OPTemptySetImplementation(mb,stk,p);#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"finished emptySet %d\n",actions); printFunction(GDKout,mb,LIST_MAL_ALL);#endif optimizerCheck(mb, "optimizer.emptySet", actions, GDKusec() - clk,OPT_CHECK_ALL); return MAL_SUCCEED;}#line 289 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"#line 291 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_emptySet.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -