LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_oltp.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 71 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 2 0.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 M.Kersten
      10             :  * This optimizer prepares a MAL block for delayed locking
      11             :  * The objects are mapped to a fixed hash table to speedup testing later.
      12             :  * We don't need the actual name of the objects
      13             :  */
      14             : #include "monetdb_config.h"
      15             : #include "opt_oltp.h"
      16             : 
      17             : static void
      18           0 : addLock(Client cntxt, OLTPlocks locks, MalBlkPtr mb, InstrPtr p, int sch, int tbl)
      19             : {       BUN hash;
      20             :         char *r,*s;
      21             : 
      22             :         (void) cntxt;
      23           0 :         r =(sch?getVarConstant(mb, getArg(p,sch)).val.sval : "sqlcatalog");
      24           0 :         s =(tbl? getVarConstant(mb, getArg(p,tbl)).val.sval : "");
      25           0 :         hash = (strHash(r)  ^ strHash(s)) % MAXOLTPLOCKS ;
      26           0 :         hash += (hash == 0);
      27           0 :         locks[hash] = 1;
      28           0 : }
      29             : 
      30             : str
      31           0 : OPToltpImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      32             : {       int i, limit, slimit, updates=0;
      33             :         InstrPtr p, q, lcks;
      34             :         int actions = 0;
      35             :         InstrPtr *old;
      36             :         OLTPlocks wlocks, rlocks;
      37             :         str msg = MAL_SUCCEED;
      38             : 
      39             :         (void) cntxt;
      40             :         (void) stk;             /* to fool compilers */
      41             : 
      42           0 :         old= mb->stmt;
      43           0 :         limit= mb->stop;
      44           0 :         slimit = mb->ssize;
      45             : 
      46             :         // We use a fake collection of objects to speed up the checking later.
      47           0 :         OLTPclear(wlocks);
      48           0 :         OLTPclear(rlocks);
      49             : 
      50           0 :         for (i = 0; i < limit; i++) {
      51           0 :                 p = old[i];
      52           0 :                 if( getModuleId(p) == sqlRef && getFunctionId(p) == bindRef)
      53           0 :                         addLock(cntxt,rlocks, mb, p, p->retc + 1, p->retc + 2);
      54             :                 else
      55           0 :                 if( getModuleId(p) == sqlRef && getFunctionId(p) == bindidxRef)
      56           0 :                         addLock(cntxt,rlocks, mb, p, p->retc + 1, p->retc + 2);
      57             :                 else
      58           0 :                 if( getModuleId(p) == sqlRef && getFunctionId(p) == appendRef ){
      59           0 :                         addLock(cntxt,wlocks, mb, p, p->retc + 1, p->retc + 2);
      60           0 :                         updates++;
      61             :                 } else
      62           0 :                 if( getModuleId(p) == sqlRef && getFunctionId(p) == updateRef ){
      63           0 :                         addLock(cntxt,wlocks, mb, p, p->retc + 1, p->retc + 2);
      64           0 :                         updates++;
      65             :                 } else
      66           0 :                 if( getModuleId(p) == sqlRef && getFunctionId(p) == deleteRef ){
      67           0 :                         addLock(cntxt,wlocks, mb, p, p->retc + 1, p->retc + 2);
      68           0 :                         updates++;
      69             :                 } else
      70           0 :                 if( getModuleId(p) == sqlcatalogRef ){
      71           0 :                         addLock(cntxt,wlocks, mb, p, 0,0);
      72           0 :                         updates++;
      73             :                 }
      74             :         }
      75             : 
      76           0 :         if( updates == 0)
      77             :                 return 0;
      78             : 
      79             :         // Get a free instruction, don't get it from mb
      80           0 :         lcks= newInstruction(0, oltpRef,lockRef);
      81           0 :         getArg(lcks,0)= newTmpVariable(mb, TYPE_void);
      82             : 
      83           0 :         for( i = 0; i< MAXOLTPLOCKS; i++)
      84           0 :         if( wlocks[i])
      85           0 :                 lcks = pushInt(mb, lcks, i);
      86             :         else
      87           0 :         if( rlocks[i])
      88           0 :                 lcks = pushInt(mb, lcks, -i);
      89             : 
      90           0 :         if( lcks->argc == 1 ){
      91           0 :                 freeInstruction(lcks);
      92           0 :                 return MAL_SUCCEED;
      93             :         }
      94             : 
      95             :         // Now optimize the code
      96           0 :         if ( newMalBlkStmt(mb,mb->ssize + 6) < 0) {
      97           0 :                 freeInstruction(lcks);
      98           0 :                 return 0;
      99             :         }
     100           0 :         pushInstruction(mb,old[0]);
     101           0 :         pushInstruction(mb,lcks);
     102           0 :         for (i = 1; i < limit; i++) {
     103           0 :                 p = old[i];
     104           0 :                 if( p->token == ENDsymbol){
     105             :                         // unlock all if there is an error
     106           0 :                         q= newCatchStmt(mb,"MALException");
     107           0 :                         q= newExitStmt(mb,"MALException");
     108           0 :                         q= newCatchStmt(mb,"SQLException");
     109           0 :                         q= newExitStmt(mb,"SQLException");
     110           0 :                         q= copyInstruction(lcks);
     111           0 :                         if( q == NULL){
     112           0 :                                 for(; i<slimit; i++)
     113           0 :                                         if( old[i])
     114           0 :                                                 freeInstruction(old[i]);
     115           0 :                                 GDKfree(old);
     116           0 :                                 throw(MAL,"optimizer.oltp", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     117             :                         }
     118           0 :                         setFunctionId(q, releaseRef);
     119           0 :                         pushInstruction(mb,q);
     120             :                 }
     121           0 :                 pushInstruction(mb,p);
     122             :         }
     123           0 :         for(; i<slimit; i++)
     124           0 :                 if( old[i])
     125           0 :                         pushInstruction(mb, old[i]);
     126           0 :         GDKfree(old);
     127             : 
     128             :         /* Defense line against incorrect plans */
     129           0 :         msg = chkTypes(cntxt->usermodule, mb, FALSE);
     130             :         //if (!msg)
     131             :         //      msg = chkFlow(mb);
     132             :         //if (!msg)
     133             :         //      msg = chkDeclarations(mb);
     134             : 
     135             :         /* keep actions taken as a fake argument*/
     136           0 :         (void) pushInt(mb, pci, actions);
     137           0 :         return msg;
     138             : }

Generated by: LCOV version 1.14