LCOV - code coverage report
Current view: top level - monetdb5/optimizer - optimizer.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 21 42.9 %
Date: 2021-10-13 02:24:04 Functions: 3 4 75.0 %

          Line data    Source code
       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 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /* Author(s) Martin Kersten
      10             :  * This module contains the framework for inclusion query transformers, i.e.
      11             :  * C-programs geared at optimizing a piece of MAL.
      12             :  * The query transformer appears at the language level as an ordinary function,
      13             :  * but it is effective only at a specific execution phase.
      14             :  *
      15             :  * Each optimizer function has access to the runtime scope of the
      16             :  * routine in which it is called. This can be used to maintain status
      17             :  * information between successive calls.
      18             :  *
      19             :  * The routines below are linked with the kernel by default
      20             : */
      21             : #include "monetdb_config.h"
      22             : #include "optimizer.h"
      23             : #include "mal_debugger.h"
      24             : #include "optimizer_private.h"
      25             : #include "opt_pipes.h"
      26             : 
      27             : /*
      28             :  * Upon loading the module it should inspect the scenario table
      29             :  * for any unresolved references to the MALoptimizer and set the
      30             :  * callback function.
      31             : */
      32             : str
      33         266 : optimizer_prelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
      34             : {
      35             :         (void) cntxt;
      36             :         (void) stk;
      37             :         (void) mb;
      38             :         (void) p;
      39         266 :         updateScenario("mal", "MALoptimizer", (MALfcn) MALoptimizer);
      40         266 :         optimizerInit();
      41             :         //return compileAllOptimizers(cntxt); causes problems
      42         266 :         return MAL_SUCCEED;
      43             : }
      44             : 
      45             : str
      46         264 : optimizer_epilogue(void *ret)
      47             : {
      48             :         (void)ret;
      49         264 :         opt_pipes_reset();
      50         264 :         return MAL_SUCCEED;
      51             : }
      52             : 
      53             : /*
      54             :  * MAL functions can be optimized explicitly using the routines below.
      55             :  * Beware, the function names should be known as literal strings, because
      56             :  * you may not know the runtime situation.
      57             : */
      58             : 
      59             : str
      60           0 : QOToptimize(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      61             : {
      62             :         str modnme;
      63             :         str fcnnme;
      64             :         Symbol s;
      65             : 
      66             :         (void) stk;
      67           0 :         if (stk != 0) {
      68           0 :                 modnme = *getArgReference_str(stk, pci, 1);
      69           0 :                 fcnnme = *getArgReference_str(stk, pci, 2);
      70             :         } else {
      71           0 :                 modnme = getArgDefault(mb, pci, 1);
      72           0 :                 fcnnme = getArgDefault(mb, pci, 2);
      73             :         }
      74           0 :         s = findSymbol(cntxt->usermodule, putName(modnme), fcnnme);
      75           0 :         if (s == NULL)
      76           0 :                 throw(MAL, "optimizer.optimize", SQLSTATE(HY002) SEMANTIC_OPERATION_MISSING);
      77           0 :         removeInstruction(mb, pci);
      78           0 :         addtoMalBlkHistory(s->def);
      79           0 :         return optimizeMALBlock(cntxt, s->def);
      80             : }
      81             : 
      82             : #include "opt_macro.h"
      83             : 
      84             : #define optwrapper_pattern(NAME, DESC) \
      85             :         pattern("optimizer", NAME, OPTwrapper, false, "", args(1,1, arg("",str))), \
      86             :         pattern("optimizer", NAME, OPTwrapper, false, DESC, args(1,3, arg("",str),arg("mod",str),arg("fcn",str)))
      87             : 
      88             : 
      89             : #include "mel.h"
      90             : static mel_func optimizer_init_funcs[] = {
      91             :  optwrapper_pattern("aliases", "Alias removal optimizer"),
      92             :  optwrapper_pattern("bincopyfrom", "Parallellize column loading"),
      93             :  optwrapper_pattern("coercions", "Handle simple type coercions"),
      94             :  optwrapper_pattern("commonTerms", "Common sub-expression optimizer"),
      95             :  optwrapper_pattern("candidates", "Mark candidate list variables"),
      96             :  optwrapper_pattern("volcano", "Simulate volcano style execution"),
      97             :  optwrapper_pattern("constants", "Duplicate constant removal optimizer"),
      98             :  optwrapper_pattern("profiler", "Collect properties for the profiler"),
      99             :  optwrapper_pattern("costModel", "Estimate the cost of a relational expression"),
     100             :  optwrapper_pattern("dataflow", "Dataflow bracket code injection"),
     101             :  optwrapper_pattern("deadcode", "Dead code optimizer"),
     102             :  optwrapper_pattern("emptybind", "Evaluate empty set expressions"),
     103             :  optwrapper_pattern("jit", "Propagate candidate lists in just-in-time optimization"),
     104             :  optwrapper_pattern("evaluate", "Evaluate constant expressions once"),
     105             :  optwrapper_pattern("garbageCollector", "Garbage collector optimizer"),
     106             :  optwrapper_pattern("generator", "Sequence generator optimizer"),
     107             :  optwrapper_pattern("querylog", "Collect SQL query statistics"),
     108             :  optwrapper_pattern("minimalfast", "Fast compound minimal optimizer pipe"),
     109             :  optwrapper_pattern("defaultfast", "Fast compound default optimizer pipe"),
     110             :  optwrapper_pattern("wrapper", "Fake optimizer"),
     111             :  pattern("optimizer", "prelude", optimizer_prelude, false, "Initialize the optimizer", noargs),
     112             :  command("optimizer", "epilogue", optimizer_epilogue, false, "release the resources held by the optimizer module", args(1,1, arg("",void))),
     113             :  pattern("optimizer", "optimize", QOToptimize, false, "Optimize a specific operation", args(0,2, arg("mod",str),arg("fcn",str))),
     114             :  optwrapper_pattern("inline", "Expand inline functions"),
     115             :  optwrapper_pattern("projectionpath", "Join path constructor"),
     116             :  pattern("optimizer", "macro", OPTmacro, false, "Inline the code of the target function.", args(1,3, arg("",void),arg("targetmod",str),arg("targetfcn",str))),
     117             :  pattern("optimizer", "macro", OPTmacro, false, "Inline a target function used in a specific function.", args(1,5, arg("",void),arg("mod",str),arg("fcn",str),arg("targetmod",str),arg("targetfcn",str))),
     118             :  pattern("optimizer", "orcam", OPTorcam, false, "Inverse macro processor for current function", args(1,3, arg("",void),arg("targetmod",str),arg("targetfcn",str))),
     119             :  pattern("optimizer", "orcam", OPTorcam, false, "Inverse macro, find pattern and replace with a function call.", args(1,5, arg("",void),arg("mod",str),arg("fcn",str),arg("targetmod",str),arg("targetfcn",str))),
     120             :  optwrapper_pattern("mergetable", "Resolve the multi-table definitions"),
     121             :  optwrapper_pattern("mitosis", "Modify the plan to exploit parallel processing on multiple cores"),
     122             :  optwrapper_pattern("multiplex", "Compiler for multiplexed instructions"),
     123             :  optwrapper_pattern("matpack", "Unroll the mat.pack operation"),
     124             :  optwrapper_pattern("json", "Unroll the mat.pack operation"),
     125             :  optwrapper_pattern("reduce", "Reduce the stack space claims"),
     126             :  optwrapper_pattern("remap", "Remapping function calls to a their multiplex variant"),
     127             :  optwrapper_pattern("remoteQueries", "Resolve the multi-table definitions"),
     128             :  optwrapper_pattern("reorder", "Reorder by dataflow dependencies"),
     129             :  pattern("inspect", "optimizer_stats", OPTstatistics, false, "Get optimizer use statistics, i.e. calls and total time", args(3,3, batarg("",str),batarg("",int),batarg("",lng))),
     130             :  optwrapper_pattern("pushselect", "Push selects down projections"),
     131             :  optwrapper_pattern("oltp", "Inject the OLTP locking primitives"),
     132             :  optwrapper_pattern("wlc", "Inject the workload capture-replay primitives"),
     133             :  optwrapper_pattern("postfix", "Postfix the plan,e.g. pushing projections"),
     134             :  pattern("optimizer", "mask", OPTwrapper, false, "", args(1,1, arg("",str))),
     135             :  pattern("optimizer", "mask", OPTwrapper, false, "Manipulate the MSK objects", args(1,3, arg("",str),arg("mod",str),arg("fcn",str))),
     136             :  { .imp=NULL }
     137             : };
     138             : #include "mal_import.h"
     139             : #ifdef _MSC_VER
     140             : #undef read
     141             : #pragma section(".CRT$XCU",read)
     142             : #endif
     143         259 : LIB_STARTUP_FUNC(init_optimizer_mal)
     144         259 : { mal_module("optimizer", NULL, optimizer_init_funcs); }

Generated by: LCOV version 1.14