1: # include   <ingres.h>
   2: # include   <aux.h>
   3: # include   <tree.h>
   4: # include   <symbol.h>
   5: # include   <pv.h>
   6: # include   "globs.h"
   7: # include   <sccs.h>
   8: 
   9: SCCSID(@(#)exec_sq.c	8.1	12/31/84)
  10: 
  11: /*
  12: ** DECOMP2 -- Routines for executing detached sub-queries appearing
  13: **	in sqlist. These routines include:
  14: **
  15: **	exec_sq -- execute sub-queries and update range table.
  16: **
  17: **	undo_sq -- restore range table and destroy temp rels.
  18: **
  19: **	reset_sq - restore range table and reset temp rels.
  20: **
  21: **	execsq1 -- call ovqp with subquery.
  22: */
  23: /*
  24: **  EXEC_SQ
  25: **
  26: **	Execute the subqueries in sqlist. Associated with
  27: **	each sub-query is a relation number stored in sqrange.
  28: **	If the sub-query has a non-null target list, the range
  29: **	table is updated to reflect the new range of the relation.
  30: **
  31: **	If any sub-query is false, all subsequent ones are ignored
  32: **	by ovqp and exec_sq returns the var number of the false subquery.
  33: **
  34: **	As a side effect, "disj" is incremented for each disjoint sub-query
  35: **
  36: **	Trace Flags:
  37: **		35
  38: */
  39: 
  40: exec_sq(sqlist, sqrange, disj)
  41: QTREE   *sqlist[];
  42: int sqrange[];
  43: int *disj;
  44: {
  45:     register QTREE  *sq;
  46:     register int    i, qualfound;
  47:     extern DESC *openr1();
  48: 
  49: #	ifdef xDTR1
  50:     if (tTf(35, 0))
  51:         printf("EXEC_SQ--\n");
  52: #	endif
  53: 
  54:     *disj = 0;
  55: 
  56:     for (i = 0; i < MAXRANGE; i++)
  57:     {
  58:         if (sq = sqlist[i])
  59:         {
  60: #			ifdef xDTR1
  61:             if (tTf(35, 1))
  62:                 printf("sq[%d]=%x\n", i, sq);
  63: #			endif
  64:             qualfound = execsq1(sq, i, sqrange[i]);
  65: 
  66: #			ifdef xDTR1
  67:             if (tTf(35, 2))
  68:                 printf("qualfound=%d\n", qualfound);
  69: #			endif
  70:             if (!qualfound)
  71:             {
  72:                 return(i);
  73:             }
  74:             if (sq->left->sym.type != TREE)
  75:             {
  76:                 /*
  77: 				** Update the range table and open
  78: 				** the relation's restricted replacement.
  79: 				*/
  80:                 new_range(i, sqrange[i]);
  81:                 openr1(i);
  82:             }
  83:             else
  84:             {
  85:                 (*disj)++;
  86:             }
  87:         }
  88:     }
  89:     return (-1);
  90: }
  91: /*
  92: **  UNDO_SQ
  93: **
  94: **	Undo the effects of one variable detachment on
  95: **	the range table. The two parameters "limit" and
  96: **	"maxlimit" describe how far down the list of
  97: **	subqueries were processed.  Maxlimit represents
  98: **	the furthest every attained and limit represents
  99: **	the last variable processed the last time.
 100: **
 101: **	Trace Flags:
 102: **		36
 103: */
 104: 
 105: undo_sq(sqlist, locrang, sqrange, limit, maxlimit, reopen)
 106: QTREE   *sqlist[];
 107: int locrang[];
 108: int sqrange[];
 109: int limit;
 110: int maxlimit;
 111: int reopen;
 112: {
 113:     register QTREE  *sq;
 114:     register int    i, lim;
 115:     bool        dstr_flag;
 116: 
 117: #	ifdef xDTR1
 118:     if (tTf(36, 0))
 119:         printf("UNDO_SQ--\n");
 120: #	endif
 121: 
 122:     initp();    /* setup parm vector for destroys */
 123:     lim = limit == -1 ? MAXRANGE : limit;
 124:     if (maxlimit == -1)
 125:         maxlimit = MAXRANGE;
 126: 
 127:     for (i = 0; i < MAXRANGE; i++)
 128:         if (sq = sqlist[i])
 129:         {
 130:             if (sq->left->sym.type != TREE)
 131:             {
 132:                 if (i < lim)
 133:                 {
 134:                     /* The query was run. Close the temp rel */
 135:                     closer1(i);
 136:                 }
 137: 
 138:                 /* mark the temporary to be destroyed */
 139:                 dstr_mark(sqrange[i]);
 140:                 dstr_flag = TRUE;
 141: 
 142:                 /* reopen the original relation. If maxlimit
 143: 				** never reached the variable "i" then the
 144: 				** original relation was never closed and thus
 145: 				** doesn't need to be reopened.
 146: 				*/
 147:                 rstrang(locrang, i);
 148:                 if (reopen && i < maxlimit)
 149:                     openr1(i);
 150:             }
 151:         }
 152:     /* Only call destroy if there's something to destroy */
 153:     if (dstr_flag)
 154:         call_dbu(mdDESTROY, FALSE);
 155:     else
 156:         resetp();
 157: 
 158: }
 159: /*
 160: ** Execsq1 -- call ovqp with mdRETR on temp relation
 161: */
 162: 
 163: execsq1(sq, var, relnum)
 164: QTREE   *sq;
 165: int var;
 166: int relnum;
 167: {
 168:     register int    qualfound;
 169: 
 170:     De.de_sourcevar = var;
 171:     De.de_newq = 1;
 172:     qualfound = call_ovqp(sq, mdRETR, relnum);
 173:     return (qualfound);
 174: }
 175: /*
 176: **	Reset each relation until limit.
 177: **	Reset will remove all tuples from the
 178: **	relation but not destroy the relation.
 179: **	The descriptor for the relation will be removed
 180: **	from the cache.
 181: **
 182: **	The original relation is returned to
 183: **	the range table.
 184: **
 185: **	If limit is -1 then all relations are done.
 186: */
 187: 
 188: reset_sq(sqlist, locrang, limit)
 189: QTREE   *sqlist[];
 190: int locrang[];
 191: int limit;
 192: {
 193:     register QTREE  *sq;
 194:     register int    i, lim;
 195:     int     old, reset;
 196:     extern char *rnum_convert();
 197: 
 198:     lim = limit == -1 ? MAXRANGE : limit;
 199:     reset = FALSE;
 200:     initp();
 201: 
 202:     for (i = 0; i < lim; i++)
 203:         if ((sq = sqlist[i]) && sq->left->sym.type != TREE)
 204:         {
 205:             old = new_range(i, locrang[i]);
 206:             setp(PV_STR, rnum_convert(old));
 207:             specclose(old);
 208:             reset = TRUE;
 209:         }
 210: 
 211:     if (reset)
 212:     {
 213:         /*
 214: 		** Guarantee that OVQP will not reuse old
 215: 		** page of relation being reset
 216: 		*/
 217:         De.de_newr = TRUE;
 218:         call_dbu(mdRESETREL, FALSE);
 219:     }
 220:     else
 221:         resetp();
 222: }

Defined functions

exec_sq defined in line 9; used 2 times
execsq1 defined in line 163; used 3 times
reset_sq defined in line 188; used 1 times
undo_sq defined in line 105; used 3 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 931
Valid CSS Valid XHTML 1.0 Strict