Skip to content

Commit badce86

Browse files
committed
First stage of reclaiming memory in executor by resetting short-term
memory contexts. Currently, only leaks in expressions executed as quals or projections are handled. Clean up some old dead cruft in executor while at it --- unused fields in state nodes, that sort of thing.
1 parent 46fb9c2 commit badce86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1523
-1571
lines changed

src/backend/access/gist/gist.c

+8-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.60 2000/07/03 23:09:11 wieck Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.61 2000/07/12 02:36:46 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -141,11 +141,10 @@ gistbuild(PG_FUNCTION_ARGS)
141141
{
142142
tupleTable = ExecCreateTupleTable(1);
143143
slot = ExecAllocTableSlot(tupleTable);
144-
econtext = makeNode(ExprContext);
145-
FillDummyExprContext(econtext, slot, hd, InvalidBuffer);
144+
ExecSetSlotDescriptor(slot, hd);
145+
econtext = MakeExprContext(slot, TransactionCommandContext);
146146
}
147147
else
148-
/* shut the compiler up */
149148
{
150149
tupleTable = NULL;
151150
slot = NULL;
@@ -161,21 +160,20 @@ gistbuild(PG_FUNCTION_ARGS)
161160
{
162161
nh++;
163162

163+
#ifndef OMIT_PARTIAL_INDEX
164164
/*
165165
* If oldPred != NULL, this is an EXTEND INDEX command, so skip
166166
* this tuple if it was already in the existing partial index
167167
*/
168168
if (oldPred != NULL)
169169
{
170-
#ifndef OMIT_PARTIAL_INDEX
171170
/* SetSlotContents(slot, htup); */
172171
slot->val = htup;
173172
if (ExecQual((List *) oldPred, econtext, false))
174173
{
175174
ni++;
176175
continue;
177176
}
178-
#endif /* OMIT_PARTIAL_INDEX */
179177
}
180178

181179
/*
@@ -184,13 +182,12 @@ gistbuild(PG_FUNCTION_ARGS)
184182
*/
185183
if (pred != NULL)
186184
{
187-
#ifndef OMIT_PARTIAL_INDEX
188185
/* SetSlotContents(slot, htup); */
189186
slot->val = htup;
190187
if (!ExecQual((List *) pred, econtext, false))
191188
continue;
192-
#endif /* OMIT_PARTIAL_INDEX */
193189
}
190+
#endif /* OMIT_PARTIAL_INDEX */
194191

195192
ni++;
196193

@@ -262,13 +259,13 @@ gistbuild(PG_FUNCTION_ARGS)
262259
/* okay, all heap tuples are indexed */
263260
heap_endscan(scan);
264261

262+
#ifndef OMIT_PARTIAL_INDEX
265263
if (pred != NULL || oldPred != NULL)
266264
{
267-
#ifndef OMIT_PARTIAL_INDEX
268265
ExecDropTupleTable(tupleTable, true);
269-
pfree(econtext);
270-
#endif /* OMIT_PARTIAL_INDEX */
266+
FreeExprContext(econtext);
271267
}
268+
#endif /* OMIT_PARTIAL_INDEX */
272269

273270
/*
274271
* Since we just counted the tuples in the heap, we update its stats

src/backend/access/hash/hash.c

+10-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.40 2000/06/17 23:41:13 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.41 2000/07/12 02:36:46 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -102,15 +102,14 @@ hashbuild(PG_FUNCTION_ARGS)
102102
{
103103
tupleTable = ExecCreateTupleTable(1);
104104
slot = ExecAllocTableSlot(tupleTable);
105-
econtext = makeNode(ExprContext);
106-
FillDummyExprContext(econtext, slot, htupdesc, InvalidBuffer);
105+
ExecSetSlotDescriptor(slot, htupdesc);
106+
econtext = MakeExprContext(slot, TransactionCommandContext);
107107
}
108108
else
109-
/* quiet the compiler */
110109
{
110+
tupleTable = NULL;
111+
slot = NULL;
111112
econtext = NULL;
112-
tupleTable = 0;
113-
slot = 0;
114113
}
115114
#endif /* OMIT_PARTIAL_INDEX */
116115

@@ -122,24 +121,22 @@ hashbuild(PG_FUNCTION_ARGS)
122121

123122
while (HeapTupleIsValid(htup = heap_getnext(hscan, 0)))
124123
{
125-
126124
nhtups++;
127125

126+
#ifndef OMIT_PARTIAL_INDEX
128127
/*
129128
* If oldPred != NULL, this is an EXTEND INDEX command, so skip
130129
* this tuple if it was already in the existing partial index
131130
*/
132131
if (oldPred != NULL)
133132
{
134133
/* SetSlotContents(slot, htup); */
135-
#ifndef OMIT_PARTIAL_INDEX
136134
slot->val = htup;
137135
if (ExecQual((List *) oldPred, econtext, false))
138136
{
139137
nitups++;
140138
continue;
141139
}
142-
#endif /* OMIT_PARTIAL_INDEX */
143140
}
144141

145142
/*
@@ -148,13 +145,12 @@ hashbuild(PG_FUNCTION_ARGS)
148145
*/
149146
if (pred != NULL)
150147
{
151-
#ifndef OMIT_PARTIAL_INDEX
152148
/* SetSlotContents(slot, htup); */
153149
slot->val = htup;
154150
if (!ExecQual((List *) pred, econtext, false))
155151
continue;
156-
#endif /* OMIT_PARTIAL_INDEX */
157152
}
153+
#endif /* OMIT_PARTIAL_INDEX */
158154

159155
nitups++;
160156

@@ -221,13 +217,13 @@ hashbuild(PG_FUNCTION_ARGS)
221217
/* okay, all heap tuples are indexed */
222218
heap_endscan(hscan);
223219

220+
#ifndef OMIT_PARTIAL_INDEX
224221
if (pred != NULL || oldPred != NULL)
225222
{
226-
#ifndef OMIT_PARTIAL_INDEX
227223
ExecDropTupleTable(tupleTable, true);
228-
pfree(econtext);
229-
#endif /* OMIT_PARTIAL_INDEX */
224+
FreeExprContext(econtext);
230225
}
226+
#endif /* OMIT_PARTIAL_INDEX */
231227

232228
/*
233229
* Since we just counted the tuples in the heap, we update its stats

src/backend/access/nbtree/nbtcompare.c

+21-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.38 2000/06/19 03:54:22 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.39 2000/07/12 02:36:48 tgl Exp $
1212
*
1313
* NOTES
1414
*
@@ -27,6 +27,10 @@
2727
* that work on 32-bit or wider datatypes can't just return "a - b".
2828
* That could overflow and give the wrong answer.
2929
*
30+
* NOTE: these routines must not leak memory, since memory allocated
31+
* during an index access won't be recovered till end of query. This
32+
* primarily affects comparison routines for toastable datatypes;
33+
* they have to be careful to free any detoasted copy of an input datum.
3034
*-------------------------------------------------------------------------
3135
*/
3236

@@ -230,18 +234,23 @@ bttextcmp(PG_FUNCTION_ARGS)
230234
} while (res == 0 && len != 0);
231235
}
232236

237+
if (res == 0 && VARSIZE(a) != VARSIZE(b))
238+
{
239+
/*
240+
* The two strings are the same in the first len bytes,
241+
* and they are of different lengths.
242+
*/
243+
if (VARSIZE(a) < VARSIZE(b))
244+
res = -1;
245+
else
246+
res = 1;
247+
}
248+
233249
#endif
234250

235-
if (res != 0 || VARSIZE(a) == VARSIZE(b))
236-
PG_RETURN_INT32(res);
251+
/* Avoid leaking memory when handed toasted input. */
252+
PG_FREE_IF_COPY(a, 0);
253+
PG_FREE_IF_COPY(b, 1);
237254

238-
/*
239-
* The two strings are the same in the first len bytes, and they are
240-
* of different lengths.
241-
*/
242-
243-
if (VARSIZE(a) < VARSIZE(b))
244-
PG_RETURN_INT32(-1);
245-
else
246-
PG_RETURN_INT32(1);
255+
PG_RETURN_INT32(res);
247256
}

src/backend/access/nbtree/nbtree.c

+8-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.59 2000/06/17 23:41:16 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.60 2000/07/12 02:36:48 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -121,8 +121,8 @@ btbuild(PG_FUNCTION_ARGS)
121121
{
122122
tupleTable = ExecCreateTupleTable(1);
123123
slot = ExecAllocTableSlot(tupleTable);
124-
econtext = makeNode(ExprContext);
125-
FillDummyExprContext(econtext, slot, htupdesc, InvalidBuffer);
124+
ExecSetSlotDescriptor(slot, htupdesc);
125+
econtext = MakeExprContext(slot, TransactionCommandContext);
126126

127127
/*
128128
* we never want to use sort/build if we are extending an existing
@@ -151,22 +151,20 @@ btbuild(PG_FUNCTION_ARGS)
151151
{
152152
nhtups++;
153153

154+
#ifndef OMIT_PARTIAL_INDEX
154155
/*
155156
* If oldPred != NULL, this is an EXTEND INDEX command, so skip
156157
* this tuple if it was already in the existing partial index
157158
*/
158159
if (oldPred != NULL)
159160
{
160-
#ifndef OMIT_PARTIAL_INDEX
161-
162161
/* SetSlotContents(slot, htup); */
163162
slot->val = htup;
164163
if (ExecQual((List *) oldPred, econtext, false))
165164
{
166165
nitups++;
167166
continue;
168167
}
169-
#endif /* OMIT_PARTIAL_INDEX */
170168
}
171169

172170
/*
@@ -175,13 +173,12 @@ btbuild(PG_FUNCTION_ARGS)
175173
*/
176174
if (pred != NULL)
177175
{
178-
#ifndef OMIT_PARTIAL_INDEX
179176
/* SetSlotContents(slot, htup); */
180177
slot->val = htup;
181178
if (!ExecQual((List *) pred, econtext, false))
182179
continue;
183-
#endif /* OMIT_PARTIAL_INDEX */
184180
}
181+
#endif /* OMIT_PARTIAL_INDEX */
185182

186183
nitups++;
187184

@@ -260,13 +257,13 @@ btbuild(PG_FUNCTION_ARGS)
260257
/* okay, all heap tuples are indexed */
261258
heap_endscan(hscan);
262259

260+
#ifndef OMIT_PARTIAL_INDEX
263261
if (pred != NULL || oldPred != NULL)
264262
{
265-
#ifndef OMIT_PARTIAL_INDEX
266263
ExecDropTupleTable(tupleTable, true);
267-
pfree(econtext);
268-
#endif /* OMIT_PARTIAL_INDEX */
264+
FreeExprContext(econtext);
269265
}
266+
#endif /* OMIT_PARTIAL_INDEX */
270267

271268
/*
272269
* if we are doing bottom-up btree build, finish the build by (1)

src/backend/access/rtree/rtree.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.50 2000/06/17 23:41:22 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.51 2000/07/12 02:36:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -136,14 +136,14 @@ rtbuild(PG_FUNCTION_ARGS)
136136
{
137137
tupleTable = ExecCreateTupleTable(1);
138138
slot = ExecAllocTableSlot(tupleTable);
139-
econtext = makeNode(ExprContext);
140-
FillDummyExprContext(econtext, slot, hd, InvalidBuffer);
139+
ExecSetSlotDescriptor(slot, hd);
140+
econtext = MakeExprContext(slot, TransactionCommandContext);
141141
}
142142
else
143143
{
144-
econtext = NULL;
145144
tupleTable = NULL;
146145
slot = NULL;
146+
econtext = NULL;
147147
}
148148
#endif /* OMIT_PARTIAL_INDEX */
149149

@@ -156,21 +156,20 @@ rtbuild(PG_FUNCTION_ARGS)
156156
{
157157
nh++;
158158

159+
#ifndef OMIT_PARTIAL_INDEX
159160
/*
160161
* If oldPred != NULL, this is an EXTEND INDEX command, so skip
161162
* this tuple if it was already in the existing partial index
162163
*/
163164
if (oldPred != NULL)
164165
{
165-
#ifndef OMIT_PARTIAL_INDEX
166166
/* SetSlotContents(slot, htup); */
167167
slot->val = htup;
168168
if (ExecQual((List *) oldPred, econtext, false))
169169
{
170170
ni++;
171171
continue;
172172
}
173-
#endif /* OMIT_PARTIAL_INDEX */
174173
}
175174

176175
/*
@@ -179,13 +178,12 @@ rtbuild(PG_FUNCTION_ARGS)
179178
*/
180179
if (pred != NULL)
181180
{
182-
#ifndef OMIT_PARTIAL_INDEX
183181
/* SetSlotContents(slot, htup); */
184182
slot->val = htup;
185183
if (!ExecQual((List *) pred, econtext, false))
186184
continue;
187-
#endif /* OMIT_PARTIAL_INDEX */
188185
}
186+
#endif /* OMIT_PARTIAL_INDEX */
189187

190188
ni++;
191189

@@ -239,13 +237,13 @@ rtbuild(PG_FUNCTION_ARGS)
239237
/* okay, all heap tuples are indexed */
240238
heap_endscan(scan);
241239

240+
#ifndef OMIT_PARTIAL_INDEX
242241
if (pred != NULL || oldPred != NULL)
243242
{
244-
#ifndef OMIT_PARTIAL_INDEX
245243
ExecDropTupleTable(tupleTable, true);
246-
pfree(econtext);
247-
#endif /* OMIT_PARTIAL_INDEX */
244+
FreeExprContext(econtext);
248245
}
246+
#endif /* OMIT_PARTIAL_INDEX */
249247

250248
/*
251249
* Since we just counted the tuples in the heap, we update its stats

0 commit comments

Comments
 (0)