Changeset: 830f5b42c2a3 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=830f5b42c2a3 Modified Files: monetdb5/optimizer/opt_origin.mx Branch: default Log Message:
Property collection We should be more aggressive in collecting properties for optimization. This is an example how it could be done, it will be extended as we move on. All variables become tagged with a reference to the underlying persistent relational table/attribute. diffs (145 lines): diff --git a/monetdb5/optimizer/opt_origin.mx b/monetdb5/optimizer/opt_origin.mx new file mode 100644 --- /dev/null +++ b/monetdb5/optimizer/opt_origin.mx @@ -0,0 +1,140 @@ +@/ +The contents of this file are subject to the MonetDB Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is the MonetDB Database System. + +The Initial Developer of the Original Code is CWI. +Portions created by CWI are Copyright (C) 1997-July 2008 CWI. +Copyright August 2008-2011 MonetDB B.V. +All Rights Reserved. +@ + +@f opt_origin +@- OID origin tracking. +This simple module extends the MAL plan with properties that +identify the source of OIDs in the underlying SQL persistent tables. +It stops when it can not be unique pinpointed anymore. +The information is kept with the variables as horigin and torigin. +[still incomplete] +@{ +@mal +pattern optimizer.origin():str +address OPTorigin; +pattern optimizer.origin(mod:str, fcn:str):str +address OPTorigin +comment "OID origin tracker"; +@h +#ifndef _OPT_ORIGIN_ +#define _OPT_ORIGIN_ +#include "opt_prelude.h" +#include "opt_support.h" +#include "mal_interpreter.h" +#include "mal_instruction.h" +#include "mal_function.h" + +@:exportOptimizer(origin)@ + +#undef DEBUG_OPT_ORIGIN +#define DEBUG_OPT_ORIGIN 1 +#define _DEBUG_OPT_ORIGIN_ +#define OPTDEBUGorigin if ( optDebug & (1 <<DEBUG_OPT_ORIGIN) ) + +#endif +@c +#include "monetdb_config.h" +#include "opt_origin.h" + +static int +OPToriginImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + int i; + InstrPtr p=0; + int actions = 0; + char buf[BUFSIZ]; + ValRecord val; + VarPtr h, t; + + (void) pci; + (void) stk; /* to fool compilers */ + + for (i = 1; i < mb->stop; i++) { + p= getInstrPtr(mb,i); + + val.vtype = TYPE_int; + if( getModuleId(p)== sqlRef && getFunctionId(p)== bindRef && + isVarConstant(mb,getArg(p,2)) && isVarConstant(mb,getArg(p,3)) && isVarConstant(mb,getArg(p,4)) ) { + snprintf(buf, BUFSIZ, "%s_%s_%s", getVarConstant(mb,getArg(p,2)).val.sval, getVarConstant(mb,getArg(p,3)).val.sval,getVarConstant(mb,getArg(p,4)).val.sval); + actions++; + VALset(&val, TYPE_str, GDKstrdup(buf)); + varSetProp(mb, getArg(p,0), horiginProp, op_eq, &val); +#ifdef _DEBUG_OPT_ORIGIN_ + mnstr_printf(cntxt->fdout,"#%s\n",buf); + printInstruction(cntxt->fdout,mb, 0, p, LIST_MAL_ALL); +#endif + } + if ( getModuleId(p) == algebraRef) { + if ( getFunctionId(p) == kunionRef) { + h= varGetProp(mb, getArg(p,1), horiginProp); + t= varGetProp(mb, getArg(p,2), horiginProp); + if ( strcmp(h->value.val.sval, t->value.val.sval) == 0) { + VALset(&val, TYPE_str, GDKstrdup(h->value.val.sval)); + varSetProp(mb, getArg(p,0), horiginProp, op_eq, &val); + } + } + if ( getFunctionId(p) == kdifferenceRef) { + h= varGetProp(mb, getArg(p,1), horiginProp); + if ( h ) { + VALset(&val, TYPE_str, GDKstrdup(h->value.val.sval)); + varSetProp(mb, getArg(p,0), horiginProp, op_eq, &val); + } + } + if ( getFunctionId(p) == thetauselectRef) { + h= varGetProp(mb, getArg(p,1), horiginProp); + t= varGetProp(mb, getArg(p,1), toriginProp); + if ( h ) { + VALset(&val, TYPE_str, GDKstrdup(h->value.val.sval)); + varSetProp(mb, getArg(p,0), horiginProp, op_eq, &val); + } + if ( t) + {} + } + if ( getFunctionId(p) == markTRef) { + h= varGetProp(mb, getArg(p,1), horiginProp); + if ( h ){ + VALset(&val, TYPE_str, GDKstrdup(h->value.val.sval)); + varSetProp(mb, getArg(p,0), horiginProp, op_eq, &val); + } + } + } + if ( getModuleId(p) == batRef) { + if ( getFunctionId(p) == reverseRef) { + h= varGetProp(mb, getArg(p,1), horiginProp); + t= varGetProp(mb, getArg(p,1), toriginProp); + if ( h ){ + VALset(&val, TYPE_str, GDKstrdup(h->value.val.sval)); + varSetProp(mb, getArg(p,0), toriginProp, op_eq, &val); + } + if ( t ) { + VALset(&val, TYPE_str, GDKstrdup(t->value.val.sval)); + varSetProp(mb, getArg(p,0), horiginProp, op_eq, &val); + } + } + } + } + DEBUGoptimizers + mnstr_printf(cntxt->fdout,"#opt_origin: %d statements marked\n", actions); + return actions; +} +@include optimizerWrapper.mx +@c +#include "opt_statistics.h" +@:wrapOptimizer(origin,OPT_CHECK_ALL)@ +@} _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list