diff options
author | Pavan Deolasee | 2016-01-25 09:32:34 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 09:46:50 +0000 |
commit | 5cf84ee37b49c36e77fe2aa5d5b75c1bf88697de (patch) | |
tree | 1e9e7ae0235c629d8e653ab2c0d60a6a4ff2c89e | |
parent | b045ec592400177b818d4931c954f1fd9a0ffbb1 (diff) |
Fix a bug where we will pick up random nodes for individual replicated tables,
thus reducing the chances of query getting fully shipped to the remote node.
We now remember all nodes that can satify a READ request for a replicated table
and then finally choose a node randomly if no preferred datanode is specified.
This will avoid non-deterministic selection of FQS query plans as well as allow
us to send some more queries to the remote node.
-rw-r--r-- | src/backend/optimizer/util/pgxcship.c | 8 | ||||
-rw-r--r-- | src/backend/pgxc/locator/locator.c | 6 | ||||
-rw-r--r-- | src/include/pgxc/locator.h | 1 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/backend/optimizer/util/pgxcship.c b/src/backend/optimizer/util/pgxcship.c index 2e4e940413..2197abe7f4 100644 --- a/src/backend/optimizer/util/pgxcship.c +++ b/src/backend/optimizer/util/pgxcship.c @@ -406,7 +406,8 @@ pgxc_FQS_find_datanodes(Query *query) * preferred node choose that one, otherwise choose the first one. */ if (IsLocatorReplicated(exec_nodes->baselocatortype) && - exec_nodes->accesstype == RELATION_ACCESS_READ) + (exec_nodes->accesstype == RELATION_ACCESS_READ || + exec_nodes->accesstype == RELATION_ACCESS_READ_FQS)) { List *tmp_list = exec_nodes->nodeList; exec_nodes->nodeList = GetPreferredReplicationNode(exec_nodes->nodeList); @@ -450,7 +451,7 @@ pgxc_FQS_get_relation_nodes(RangeTblEntry *rte, Index varno, Query *query) if (for_update) rel_access = RELATION_ACCESS_READ_FOR_UPDATE; else - rel_access = RELATION_ACCESS_READ; + rel_access = RELATION_ACCESS_READ_FQS; break; case CMD_UPDATE: @@ -1556,7 +1557,8 @@ pgxc_merge_exec_nodes(ExecNodes *en1, ExecNodes *en2) if (en1->primarynodelist || en2->primarynodelist || en1->en_expr || en2->en_expr || OidIsValid(en1->en_relid) || OidIsValid(en2->en_relid) || - en1->accesstype != RELATION_ACCESS_READ || en2->accesstype != RELATION_ACCESS_READ) + (en1->accesstype != RELATION_ACCESS_READ && en1->accesstype != RELATION_ACCESS_READ_FQS) || + (en2->accesstype != RELATION_ACCESS_READ && en2->accesstype != RELATION_ACCESS_READ_FQS)) return NULL; if (IsExecNodesReplicated(en1) && diff --git a/src/backend/pgxc/locator/locator.c b/src/backend/pgxc/locator/locator.c index e9c6cb8273..2ee9e27295 100644 --- a/src/backend/pgxc/locator/locator.c +++ b/src/backend/pgxc/locator/locator.c @@ -203,7 +203,8 @@ GetPreferredReplicationNode(List *relNodes) break; } if (nodeid < 0) - return list_make1_int(linitial_int(relNodes)); + return list_make1_int(list_nth_int(relNodes, + ((unsigned int) random()) % list_length(relNodes))); return list_make1_int(nodeid); } @@ -1005,7 +1006,8 @@ createLocator(char locatorType, RelationAccessType accessType, { case LOCATOR_TYPE_REPLICATED: if (accessType == RELATION_ACCESS_INSERT || - accessType == RELATION_ACCESS_UPDATE) + accessType == RELATION_ACCESS_UPDATE || + accessType == RELATION_ACCESS_READ_FQS) { locator->locatefunc = locate_static; if (nodeMap == NULL) diff --git a/src/include/pgxc/locator.h b/src/include/pgxc/locator.h index a5501ce0d4..dd4892da02 100644 --- a/src/include/pgxc/locator.h +++ b/src/include/pgxc/locator.h @@ -53,6 +53,7 @@ typedef int PartAttrNumber; typedef enum { RELATION_ACCESS_READ, /* SELECT */ + RELATION_ACCESS_READ_FQS, /* SELECT for FQS */ RELATION_ACCESS_READ_FOR_UPDATE, /* SELECT FOR UPDATE */ RELATION_ACCESS_UPDATE, /* UPDATE OR DELETE */ RELATION_ACCESS_INSERT /* INSERT */ |