|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.36 2002/06/13 19:52:02 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.37 2002/06/15 22:25:40 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -59,7 +59,7 @@ typedef enum
|
59 | 59 |
|
60 | 60 | /*
|
61 | 61 | * We build one of these structs for each attribute (column) that is to be
|
62 |
| - * analyzed. The struct and subsidiary data are inTransactionCommandContext, |
| 62 | + * analyzed. The struct and subsidiary data are inanl_context, |
63 | 63 | * so they live until the end of the ANALYZE operation.
|
64 | 64 | */
|
65 | 65 | typedefstruct
|
@@ -109,6 +109,8 @@ typedef struct
|
109 | 109 |
|
110 | 110 | staticintelevel=-1;
|
111 | 111 |
|
| 112 | +staticMemoryContextanl_context=NULL; |
| 113 | + |
112 | 114 | /* context information for compare_scalars() */
|
113 | 115 | staticFmgrInfo*datumCmpFn;
|
114 | 116 | staticSortFunctionKinddatumCmpFnKind;
|
@@ -155,6 +157,13 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
|
155 | 157 | else
|
156 | 158 | elevel=DEBUG1;
|
157 | 159 |
|
| 160 | +/* |
| 161 | + * Use the current context for storing analysis info. vacuum.c ensures |
| 162 | + * that this context will be cleared when I return, thus releasing the |
| 163 | + * memory allocated here. |
| 164 | + */ |
| 165 | +anl_context=CurrentMemoryContext; |
| 166 | + |
158 | 167 | /*
|
159 | 168 | * Check for user-requested abort.Note we want this to be inside a
|
160 | 169 | * transaction, so xact.c doesn't issue useless WARNING.
|
@@ -306,14 +315,14 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
|
306 | 315 | * Compute the statistics.Temporary results during the calculations
|
307 | 316 | * for each column are stored in a child context. The calc routines
|
308 | 317 | * are responsible to make sure that whatever they store into the
|
309 |
| - * VacAttrStats structure is allocated inTransactionCommandContext. |
| 318 | + * VacAttrStats structure is allocated inanl_context. |
310 | 319 | */
|
311 | 320 | if (numrows>0)
|
312 | 321 | {
|
313 | 322 | MemoryContextcol_context,
|
314 | 323 | old_context;
|
315 | 324 |
|
316 |
| -col_context=AllocSetContextCreate(CurrentMemoryContext, |
| 325 | +col_context=AllocSetContextCreate(anl_context, |
317 | 326 | "Analyze Column",
|
318 | 327 | ALLOCSET_DEFAULT_MINSIZE,
|
319 | 328 | ALLOCSET_DEFAULT_INITSIZE,
|
@@ -1094,8 +1103,8 @@ compute_minimal_stats(VacAttrStats *stats,
|
1094 | 1103 | Datum*mcv_values;
|
1095 | 1104 | float4*mcv_freqs;
|
1096 | 1105 |
|
1097 |
| -/* Must copy the target values intoTransactionCommandContext */ |
1098 |
| -old_context=MemoryContextSwitchTo(TransactionCommandContext); |
| 1106 | +/* Must copy the target values intoanl_context */ |
| 1107 | +old_context=MemoryContextSwitchTo(anl_context); |
1099 | 1108 | mcv_values= (Datum*)palloc(num_mcv*sizeof(Datum));
|
1100 | 1109 | mcv_freqs= (float4*)palloc(num_mcv*sizeof(float4));
|
1101 | 1110 | for (i=0;i<num_mcv;i++)
|
@@ -1415,8 +1424,8 @@ compute_scalar_stats(VacAttrStats *stats,
|
1415 | 1424 | Datum*mcv_values;
|
1416 | 1425 | float4*mcv_freqs;
|
1417 | 1426 |
|
1418 |
| -/* Must copy the target values intoTransactionCommandContext */ |
1419 |
| -old_context=MemoryContextSwitchTo(TransactionCommandContext); |
| 1427 | +/* Must copy the target values intoanl_context */ |
| 1428 | +old_context=MemoryContextSwitchTo(anl_context); |
1420 | 1429 | mcv_values= (Datum*)palloc(num_mcv*sizeof(Datum));
|
1421 | 1430 | mcv_freqs= (float4*)palloc(num_mcv*sizeof(float4));
|
1422 | 1431 | for (i=0;i<num_mcv;i++)
|
@@ -1501,8 +1510,8 @@ compute_scalar_stats(VacAttrStats *stats,
|
1501 | 1510 | nvals=values_cnt;
|
1502 | 1511 | Assert(nvals >=num_hist);
|
1503 | 1512 |
|
1504 |
| -/* Must copy the target values intoTransactionCommandContext */ |
1505 |
| -old_context=MemoryContextSwitchTo(TransactionCommandContext); |
| 1513 | +/* Must copy the target values intoanl_context */ |
| 1514 | +old_context=MemoryContextSwitchTo(anl_context); |
1506 | 1515 | hist_values= (Datum*)palloc(num_hist*sizeof(Datum));
|
1507 | 1516 | for (i=0;i<num_hist;i++)
|
1508 | 1517 | {
|
@@ -1530,8 +1539,8 @@ compute_scalar_stats(VacAttrStats *stats,
|
1530 | 1539 | doublecorr_xsum,
|
1531 | 1540 | corr_x2sum;
|
1532 | 1541 |
|
1533 |
| -/* Must copy the target values intoTransactionCommandContext */ |
1534 |
| -old_context=MemoryContextSwitchTo(TransactionCommandContext); |
| 1542 | +/* Must copy the target values intoanl_context */ |
| 1543 | +old_context=MemoryContextSwitchTo(anl_context); |
1535 | 1544 | corrs= (float4*)palloc(sizeof(float4));
|
1536 | 1545 | MemoryContextSwitchTo(old_context);
|
1537 | 1546 |
|
|