summaryrefslogtreecommitdiff
path: root/src/backend/commands/analyze.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-10-30 13:03:31 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-10-30 13:03:31 -0400
commit38cb8687a9dde85b1dad3d347ab420ecdf2259b7 (patch)
treee328d92226aa0fb984db7014f455d007960aaacb /src/backend/commands/analyze.c
parent40058fbcecf66b39ad5c608d3bda55d56df8b795 (diff)
Test IsInTransactionChain, not IsTransactionBlock, in vac_update_relstats.
As noted by Noah Misch, my initial cut at fixing bug #11638 didn't cover all cases where ANALYZE might be invoked in an unsafe context. We need to test the result of IsInTransactionChain not IsTransactionBlock; which is notationally a pain because IsInTransactionChain requires an isTopLevel flag, 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 apropos for the intermediate functions to know about.
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r--src/backend/commands/analyze.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 376a57a1245..62774a90fc0 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -85,7 +85,7 @@ static BufferAccessStrategy vac_strategy;
static void do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
AcquireSampleRowsFunc acquirefunc, BlockNumber relpages,
- bool inh, int elevel);
+ bool inh, bool in_outer_xact, int elevel);
static void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks,
int samplesize);
static bool BlockSampler_HasMore(BlockSampler bs);
@@ -113,7 +113,8 @@ static Datum ind_fetch_func(VacAttrStatsP stats, int rownum, bool *isNull);
* analyze_rel() -- analyze one relation
*/
void
-analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
+analyze_rel(Oid relid, VacuumStmt *vacstmt,
+ bool in_outer_xact, BufferAccessStrategy bstrategy)
{
Relation onerel;
int elevel;
@@ -262,13 +263,15 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
/*
* Do the normal non-recursive ANALYZE.
*/
- do_analyze_rel(onerel, vacstmt, acquirefunc, relpages, false, elevel);
+ do_analyze_rel(onerel, vacstmt, acquirefunc, relpages,
+ false, in_outer_xact, elevel);
/*
* If there are child tables, do recursive ANALYZE.
*/
if (onerel->rd_rel->relhassubclass)
- do_analyze_rel(onerel, vacstmt, acquirefunc, relpages, true, elevel);
+ do_analyze_rel(onerel, vacstmt, acquirefunc, relpages,
+ true, in_outer_xact, elevel);
/*
* Close source relation now, but keep lock so that no one deletes it
@@ -298,7 +301,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
static void
do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
AcquireSampleRowsFunc acquirefunc, BlockNumber relpages,
- bool inh, int elevel)
+ bool inh, bool in_outer_xact, int elevel)
{
int attr_cnt,
tcnt,
@@ -580,7 +583,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
totalrows,
visibilitymap_count(onerel),
hasindex,
- InvalidTransactionId);
+ InvalidTransactionId,
+ in_outer_xact);
/*
* Same for indexes. Vacuum always scans all indexes, so if we're part of
@@ -600,7 +604,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
totalindexrows,
0,
false,
- InvalidTransactionId);
+ InvalidTransactionId,
+ in_outer_xact);
}
}