always picking up the first node.
When planner has a choice of executing a subplan on any of the remote nodes,
it always used to execute the subplan on the first node. That can cause
excessive load/number of connections on that node. This patch fixes that by
choosing a node randomly from the list of available nodes
return DatumGetUInt32(hash_any((const unsigned char *) a->words,
(lastword + 1) * sizeof(bitmapword)));
}
+
+#ifdef XCP
+/*
+ * bms_any_member - return any member from the set randomly
+ *
+ * Returns -1 if set is empty. NB: set is destructively modified!
+ *
+ * CAUTION: this destroys the content of "inputset".
+ */
+int
+bms_any_member(Bitmapset *a)
+{
+ int member;
+ int random = abs(rand()) % bms_num_members(a);
+ for (member = 0; member < random; member++)
+ bms_first_member(a);
+ return bms_first_member(a);
+}
+#endif
if (bms_num_members(tmpset) > 1)
{
/* get one execution node TODO: load balancing */
- nodenum = bms_first_member(tmpset);
+ nodenum = bms_any_member(tmpset);
node->nodeList = list_make1_int(nodenum);
node->execOnAll = true;
}
/* support for hashtables using Bitmapsets as keys: */
extern uint32 bms_hash_value(const Bitmapset *a);
+#ifdef XCP
+extern int bms_any_member(Bitmapset *a);
+#endif
+
#endif /* BITMAPSET_H */