| 1 | /* |
| 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | * |
| 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Collect properties for beautified variable rendering |
| 11 | * All variables are tagged with the schema.table.column name if possible. |
| 12 | */ |
| 13 | |
| 14 | #include "monetdb_config.h" |
| 15 | #include "mal_instruction.h" |
| 16 | #include "opt_prelude.h" |
| 17 | #include "opt_profiler.h" |
| 18 | |
| 19 | str |
| 20 | OPTprofilerImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) |
| 21 | { |
| 22 | int i; |
| 23 | InstrPtr p; |
| 24 | char buf[BUFSIZ]; |
| 25 | lng usec = GDKusec(); |
| 26 | |
| 27 | (void) pci; |
| 28 | (void) stk; |
| 29 | (void) cntxt; |
| 30 | |
| 31 | for( i=0; i< mb->stop; i++){ |
| 32 | p= getInstrPtr(mb,i); |
| 33 | if( p == NULL) |
| 34 | continue; |
| 35 | if ( getModuleId(p) == NULL || getFunctionId(p) == NULL) |
| 36 | continue; |
| 37 | if( getModuleId(p)== sqlRef && (getFunctionId(p)== bindRef || getFunctionId(p) == bindidxRef)){ |
| 38 | getVarSTC(mb,getArg(p,0)) = i; |
| 39 | } else |
| 40 | if( getModuleId(p)== sqlRef && getFunctionId(p)== tidRef){ |
| 41 | getVarSTC(mb,getArg(p,0)) = i; |
| 42 | } else |
| 43 | if( getModuleId(p)== sqlRef && (getFunctionId(p)== deltaRef || getFunctionId(p) == subdeltaRef)){ |
| 44 | // inherit property of first argument |
| 45 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,1)); |
| 46 | } else |
| 47 | if( getModuleId(p)== sqlRef && getFunctionId(p)== projectdeltaRef){ |
| 48 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,1)); |
| 49 | } else |
| 50 | if( getModuleId(p)== algebraRef && getFunctionId(p)== projectionRef){ |
| 51 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,p->argc-1)); |
| 52 | } else |
| 53 | if( getModuleId(p)== algebraRef && |
| 54 | (getFunctionId(p)== selectRef || |
| 55 | getFunctionId(p) == thetaselectRef || |
| 56 | getFunctionId(p) == selectNotNilRef) ){ |
| 57 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,p->retc)); |
| 58 | } else |
| 59 | if( getModuleId(p)== algebraRef && (getFunctionId(p)== likeselectRef || getFunctionId(p) == ilikeselectRef)){ |
| 60 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,p->retc)); |
| 61 | } else |
| 62 | if( getModuleId(p)== algebraRef && |
| 63 | ( getFunctionId(p)== joinRef || |
| 64 | getFunctionId(p) == leftjoinRef || |
| 65 | getFunctionId(p) == thetajoinRef || |
| 66 | getFunctionId(p) == antijoinRef || |
| 67 | getFunctionId(p) == bandjoinRef || |
| 68 | getFunctionId(p) == rangejoinRef )){ |
| 69 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,p->retc)); |
| 70 | getVarSTC(mb,getArg(p,1)) = getVarSTC(mb,getArg(p,p->retc +1)); |
| 71 | } else |
| 72 | if( getModuleId(p)== matRef && getFunctionId(p)== packIncrementRef){ |
| 73 | getVarSTC(mb,getArg(p,0)) = getVarSTC(mb,getArg(p,1)); |
| 74 | } |
| 75 | } |
| 76 | /* Defense line against incorrect plans */ |
| 77 | /* Plan remains unaffected */ |
| 78 | //chkTypes(cntxt->usermodule, mb, FALSE); |
| 79 | //chkFlow(mb); |
| 80 | //chkDeclarations(mb); |
| 81 | |
| 82 | /* keep all actions taken as a post block comment */ |
| 83 | usec = GDKusec()- usec; |
| 84 | snprintf(buf,256,"%-20s actions= 1 time=" LLFMT " usec" ,"profiler" , usec); |
| 85 | newComment(mb,buf); |
| 86 | addtoMalBlkHistory(mb); |
| 87 | if( OPTdebug & OPTprofiler){ |
| 88 | fprintf(stderr, "#PROFILER optimizer exit\n" ); |
| 89 | fprintFunction(stderr, mb, 0, LIST_MAL_ALL); |
| 90 | } |
| 91 | return MAL_SUCCEED; |
| 92 | } |
| 93 | |