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

Commitfd0f651

Browse files
committed
Test IsInTransactionChain, not IsTransactionBlock, in vac_update_relstats.
As noted by Noah Misch, my initial cut at fixing bug #11638 didn't coverall cases where ANALYZE might be invoked in an unsafe context. We need totest the result of IsInTransactionChain not IsTransactionBlock; which isnotationally a pain because IsInTransactionChain requires an isTopLevelflag, which would have to be passed down through several levels of callers.I chose to pass in_outer_xact (ie, the result of IsInTransactionChain)rather than isTopLevel per se, as that seemed marginally more aproposfor the intermediate functions to know about.
1 parent6057c21 commitfd0f651

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

‎src/backend/commands/analyze.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static BufferAccessStrategy vac_strategy;
8787

8888
staticvoiddo_analyze_rel(Relationonerel,VacuumStmt*vacstmt,
8989
AcquireSampleRowsFuncacquirefunc,BlockNumberrelpages,
90-
boolinh,intelevel);
90+
boolinh,boolin_outer_xact,intelevel);
9191
staticvoidBlockSampler_Init(BlockSamplerbs,BlockNumbernblocks,
9292
intsamplesize);
9393
staticboolBlockSampler_HasMore(BlockSamplerbs);
@@ -115,7 +115,8 @@ static Datum ind_fetch_func(VacAttrStatsP stats, int rownum, bool *isNull);
115115
*analyze_rel() -- analyze one relation
116116
*/
117117
void
118-
analyze_rel(Oidrelid,VacuumStmt*vacstmt,BufferAccessStrategybstrategy)
118+
analyze_rel(Oidrelid,VacuumStmt*vacstmt,
119+
boolin_outer_xact,BufferAccessStrategybstrategy)
119120
{
120121
Relationonerel;
121122
intelevel;
@@ -265,13 +266,15 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
265266
/*
266267
* Do the normal non-recursive ANALYZE.
267268
*/
268-
do_analyze_rel(onerel,vacstmt,acquirefunc,relpages, false,elevel);
269+
do_analyze_rel(onerel,vacstmt,acquirefunc,relpages,
270+
false,in_outer_xact,elevel);
269271

270272
/*
271273
* If there are child tables, do recursive ANALYZE.
272274
*/
273275
if (onerel->rd_rel->relhassubclass)
274-
do_analyze_rel(onerel,vacstmt,acquirefunc,relpages, true,elevel);
276+
do_analyze_rel(onerel,vacstmt,acquirefunc,relpages,
277+
true,in_outer_xact,elevel);
275278

276279
/*
277280
* Close source relation now, but keep lock so that no one deletes it
@@ -301,7 +304,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
301304
staticvoid
302305
do_analyze_rel(Relationonerel,VacuumStmt*vacstmt,
303306
AcquireSampleRowsFuncacquirefunc,BlockNumberrelpages,
304-
boolinh,intelevel)
307+
boolinh,boolin_outer_xact,intelevel)
305308
{
306309
intattr_cnt,
307310
tcnt,
@@ -584,7 +587,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
584587
visibilitymap_count(onerel),
585588
hasindex,
586589
InvalidTransactionId,
587-
InvalidMultiXactId);
590+
InvalidMultiXactId,
591+
in_outer_xact);
588592

589593
/*
590594
* Same for indexes. Vacuum always scans all indexes, so if we're part of
@@ -605,7 +609,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
605609
0,
606610
false,
607611
InvalidTransactionId,
608-
InvalidMultiXactId);
612+
InvalidMultiXactId,
613+
in_outer_xact);
609614
}
610615
}
611616

‎src/backend/commands/vacuum.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
206206
*/
207207
if (use_own_xacts)
208208
{
209+
Assert(!in_outer_xact);
210+
209211
/* ActiveSnapshot is not set by autovacuum */
210212
if (ActiveSnapshotSet())
211213
PopActiveSnapshot();
@@ -251,7 +253,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
251253
PushActiveSnapshot(GetTransactionSnapshot());
252254
}
253255

254-
analyze_rel(relid,vacstmt,vac_strategy);
256+
analyze_rel(relid,vacstmt,in_outer_xact,vac_strategy);
255257

256258
if (use_own_xacts)
257259
{
@@ -665,13 +667,13 @@ vac_estimate_reltuples(Relation relation, bool is_analyze,
665667
*DDL flags such as relhasindex, by clearing them if no longer correct.
666668
*It's safe to do this in VACUUM, which can't run in parallel with
667669
*CREATE INDEX/RULE/TRIGGER and can't be part of a transaction block.
668-
*However, it's *not* safe to do it in an ANALYZE that's withina
669-
*transaction block, because for example the current transaction might
670+
*However, it's *not* safe to do it in an ANALYZE that's withinan
671+
*outer transaction, because for example the current transaction might
670672
*have dropped the last index; then we'd think relhasindex should be
671673
*cleared, but if the transaction later rolls back this would be wrong.
672-
*So we refrain from updating the DDL flags if we're insidea
673-
*transaction block. This is OK since postponing the flag maintenance
674-
*isalways allowable.
674+
*So we refrain from updating the DDL flags if we're insidean outer
675+
*transaction. This is OK since postponing the flag maintenance is
676+
*always allowable.
675677
*
676678
*This routine is shared by VACUUM and ANALYZE.
677679
*/
@@ -680,7 +682,8 @@ vac_update_relstats(Relation relation,
680682
BlockNumbernum_pages,doublenum_tuples,
681683
BlockNumbernum_all_visible_pages,
682684
boolhasindex,TransactionIdfrozenxid,
683-
MultiXactIdminmulti)
685+
MultiXactIdminmulti,
686+
boolin_outer_xact)
684687
{
685688
Oidrelid=RelationGetRelid(relation);
686689
Relationrd;
@@ -716,9 +719,9 @@ vac_update_relstats(Relation relation,
716719
dirty= true;
717720
}
718721

719-
/* Apply DDL updates, but not insidea transaction block (see above) */
722+
/* Apply DDL updates, but not insidean outer transaction (see above) */
720723

721-
if (!IsTransactionBlock())
724+
if (!in_outer_xact)
722725
{
723726
/*
724727
* If we didn't find any indexes, reset relhasindex.

‎src/backend/commands/vacuumlazy.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
309309
new_rel_allvisible,
310310
vacrelstats->hasindex,
311311
new_frozen_xid,
312-
new_min_multi);
312+
new_min_multi,
313+
false);
313314

314315
/* report results to the stats collector, too */
315316
new_live_tuples=new_rel_tuples-vacrelstats->new_dead_tuples;
@@ -1377,7 +1378,8 @@ lazy_cleanup_index(Relation indrel,
13771378
0,
13781379
false,
13791380
InvalidTransactionId,
1380-
InvalidMultiXactId);
1381+
InvalidMultiXactId,
1382+
false);
13811383

13821384
ereport(elevel,
13831385
(errmsg("index \"%s\" now contains %.0f row versions in %u pages",

‎src/include/commands/vacuum.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ extern void vac_update_relstats(Relation relation,
156156
BlockNumbernum_all_visible_pages,
157157
boolhasindex,
158158
TransactionIdfrozenxid,
159-
MultiXactIdminmulti);
159+
MultiXactIdminmulti,
160+
boolin_outer_xact);
160161
externvoidvacuum_set_xid_limits(Relationrel,
161162
intfreeze_min_age,intfreeze_table_age,
162163
intmultixact_freeze_min_age,
@@ -175,7 +176,7 @@ extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
175176

176177
/* in commands/analyze.c */
177178
externvoidanalyze_rel(Oidrelid,VacuumStmt*vacstmt,
178-
BufferAccessStrategybstrategy);
179+
boolin_outer_xact,BufferAccessStrategybstrategy);
179180
externboolstd_typanalyze(VacAttrStats*stats);
180181
externdoubleanl_random_fract(void);
181182
externdoubleanl_init_selection_state(intn);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp