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 | * Mark the production and use of candidate lists. |
11 | */ |
12 | |
13 | #include "monetdb_config.h" |
14 | #include "mal_instruction.h" |
15 | #include "opt_candidates.h" |
16 | |
17 | str |
18 | OPTcandidatesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) |
19 | { |
20 | int i; |
21 | InstrPtr p; |
22 | char buf[256]; |
23 | lng usec = GDKusec(); |
24 | |
25 | (void) pci; |
26 | (void) cntxt; |
27 | (void) stk; /* to fool compilers */ |
28 | for (i = 0; i < mb->stop; i++) { |
29 | p = getInstrPtr(mb,i); |
30 | if( p->token == ASSIGNsymbol) { |
31 | int j; |
32 | for (j = 0; j < p->retc && j + p->retc < p->argc; j++) |
33 | if (isVarCList(mb,getArg(p,p->retc + j))) |
34 | setVarCList(mb,getArg(p,j)); |
35 | } |
36 | if( getModuleId(p) == sqlRef){ |
37 | if(getFunctionId(p) == tidRef) |
38 | setVarCList(mb,getArg(p,0)); |
39 | else if(getFunctionId(p) == subdeltaRef) |
40 | setVarCList(mb,getArg(p,0)); |
41 | } |
42 | else if( getModuleId(p) == algebraRef ){ |
43 | if(getFunctionId(p) == selectRef || getFunctionId(p) == thetaselectRef) |
44 | setVarCList(mb,getArg(p,0)); |
45 | else if(getFunctionId(p) == likeselectRef || getFunctionId(p) == likethetaselectRef) |
46 | setVarCList(mb,getArg(p,0)); |
47 | else if(getFunctionId(p) == intersectRef || getFunctionId(p) == differenceRef ) |
48 | setVarCList(mb,getArg(p,0)); |
49 | else if(getFunctionId(p) == uniqueRef ) |
50 | setVarCList(mb,getArg(p,0)); |
51 | else if(getFunctionId(p) == firstnRef ) |
52 | setVarCList(mb,getArg(p,0)); |
53 | else if(getFunctionId(p) == subsliceRef ) |
54 | setVarCList(mb,getArg(p,0)); |
55 | else if (getFunctionId(p) == projectionRef && |
56 | isVarCList(mb,getArg(p,p->retc + 0)) && |
57 | isVarCList(mb,getArg(p,p->retc + 1))) |
58 | setVarCList(mb,getArg(p,0)); |
59 | } |
60 | else if( getModuleId(p) == generatorRef){ |
61 | if(getFunctionId(p) == selectRef || getFunctionId(p) == thetaselectRef) |
62 | setVarCList(mb,getArg(p,0)); |
63 | } |
64 | else if (getModuleId(p) == sampleRef) { |
65 | if (getFunctionId(p) == subuniformRef) |
66 | setVarCList(mb, getArg(p, 0)); |
67 | } |
68 | else if (getModuleId(p) == groupRef && p->retc > 1) { |
69 | if (getFunctionId(p) == subgroupRef || getFunctionId(p) == subgroupdoneRef || |
70 | getFunctionId(p) == groupRef || getFunctionId(p) == groupdoneRef) |
71 | setVarCList(mb, getArg(p, 1)); |
72 | } else if (getModuleId(p) == batRef) { |
73 | if (getFunctionId(p) == mergecandRef || |
74 | getFunctionId(p) == intersectcandRef || |
75 | getFunctionId(p) == diffcandRef || |
76 | getFunctionId(p) == mirrorRef) |
77 | setVarCList(mb,getArg(p,0)); |
78 | } |
79 | } |
80 | |
81 | /* Defense line against incorrect plans */ |
82 | /* plan remains unaffected */ |
83 | //chkTypes(cntxt->usermodule, mb, FALSE); |
84 | //chkFlow(mb); |
85 | //chkDeclarations(mb); |
86 | |
87 | /* keep all actions taken as a post block comment */ |
88 | usec = GDKusec()- usec; |
89 | snprintf(buf,256,"%-20s actions= 1 time=" LLFMT " usec" ,"candidates" ,usec); |
90 | newComment(mb,buf); |
91 | addtoMalBlkHistory(mb); |
92 | if( OPTdebug & OPTaliases){ |
93 | fprintf(stderr, "#CANDIDATES optimizer exit\n" ); |
94 | fprintFunction(stderr, mb, 0, LIST_MAL_ALL); |
95 | } |
96 | return MAL_SUCCEED; |
97 | } |
98 | |