aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/analyze.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-10-30 13:03:28 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-10-30 13:03:28 -0400
commite65b550b37ec25102813d8e39eeb70f0c7944433 (patch)
treeafad536ae1e512d92dd48284d92ed595ccc7bb28 /src/backend/commands/analyze.c
parent81f0a5e38a05811f762b1dec9d344be923025f40 (diff)
downloadpostgresql-e65b550b37ec25102813d8e39eeb70f0c7944433.tar.gz
postgresql-e65b550b37ec25102813d8e39eeb70f0c7944433.zip
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 38560d11273..801df26945d 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -86,7 +86,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);
@@ -114,7 +114,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;
@@ -264,13 +265,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
@@ -300,7 +303,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,
@@ -583,7 +586,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
visibilitymap_count(onerel),
hasindex,
InvalidTransactionId,
- InvalidMultiXactId);
+ InvalidMultiXactId,
+ in_outer_xact);
/*
* Same for indexes. Vacuum always scans all indexes, so if we're part of
@@ -604,7 +608,8 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
0,
false,
InvalidTransactionId,
- InvalidMultiXactId);
+ InvalidMultiXactId,
+ in_outer_xact);
}
}