@@ -72,12 +72,6 @@ int vacuum_multixact_freeze_table_age;
72
72
int vacuum_failsafe_age ;
73
73
int vacuum_multixact_failsafe_age ;
74
74
75
-
76
- /* A few variables that don't seem worth passing around as parameters */
77
- static MemoryContext vac_context = NULL ;
78
- static BufferAccessStrategy vac_strategy ;
79
-
80
-
81
75
/*
82
76
* Variables for cost-based parallel vacuum. See comments atop
83
77
* compute_parallel_delay to understand how it works.
@@ -87,14 +81,15 @@ pg_atomic_uint32 *VacuumActiveNWorkers = NULL;
87
81
int VacuumCostBalanceLocal = 0 ;
88
82
89
83
/* non-export function prototypes */
90
- static List * expand_vacuum_rel (VacuumRelation * vrel , int options );
91
- static List * get_all_vacuum_rels (int options );
84
+ static List * expand_vacuum_rel (VacuumRelation * vrel ,
85
+ MemoryContext vac_context , int options );
86
+ static List * get_all_vacuum_rels (MemoryContext vac_context , int options );
92
87
static void vac_truncate_clog (TransactionId frozenXID ,
93
88
MultiXactId minMulti ,
94
89
TransactionId lastSaneFrozenXid ,
95
90
MultiXactId lastSaneMinMulti );
96
91
static bool vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params ,
97
- bool skip_privs );
92
+ bool skip_privs , BufferAccessStrategy bstrategy );
98
93
static double compute_parallel_delay (void );
99
94
static VacOptValue get_vacoptval_from_boolean (DefElem * def );
100
95
static bool vac_tid_reaped (ItemPointer itemptr , void * state );
@@ -313,6 +308,7 @@ vacuum(List *relations, VacuumParams *params,
313
308
{
314
309
static bool in_vacuum = false;
315
310
311
+ MemoryContext vac_context ;
316
312
const char * stmttype ;
317
313
volatile bool in_outer_xact ,
318
314
use_own_xacts ;
@@ -338,9 +334,9 @@ vacuum(List *relations, VacuumParams *params,
338
334
in_outer_xact = IsInTransactionBlock (isTopLevel );
339
335
340
336
/*
341
- * Due to static variables vac_context, anl_context and vac_strategy,
342
- * vacuum() is not reentrant. This matters when VACUUM FULL or ANALYZE
343
- * calls a hostile index expression that itself calls ANALYZE.
337
+ * Check for and disallow recursive calls. This could happen when VACUUM
338
+ * FULL or ANALYZE calls a hostile index expression that itself calls
339
+ * ANALYZE.
344
340
*/
345
341
if (in_vacuum )
346
342
ereport (ERROR ,
@@ -404,7 +400,6 @@ vacuum(List *relations, VacuumParams *params,
404
400
bstrategy = GetAccessStrategy (BAS_VACUUM );
405
401
MemoryContextSwitchTo (old_context );
406
402
}
407
- vac_strategy = bstrategy ;
408
403
409
404
/*
410
405
* Build list of relation(s) to process, putting any new data in
@@ -426,15 +421,15 @@ vacuum(List *relations, VacuumParams *params,
426
421
List * sublist ;
427
422
MemoryContext old_context ;
428
423
429
- sublist = expand_vacuum_rel (vrel , params -> options );
424
+ sublist = expand_vacuum_rel (vrel , vac_context , params -> options );
430
425
old_context = MemoryContextSwitchTo (vac_context );
431
426
newrels = list_concat (newrels , sublist );
432
427
MemoryContextSwitchTo (old_context );
433
428
}
434
429
relations = newrels ;
435
430
}
436
431
else
437
- relations = get_all_vacuum_rels (params -> options );
432
+ relations = get_all_vacuum_rels (vac_context , params -> options );
438
433
439
434
/*
440
435
* Decide whether we need to start/commit our own transactions.
@@ -509,7 +504,8 @@ vacuum(List *relations, VacuumParams *params,
509
504
510
505
if (params -> options & VACOPT_VACUUM )
511
506
{
512
- if (!vacuum_rel (vrel -> oid , vrel -> relation , params , false))
507
+ if (!vacuum_rel (vrel -> oid , vrel -> relation , params , false,
508
+ bstrategy ))
513
509
continue ;
514
510
}
515
511
@@ -527,7 +523,7 @@ vacuum(List *relations, VacuumParams *params,
527
523
}
528
524
529
525
analyze_rel (vrel -> oid , vrel -> relation , params ,
530
- vrel -> va_cols , in_outer_xact , vac_strategy );
526
+ vrel -> va_cols , in_outer_xact , bstrategy );
531
527
532
528
if (use_own_xacts )
533
529
{
@@ -582,7 +578,6 @@ vacuum(List *relations, VacuumParams *params,
582
578
* context!
583
579
*/
584
580
MemoryContextDelete (vac_context );
585
- vac_context = NULL ;
586
581
}
587
582
588
583
/*
@@ -760,7 +755,8 @@ vacuum_open_relation(Oid relid, RangeVar *relation, bits32 options,
760
755
* are made in vac_context.
761
756
*/
762
757
static List *
763
- expand_vacuum_rel (VacuumRelation * vrel , int options )
758
+ expand_vacuum_rel (VacuumRelation * vrel , MemoryContext vac_context ,
759
+ int options )
764
760
{
765
761
List * vacrels = NIL ;
766
762
MemoryContext oldcontext ;
@@ -899,7 +895,7 @@ expand_vacuum_rel(VacuumRelation *vrel, int options)
899
895
* the current database. The list is built in vac_context.
900
896
*/
901
897
static List *
902
- get_all_vacuum_rels (int options )
898
+ get_all_vacuum_rels (MemoryContext vac_context , int options )
903
899
{
904
900
List * vacrels = NIL ;
905
901
Relation pgclass ;
@@ -1838,7 +1834,8 @@ vac_truncate_clog(TransactionId frozenXID,
1838
1834
* At entry and exit, we are not inside a transaction.
1839
1835
*/
1840
1836
static bool
1841
- vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params , bool skip_privs )
1837
+ vacuum_rel (Oid relid , RangeVar * relation , VacuumParams * params ,
1838
+ bool skip_privs , BufferAccessStrategy bstrategy )
1842
1839
{
1843
1840
LOCKMODE lmode ;
1844
1841
Relation rel ;
@@ -2084,7 +2081,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, bool skip_privs)
2084
2081
cluster_rel (relid , InvalidOid , & cluster_params );
2085
2082
}
2086
2083
else
2087
- table_relation_vacuum (rel , params , vac_strategy );
2084
+ table_relation_vacuum (rel , params , bstrategy );
2088
2085
}
2089
2086
2090
2087
/* Roll back any GUC changes executed by index functions */
@@ -2118,7 +2115,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, bool skip_privs)
2118
2115
memcpy (& toast_vacuum_params , params , sizeof (VacuumParams ));
2119
2116
toast_vacuum_params .options |= VACOPT_PROCESS_MAIN ;
2120
2117
2121
- vacuum_rel (toast_relid , NULL , & toast_vacuum_params , true);
2118
+ vacuum_rel (toast_relid , NULL , & toast_vacuum_params , true, bstrategy );
2122
2119
}
2123
2120
2124
2121
/*
0 commit comments