From: Pavan Deolasee Date: Tue, 19 Jul 2016 10:51:27 +0000 (+0530) Subject: Use 2^32 modulo computation to convert signed integer to unsigned value since X-Git-Tag: XL9_5_R1_2~16 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=34d2c2362b8856c736e0e2567301e4e461e30aba;p=postgres-xl.git 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 --- 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 */