* Reduce the hash to a segment number. */
| 250 | * Reduce the hash to a segment number. |
| 251 | */ |
| 252 | unsigned int |
| 253 | cdbhashreduce(CdbHash *h) |
| 254 | { |
| 255 | int result = 0; /* TODO: what is a good initialization value? |
| 256 | * could we guarantee at this point that there |
| 257 | * will not be a negative segid in Cloudberry |
| 258 | * Database and therefore initialize to this |
| 259 | * value for error checking? */ |
| 260 | |
| 261 | Assert(h->reducealg == REDUCE_BITMASK || |
| 262 | h->reducealg == REDUCE_LAZYMOD || |
| 263 | h->reducealg == REDUCE_JUMP_HASH); |
| 264 | Assert(h->natts > 0); |
| 265 | |
| 266 | /* |
| 267 | * Reduce our 32-bit hash value to a segment number |
| 268 | */ |
| 269 | switch (h->reducealg) |
| 270 | { |
| 271 | case REDUCE_BITMASK: |
| 272 | result = FASTMOD(h->hash, (uint32) h->numsegs); /* fast mod (bitmask) */ |
| 273 | break; |
| 274 | |
| 275 | case REDUCE_LAZYMOD: |
| 276 | result = (h->hash) % (h->numsegs); /* simple mod */ |
| 277 | break; |
| 278 | |
| 279 | case REDUCE_JUMP_HASH: |
| 280 | result = jump_consistent_hash(h->hash, h->numsegs); |
| 281 | break; |
| 282 | } |
| 283 | |
| 284 | return result; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Return a random segment number, for randomly distributed policy. |
no test coverage detected