From 17fbccca274c5b201a59212b679d345141649b8e Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Tue, 19 Jul 2016 16:21:27 +0530 Subject: 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 --- src/backend/pgxc/locator/redistrib.c | 14 ++++++++++---- 1 file 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 */ -- cgit v1.2.3