MCPcopy Create free account
hub / github.com/apache/cloudberry / cdbhashreduce

Function cdbhashreduce

src/backend/cdb/cdbhash.c:252–285  ·  view source on GitHub ↗

* Reduce the hash to a segment number. */

Source from the content-addressed store, hash-verified

250 * Reduce the hash to a segment number.
251 */
252unsigned int
253cdbhashreduce(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.

Callers 9

GetTargetSegFunction · 0.85
cdbhash_const_listFunction · 0.85
evalHashKeyFunction · 0.85
TupleMatchesHashFilterFunction · 0.85
ExecInsertFunction · 0.85
evalHashKeyFunction · 0.85

Calls 1

jump_consistent_hashFunction · 0.85

Tested by

no test coverage detected