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