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

Commit3f476c9

Browse files
committed
Remove some global variables from vacuum.c
Using global variables because we don't want to pass these values aroundas parameters does not really seem like a great idea, so let's removethese two global variables and adjust a few functions to accept thesevalues as parameters instead.This is part of a wider patch which intends to allow the size of thebuffer access strategy that vacuum uses to be adjusted.Author: Melanie PlagemanReviewed-by: Bharath RupireddyDiscussion:https://postgr.es/m/CAAKRu_b1q_07uquUtAvLqTM%3DW9nzee7QbtzHwA4XdUo7KX_Cnw%40mail.gmail.com
1 parent2e6ba13 commit3f476c9

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

‎src/backend/commands/vacuum.c‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ intvacuum_multixact_freeze_table_age;
7272
intvacuum_failsafe_age;
7373
intvacuum_multixact_failsafe_age;
7474

75-
76-
/* A few variables that don't seem worth passing around as parameters */
77-
staticMemoryContextvac_context=NULL;
78-
staticBufferAccessStrategyvac_strategy;
79-
80-
8175
/*
8276
* Variables for cost-based parallel vacuum. See comments atop
8377
* compute_parallel_delay to understand how it works.
@@ -87,14 +81,15 @@ pg_atomic_uint32 *VacuumActiveNWorkers = NULL;
8781
intVacuumCostBalanceLocal=0;
8882

8983
/* non-export function prototypes */
90-
staticList*expand_vacuum_rel(VacuumRelation*vrel,intoptions);
91-
staticList*get_all_vacuum_rels(intoptions);
84+
staticList*expand_vacuum_rel(VacuumRelation*vrel,
85+
MemoryContextvac_context,intoptions);
86+
staticList*get_all_vacuum_rels(MemoryContextvac_context,intoptions);
9287
staticvoidvac_truncate_clog(TransactionIdfrozenXID,
9388
MultiXactIdminMulti,
9489
TransactionIdlastSaneFrozenXid,
9590
MultiXactIdlastSaneMinMulti);
9691
staticboolvacuum_rel(Oidrelid,RangeVar*relation,VacuumParams*params,
97-
boolskip_privs);
92+
boolskip_privs,BufferAccessStrategybstrategy);
9893
staticdoublecompute_parallel_delay(void);
9994
staticVacOptValueget_vacoptval_from_boolean(DefElem*def);
10095
staticboolvac_tid_reaped(ItemPointeritemptr,void*state);
@@ -313,6 +308,7 @@ vacuum(List *relations, VacuumParams *params,
313308
{
314309
staticboolin_vacuum= false;
315310

311+
MemoryContextvac_context;
316312
constchar*stmttype;
317313
volatileboolin_outer_xact,
318314
use_own_xacts;
@@ -338,9 +334,9 @@ vacuum(List *relations, VacuumParams *params,
338334
in_outer_xact=IsInTransactionBlock(isTopLevel);
339335

340336
/*
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 callsANALYZE.
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.
344340
*/
345341
if (in_vacuum)
346342
ereport(ERROR,
@@ -404,7 +400,6 @@ vacuum(List *relations, VacuumParams *params,
404400
bstrategy=GetAccessStrategy(BAS_VACUUM);
405401
MemoryContextSwitchTo(old_context);
406402
}
407-
vac_strategy=bstrategy;
408403

409404
/*
410405
* Build list of relation(s) to process, putting any new data in
@@ -426,15 +421,15 @@ vacuum(List *relations, VacuumParams *params,
426421
List*sublist;
427422
MemoryContextold_context;
428423

429-
sublist=expand_vacuum_rel(vrel,params->options);
424+
sublist=expand_vacuum_rel(vrel,vac_context,params->options);
430425
old_context=MemoryContextSwitchTo(vac_context);
431426
newrels=list_concat(newrels,sublist);
432427
MemoryContextSwitchTo(old_context);
433428
}
434429
relations=newrels;
435430
}
436431
else
437-
relations=get_all_vacuum_rels(params->options);
432+
relations=get_all_vacuum_rels(vac_context,params->options);
438433

439434
/*
440435
* Decide whether we need to start/commit our own transactions.
@@ -509,7 +504,8 @@ vacuum(List *relations, VacuumParams *params,
509504

510505
if (params->options&VACOPT_VACUUM)
511506
{
512-
if (!vacuum_rel(vrel->oid,vrel->relation,params, false))
507+
if (!vacuum_rel(vrel->oid,vrel->relation,params, false,
508+
bstrategy))
513509
continue;
514510
}
515511

@@ -527,7 +523,7 @@ vacuum(List *relations, VacuumParams *params,
527523
}
528524

529525
analyze_rel(vrel->oid,vrel->relation,params,
530-
vrel->va_cols,in_outer_xact,vac_strategy);
526+
vrel->va_cols,in_outer_xact,bstrategy);
531527

532528
if (use_own_xacts)
533529
{
@@ -582,7 +578,6 @@ vacuum(List *relations, VacuumParams *params,
582578
* context!
583579
*/
584580
MemoryContextDelete(vac_context);
585-
vac_context=NULL;
586581
}
587582

588583
/*
@@ -760,7 +755,8 @@ vacuum_open_relation(Oid relid, RangeVar *relation, bits32 options,
760755
* are made in vac_context.
761756
*/
762757
staticList*
763-
expand_vacuum_rel(VacuumRelation*vrel,intoptions)
758+
expand_vacuum_rel(VacuumRelation*vrel,MemoryContextvac_context,
759+
intoptions)
764760
{
765761
List*vacrels=NIL;
766762
MemoryContextoldcontext;
@@ -899,7 +895,7 @@ expand_vacuum_rel(VacuumRelation *vrel, int options)
899895
* the current database. The list is built in vac_context.
900896
*/
901897
staticList*
902-
get_all_vacuum_rels(intoptions)
898+
get_all_vacuum_rels(MemoryContextvac_context,intoptions)
903899
{
904900
List*vacrels=NIL;
905901
Relationpgclass;
@@ -1838,7 +1834,8 @@ vac_truncate_clog(TransactionId frozenXID,
18381834
*At entry and exit, we are not inside a transaction.
18391835
*/
18401836
staticbool
1841-
vacuum_rel(Oidrelid,RangeVar*relation,VacuumParams*params,boolskip_privs)
1837+
vacuum_rel(Oidrelid,RangeVar*relation,VacuumParams*params,
1838+
boolskip_privs,BufferAccessStrategybstrategy)
18421839
{
18431840
LOCKMODElmode;
18441841
Relationrel;
@@ -2084,7 +2081,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, bool skip_privs)
20842081
cluster_rel(relid,InvalidOid,&cluster_params);
20852082
}
20862083
else
2087-
table_relation_vacuum(rel,params,vac_strategy);
2084+
table_relation_vacuum(rel,params,bstrategy);
20882085
}
20892086

20902087
/* Roll back any GUC changes executed by index functions */
@@ -2118,7 +2115,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, bool skip_privs)
21182115
memcpy(&toast_vacuum_params,params,sizeof(VacuumParams));
21192116
toast_vacuum_params.options |=VACOPT_PROCESS_MAIN;
21202117

2121-
vacuum_rel(toast_relid,NULL,&toast_vacuum_params, true);
2118+
vacuum_rel(toast_relid,NULL,&toast_vacuum_params, true,bstrategy);
21222119
}
21232120

21242121
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp