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

Commitfcf0246

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 parent6ec1c3e commitfcf0246

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

‎src/backend/commands/analyze.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ static MemoryContext anl_context = NULL;
8484
staticBufferAccessStrategyvac_strategy;
8585

8686

87-
staticvoiddo_analyze_rel(Relationonerel,VacuumStmt*vacstmt,boolinh);
87+
staticvoiddo_analyze_rel(Relationonerel,VacuumStmt*vacstmt,
88+
boolinh,boolin_outer_xact);
8889
staticvoidBlockSampler_Init(BlockSamplerbs,BlockNumbernblocks,
8990
intsamplesize);
9091
staticboolBlockSampler_HasMore(BlockSamplerbs);
@@ -116,7 +117,8 @@ static bool std_typanalyze(VacAttrStats *stats);
116117
*analyze_rel() -- analyze one relation
117118
*/
118119
void
119-
analyze_rel(Oidrelid,VacuumStmt*vacstmt,BufferAccessStrategybstrategy)
120+
analyze_rel(Oidrelid,VacuumStmt*vacstmt,
121+
boolin_outer_xact,BufferAccessStrategybstrategy)
120122
{
121123
Relationonerel;
122124

@@ -228,13 +230,13 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
228230
/*
229231
* Do the normal non-recursive ANALYZE.
230232
*/
231-
do_analyze_rel(onerel,vacstmt, false);
233+
do_analyze_rel(onerel,vacstmt, false,in_outer_xact);
232234

233235
/*
234236
* If there are child tables, do recursive ANALYZE.
235237
*/
236238
if (onerel->rd_rel->relhassubclass)
237-
do_analyze_rel(onerel,vacstmt, true);
239+
do_analyze_rel(onerel,vacstmt, true,in_outer_xact);
238240

239241
/*
240242
* Close source relation now, but keep lock so that no one deletes it
@@ -257,7 +259,8 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
257259
*do_analyze_rel() -- analyze one relation, recursively or not
258260
*/
259261
staticvoid
260-
do_analyze_rel(Relationonerel,VacuumStmt*vacstmt,boolinh)
262+
do_analyze_rel(Relationonerel,VacuumStmt*vacstmt,
263+
boolinh,boolin_outer_xact)
261264
{
262265
intattr_cnt,
263266
tcnt,
@@ -534,7 +537,10 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt, bool inh)
534537
if (!inh)
535538
vac_update_relstats(onerel,
536539
RelationGetNumberOfBlocks(onerel),
537-
totalrows,hasindex,InvalidTransactionId);
540+
totalrows,
541+
hasindex,
542+
InvalidTransactionId,
543+
in_outer_xact);
538544

539545
/*
540546
* Same for indexes. Vacuum always scans all indexes, so if we're part of
@@ -551,7 +557,10 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt, bool inh)
551557
totalindexrows=ceil(thisdata->tupleFract*totalrows);
552558
vac_update_relstats(Irel[ind],
553559
RelationGetNumberOfBlocks(Irel[ind]),
554-
totalindexrows, false,InvalidTransactionId);
560+
totalindexrows,
561+
false,
562+
InvalidTransactionId,
563+
in_outer_xact);
555564
}
556565
}
557566

‎src/backend/commands/vacuum.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
199199
*/
200200
if (use_own_xacts)
201201
{
202+
Assert(!in_outer_xact);
203+
202204
/* ActiveSnapshot is not set by autovacuum */
203205
if (ActiveSnapshotSet())
204206
PopActiveSnapshot();
@@ -241,7 +243,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
241243
PushActiveSnapshot(GetTransactionSnapshot());
242244
}
243245

244-
analyze_rel(relid,vacstmt,vac_strategy);
246+
analyze_rel(relid,vacstmt,in_outer_xact,vac_strategy);
245247

246248
if (use_own_xacts)
247249
{
@@ -555,20 +557,21 @@ vac_estimate_reltuples(Relation relation, bool is_analyze,
555557
*DDL flags such as relhasindex, by clearing them if no longer correct.
556558
*It's safe to do this in VACUUM, which can't run in parallel with
557559
*CREATE INDEX/RULE/TRIGGER and can't be part of a transaction block.
558-
*However, it's *not* safe to do it in an ANALYZE that's withina
559-
*transaction block, because for example the current transaction might
560+
*However, it's *not* safe to do it in an ANALYZE that's withinan
561+
*outer transaction, because for example the current transaction might
560562
*have dropped the last index; then we'd think relhasindex should be
561563
*cleared, but if the transaction later rolls back this would be wrong.
562-
*So we refrain from updating the DDL flags if we're insidea
563-
*transaction block. This is OK since postponing the flag maintenance
564-
*isalways allowable.
564+
*So we refrain from updating the DDL flags if we're insidean outer
565+
*transaction. This is OK since postponing the flag maintenance is
566+
*always allowable.
565567
*
566568
*This routine is shared by VACUUM and ANALYZE.
567569
*/
568570
void
569571
vac_update_relstats(Relationrelation,
570572
BlockNumbernum_pages,doublenum_tuples,
571-
boolhasindex,TransactionIdfrozenxid)
573+
boolhasindex,TransactionIdfrozenxid,
574+
boolin_outer_xact)
572575
{
573576
Oidrelid=RelationGetRelid(relation);
574577
Relationrd;
@@ -599,9 +602,9 @@ vac_update_relstats(Relation relation,
599602
dirty= true;
600603
}
601604

602-
/* Apply DDL updates, but not insidea transaction block (see above) */
605+
/* Apply DDL updates, but not insidean outer transaction (see above) */
603606

604-
if (!IsTransactionBlock())
607+
if (!in_outer_xact)
605608
{
606609
/*
607610
* If we didn't find any indexes, reset relhasindex.

‎src/backend/commands/vacuumlazy.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
266266
vac_update_relstats(onerel,
267267
new_rel_pages,new_rel_tuples,
268268
vacrelstats->hasindex,
269-
new_frozen_xid);
269+
new_frozen_xid,
270+
false);
270271

271272
/* report results to the stats collector, too */
272273
pgstat_report_vacuum(RelationGetRelid(onerel),
@@ -1091,7 +1092,9 @@ lazy_cleanup_index(Relation indrel,
10911092
if (!stats->estimated_count)
10921093
vac_update_relstats(indrel,
10931094
stats->num_pages,stats->num_index_tuples,
1094-
false,InvalidTransactionId);
1095+
false,
1096+
InvalidTransactionId,
1097+
false);
10951098

10961099
ereport(elevel,
10971100
(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
@@ -150,7 +150,8 @@ extern void vac_update_relstats(Relation relation,
150150
BlockNumbernum_pages,
151151
doublenum_tuples,
152152
boolhasindex,
153-
TransactionIdfrozenxid);
153+
TransactionIdfrozenxid,
154+
boolin_outer_xact);
154155
externvoidvacuum_set_xid_limits(intfreeze_min_age,intfreeze_table_age,
155156
boolsharedRel,
156157
TransactionId*oldestXmin,
@@ -165,6 +166,6 @@ extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
165166

166167
/* in commands/analyze.c */
167168
externvoidanalyze_rel(Oidrelid,VacuumStmt*vacstmt,
168-
BufferAccessStrategybstrategy);
169+
boolin_outer_xact,BufferAccessStrategybstrategy);
169170

170171
#endif/* VACUUM_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp