Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1cffbfc

Browse files
committed
Arrange to free planning memory (or most of it, anyway) at completion
of planning. This should reduce memory requirements for large joins.
1 parentc7793a7 commit1cffbfc

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

‎src/backend/optimizer/plan/planmain.c

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.56 2000/07/24 03:11:01 tgl Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.57 2000/07/27 04:51:04 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -28,6 +28,7 @@
2828
#include"optimizer/paths.h"
2929
#include"optimizer/planmain.h"
3030
#include"optimizer/tlist.h"
31+
#include"utils/memutils.h"
3132

3233

3334
staticPlan*subplanner(Query*root,List*flat_tlist,List*qual,
@@ -176,6 +177,9 @@ subplanner(Query *root,
176177
doubletuple_fraction)
177178
{
178179
RelOptInfo*final_rel;
180+
Plan*resultplan;
181+
MemoryContextmycontext;
182+
MemoryContextoldcxt;
179183
Path*cheapestpath;
180184
Path*presortedpath;
181185

@@ -212,6 +216,24 @@ subplanner(Query *root,
212216
*/
213217
root->query_pathkeys=canonicalize_pathkeys(root,root->query_pathkeys);
214218

219+
/*
220+
* We might allocate quite a lot of storage during planning (due to
221+
* constructing lots of Paths), but all of it can be reclaimed after
222+
* we generate the finished Plan tree. Work in a temporary context
223+
* to let that happen. We make the context a child of
224+
* TransactionCommandContext so it will be freed if error abort.
225+
*
226+
* Note: beware of trying to move this up to the start of this routine.
227+
* Some of the data structures built above --- notably the pathkey
228+
* equivalence sets --- will still be needed after this routine exits.
229+
*/
230+
mycontext=AllocSetContextCreate(TransactionCommandContext,
231+
"Planner",
232+
ALLOCSET_DEFAULT_MINSIZE,
233+
ALLOCSET_DEFAULT_INITSIZE,
234+
ALLOCSET_DEFAULT_MAXSIZE);
235+
oldcxt=MemoryContextSwitchTo(mycontext);
236+
215237
/*
216238
* Ready to do the primary planning.
217239
*/
@@ -235,7 +257,9 @@ subplanner(Query *root,
235257
root->query_pathkeys=NIL;/* signal unordered result */
236258

237259
/* Make childless Result node to evaluate given tlist. */
238-
return (Plan*)make_result(flat_tlist, (Node*)qual, (Plan*)NULL);
260+
resultplan= (Plan*)make_result(flat_tlist, (Node*)qual,
261+
(Plan*)NULL);
262+
gotoplan_built;
239263
}
240264

241265
#ifdefNOT_USED/* fix xfunc */
@@ -295,7 +319,8 @@ subplanner(Query *root,
295319
cheapestpath->pathkeys))
296320
{
297321
root->query_pathkeys=cheapestpath->pathkeys;
298-
returncreate_plan(root,cheapestpath);
322+
resultplan=create_plan(root,cheapestpath);
323+
gotoplan_built;
299324
}
300325

301326
/*
@@ -321,7 +346,8 @@ subplanner(Query *root,
321346
{
322347
/* Presorted path is cheaper, use it */
323348
root->query_pathkeys=presortedpath->pathkeys;
324-
returncreate_plan(root,presortedpath);
349+
resultplan=create_plan(root,presortedpath);
350+
gotoplan_built;
325351
}
326352
/* otherwise, doing it the hard way is still cheaper */
327353
}
@@ -334,5 +360,24 @@ subplanner(Query *root,
334360
* as an aggregate function...)
335361
*/
336362
root->query_pathkeys=cheapestpath->pathkeys;
337-
returncreate_plan(root,cheapestpath);
363+
resultplan=create_plan(root,cheapestpath);
364+
365+
plan_built:
366+
367+
/*
368+
* Must copy the completed plan tree and its pathkeys out of temporary
369+
* context.
370+
*/
371+
MemoryContextSwitchTo(oldcxt);
372+
373+
resultplan=copyObject(resultplan);
374+
375+
root->query_pathkeys=copyObject(root->query_pathkeys);
376+
377+
/*
378+
* Now we can release the Path storage.
379+
*/
380+
MemoryContextDelete(mycontext);
381+
382+
returnresultplan;
338383
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp