1: # include "../ingres.h"
2: # include "../tree.h"
3: # include "../symbol.h"
4:
5: /* DECOMP3 -- This file contains routines associated with redefining
6: ** attribute numbers. This is needed when one variable sub queries
7: ** or reduction change the positions of attributes in a relation.
8: ** This file includes:
9: **
10: ** Tempvar -- Change the attribute numbers to new ones.
11: **
12: ** Origvar -- Restore attribute numbers back to their previous values.
13: **
14: ** Ckvar -- Return the currently active VAR node
15: */
16:
17:
18:
19: tempvar(node, sqlist, buf)
20: struct querytree *node;
21: struct querytree *sqlist[];
22: char *buf;
23:
24: /*
25: ** Tempvar -- Replace a VAR attribute number with its new number.
26: **
27: ** Tempvar is given a list of subqueries which will potentially
28: ** alter the attribute numbers of VARs they reference. An attno
29: ** is changed by making the current VAR point to a new VAR node
30: ** which has the updated attno.
31: **
32: ** The new attno is determined from the target list of the subquery
33: ** for that VAR. The RESDOM number is the new attno and the VAR it
34: ** points to is the old attno. For example:
35: ** RESDOM/2 -> right = VAR 1/3
36: ** The right subtree of result domain 2 is domain 3 of variable 1.
37: ** Thus domain 3 should be renumbered to be domain 2.
38: */
39:
40: {
41: register struct querytree *v, *sq, *nod;
42: int attno;
43: struct querytree *ckvar(), *need();
44:
45: if ((nod = node) == NULL)
46: return;
47:
48: if (nod->sym.type == VAR )
49: {
50: nod = ckvar(nod);
51: if (sq = sqlist[((struct qt_var *)nod)->varno])
52: {
53: /* This var has a subquery on it */
54:
55: /* allocate a new VAR node */
56: if (buf)
57: {
58: v = (struct querytree *) (((struct qt_var *)nod)->valptr = (char *) need(buf, 12));
59: v->left = v->right = (struct querytree *) (((struct qt_var *)v)->valptr = (char *) 0);
60: bmove(&nod->sym, &v->sym, 6);
61: ((struct qt_var *)nod)->varno = -1;
62: }
63: else
64: v = nod;
65:
66: /* search for the new attno */
67: for (sq = sq->left; sq->sym.type != TREE; sq = sq->left)
68: {
69: if (((struct qt_var *)ckvar(sq->right))->attno == ((struct qt_var *)nod)->attno)
70: {
71:
72: ((struct qt_var *)v)->attno = ((struct qt_res *)sq)->resno;
73: # ifdef xDTR1
74: if (tTf(12, 3))
75: {
76: printf("Tempvar:");
77: writenod(nod);
78: }
79: # endif
80:
81: return;
82: }
83: }
84: syserr("tempvar:dom %d of %s missing", ((struct qt_var *)nod)->attno, rangename(((struct qt_var *)nod)->varno));
85: }
86: return;
87: }
88:
89: tempvar(nod->left, sqlist, buf);
90: tempvar(nod->right, sqlist, buf);
91: }
92:
93:
94:
95:
96: origvar(node, sqlist)
97: struct querytree *node;
98: struct querytree *sqlist[];
99:
100: /*
101: ** Origvar -- Restore VAR node to previous state.
102: **
103: ** Origvar undoes the effect of tempvar. All vars listed
104: ** in the sqlist will have their most recent tempvar removed.
105: */
106:
107: {
108: register struct querytree *t;
109: register int v;
110:
111: t = node;
112: if (!t)
113: return;
114: if (t->sym.type == VAR && ((struct qt_var *)t)->varno < 0)
115: {
116: for (; ((struct qt_var *)((struct qt_var *)t)->valptr)->varno<0; t=(struct querytree *)(((struct qt_var *)t)->valptr));
117: if (sqlist[v=((struct qt_var *)((struct qt_var *)t)->valptr)->varno])
118: {
119: ((struct qt_var *)t)->varno = v;
120: ((struct qt_var *)t)->valptr = 0;
121: }
122: return;
123: }
124: origvar(t->left, sqlist);
125: origvar(t->right, sqlist);
126: }
127:
128:
129:
130: struct querytree *ckvar(node)
131: struct querytree *node;
132:
133: /*
134: ** Ckvar -- Return pointer to currently "active" VAR.
135: **
136: ** This routine guarantees that "t" will point to
137: ** the most current definition of the VAR.
138: */
139:
140: {
141: register struct querytree *t;
142:
143: t = node;
144: if (t->sym.type != VAR)
145: {
146: syserr("ckvar: not a VAR %d", t->sym.type);
147: }
148: while (((struct qt_var *)t)->varno < 0)
149: t = (struct querytree *)(((struct qt_var *)t)->valptr);
150: return(t);
151: }
Defined functions
ckvar
defined in line
130; used 18 times
- in line 43,
50,
69
- in /usr/ingres/source/decomp/call_ovqp.c line
303,
314
- in /usr/ingres/source/decomp/call_ovqp70.c line
284,
293
- in /usr/ingres/source/decomp/mapvar.c line
17,
49
- in /usr/ingres/source/decomp/pull_sq.c line
166,
177
- in /usr/ingres/source/decomp/reformat.c line
132,
157-158(2)
- in /usr/ingres/source/decomp/setvar.c line
31,
39,
97,
106