summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2015-08-05 05:04:02 +0000
committerPavan Deolasee2015-08-05 05:04:02 +0000
commit2baaab103d58c01714320507c21296be2c0cd1cc (patch)
treed45867b244e73ce24b05a7bcf7432e3e6e82ab15
parentbc78e505b9ce036f72fd06151242bf32f51c39df (diff)
Fix issues with ANALYZE command
ANALYZE command was failing to fetch the relation statistics such as relpages and reltuples from the datanodes. This could result gross planner errors and generation of very bad plans, as seen in DBT3 benchmark. We now pull relation stats from the datanodes at ANALYZE time, just the way we do at VACUUM time. There was also a lingering bug where the results of ANALYZE command on a datanode won't be available to the coordinator. This turned out to be because of using a stale snapshot and hence coordinator fails to see the new data generated by previous ANALYZE command. We fix that by taking a fresh snapshot at the coordinator and sending that down to the datanodes
-rw-r--r--src/backend/commands/analyze.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 3503b7df18..681982a1f8 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -419,6 +419,11 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
if (IS_PGXC_COORDINATOR && onerel->rd_locator_info)
{
/*
+ * Fetch relation statistics from remote nodes and update
+ */
+ vacuum_rel_coordinator(onerel, in_outer_xact);
+
+ /*
* Fetch attribute statistics from remote nodes.
*/
analyze_rel_coordinator(onerel, inh, attr_cnt, vacattrstats);
@@ -2873,6 +2878,12 @@ analyze_rel_coordinator(Relation onerel, bool inh, int attr_cnt,
oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
+ /*
+ * Take a fresh snapshot so that we see the effects of the ANALYZE command
+ * on the datanode. That command is run in auto-commit mode hence just
+ * bumping up the command ID is not good enough
+ */
+ PushActiveSnapshot(GetTransactionSnapshot());
estate->es_snapshot = GetActiveSnapshot();
node = ExecInitRemoteQuery(step, estate, 0);
@@ -2884,6 +2895,7 @@ analyze_rel_coordinator(Relation onerel, bool inh, int attr_cnt,
numnodes[i] = 0;
result = ExecRemoteQuery(node);
+ PopActiveSnapshot();
while (result != NULL && !TupIsNull(result))
{
Datum value;