static void analyze_rel_coordinator(Relation onerel, bool inh, int attr_cnt,
VacAttrStats **vacattrstats, int nindexes,
Relation *indexes, AnlIndexData *indexdata);
+static void analyze_remote_coordinators(Relation onerel);
#endif
/*
analyze_rel_coordinator(onerel, inh, attr_cnt, vacattrstats,
nindexes, Irel, indexdata);
+ /*
+ * Run ANALYZE on remote coordinators as well.
+ */
+ analyze_remote_coordinators(onerel);
+
/*
* Skip acquiring local stats. Coordinator does not store data of
* distributed tables.
/* extended statistics (pg_statistic) for the relation */
coord_collect_extended_stats(onerel, attr_cnt);
}
+
+static void
+analyze_remote_coordinators(Relation onerel)
+{
+ RemoteQuery *step;
+ StringInfoData sql;
+
+ if (IsConnFromCoord())
+ return;
+
+ /*
+ * Temporary tables are not available on remote coordinators.
+ */
+ if (onerel->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
+ return;
+
+ initStringInfo(&sql);
+ appendStringInfo(&sql, "ANALYZE (COORDINATOR) %s",
+ quote_identifier(RelationGetRelationName(onerel)));
+
+ step = makeNode(RemoteQuery);
+ step->combine_type = COMBINE_TYPE_SAME;
+ step->exec_nodes = NULL;
+ step->exec_type = EXEC_ON_AVAILABLE_COORDS;
+ step->sql_statement = pstrdup(sql.data);
+
+ ExecRemoteUtility(step);
+ pfree(step->sql_statement);
+ pfree(step);
+
+ /* Be sure to advance the command counter after the last command */
+ CommandCounterIncrement();
+}
#endif
}
+/*
+ * Return a list of all currently available Coordinators. This is used to send
+ * commands to only those coordinators which are currently reachable per the
+ * health map, thus avoiding possible connection errors. Non-critical functions
+ * may use this list.
+ */
+List *
+GetAvailableCoordNodes(void)
+{
+ int i;
+ List *nodeList = NIL;
+ Oid coOids[MaxCoords];
+ bool coHealthMap[MaxCoords];
+ int numCo;
+
+ PgxcNodeGetHealthMap(coOids, NULL, &numCo, NULL, coHealthMap, NULL);
+
+ for (i = 0; i < numCo; i++)
+ {
+ /*
+ * Do not put in list the Coordinator we are on,
+ * it doesn't make sense to connect to the local Coordinator.
+ */
+
+ if ((i != PGXCNodeId - 1) && coHealthMap[i])
+ nodeList = lappend_int(nodeList, i);
+ }
+
+ return nodeList;
+}
+
/*
* Build locator information associated with the specified relation.
*/
coordlist = GetAllCoordNodes();
co_conn_count = list_length(coordlist);
}
+ else if (list_length(coordlist) == 0 &&
+ exec_type == EXEC_ON_AVAILABLE_COORDS)
+ {
+ coordlist = GetAvailableCoordNodes();
+ co_conn_count = list_length(coordlist);
+ }
else
{
if (exec_type == EXEC_ON_COORDS)
extern bool IsTypeHashDistributable(Oid col_type);
extern List *GetAllDataNodes(void);
extern List *GetAllCoordNodes(void);
+extern List *GetAvailableCoordNodes(void);
extern int GetAnyDataNode(Bitmapset *nodes);
extern void RelationBuildLocator(Relation rel);
extern void FreeRelationLocInfo(RelationLocInfo *relationLocInfo);