diff options
author | Pavan Deolasee | 2016-07-19 10:51:27 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 10:07:22 +0000 |
commit | 17fbccca274c5b201a59212b679d345141649b8e (patch) | |
tree | 474369209988bb7bc5daa8dceddb921185c9c311 | |
parent | 1c7207109d6863d36fe0f2342f103c1960251dd2 (diff) |
Use 2^32 modulo computation to convert signed integer to unsigned value since
abs() may give a different result.
This makes the redistribution code in sync with the way hash modulo is computed
elsewhere in the code
-rw-r--r-- | src/backend/pgxc/locator/redistrib.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/backend/pgxc/locator/redistrib.c b/src/backend/pgxc/locator/redistrib.c index 3fc36af8d0..e57cf2e7d9 100644 --- a/src/backend/pgxc/locator/redistrib.c +++ b/src/backend/pgxc/locator/redistrib.c @@ -752,8 +752,14 @@ distrib_delete_hash(RedistribState *distribState, ExecNodes *exec_nodes) /* * Then build the WHERE clause for deletion. * The condition that allows to keep the tuples on remote nodes - * is of the type "RemoteNodeNumber != abs(hash_func(dis_col)) % NumDatanodes". - * the remote Datanode has no knowledge of its position in cluster so this + * is of the type "RemoteNodeNumber != (hash_func(dis_col)) % + * NumDatanodes". + * + * (Earlier we were using abs(hashvalue), but that does not render the + * same result as (unsigned int) (signed value). So we must do a modulo + * 2^32 computation. + * + * The remote Datanode has no knowledge of its position in cluster so this * number needs to be compiled locally on Coordinator. * Taking the absolute value is necessary as hash may return a negative value. * For hash distributions a condition with correct hash function is used. @@ -762,11 +768,11 @@ distrib_delete_hash(RedistribState *distribState, ExecNodes *exec_nodes) */ buf2 = makeStringInfo(); if (hashfuncname) - appendStringInfo(buf2, "%s WHERE abs(%s(%s)) %% %d != %d", + appendStringInfo(buf2, "%s WHERE ((2^32 + %s(%s))::bigint %% (2^32)::bigint) %% %d != %d", buf->data, hashfuncname, colname, list_length(locinfo->rl_nodeList), nodepos); else - appendStringInfo(buf2, "%s WHERE abs(%s) %% %d != %d", buf->data, colname, + appendStringInfo(buf2, "%s WHERE ((2^32 + %s)::bigint %% (2^32)::bigint) %% %d != %d", buf->data, colname, list_length(locinfo->rl_nodeList), nodepos); /* Then launch this single query */ |