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

Function cdbhash

src/backend/cdb/cdbhash.c:188–247  ·  view source on GitHub ↗

* Add an attribute to the CdbHash calculation. * * Note: this must be called for each attribute, in order. If you try to hash * the attributes in a different order, you get a different hash value. */

Source from the content-addressed store, hash-verified

186 * the attributes in a different order, you get a different hash value.
187 */
188void
189cdbhash(CdbHash *h, int attno, Datum datum, bool isnull)
190{
191 uint32 hashkey = h->hash;
192
193 if (!h->is_legacy_hash)
194 {
195 /* rotate hashkey left 1 bit at each step */
196 hashkey = (hashkey << 1) | ((hashkey & 0x80000000) ? 1 : 0);
197
198 if (!isnull)
199 {
200 LOCAL_FCINFO(fcinfo, 1);
201 uint32 hkey;
202
203 InitFunctionCallInfoData(*fcinfo, &h->hashfuncs[attno - 1], 1,
204 DEFAULT_COLLATION_OID, /* have to specify collation for attribute of text or bpchar */
205 NULL, NULL);
206
207 fcinfo->args[0].value = datum;
208 fcinfo->args[0].isnull = false;
209
210 hkey = DatumGetUInt32(FunctionCallInvoke(fcinfo));
211
212 /* Check for null result, since caller is clearly not expecting one */
213 if (fcinfo->isnull)
214 elog(ERROR, "function %u returned NULL", fcinfo->flinfo->fn_oid);
215
216 hashkey ^= hkey;
217 }
218 }
219 else
220 {
221 magic_hash_stash = hashkey;
222 if (!isnull)
223 {
224 LOCAL_FCINFO(fcinfo, 1);
225 uint32 hkey;
226
227 InitFunctionCallInfoData(*fcinfo, &h->hashfuncs[attno - 1], 1,
228 DEFAULT_COLLATION_OID, /* legacy hash functions don't care about collations */
229 NULL, NULL);
230
231 fcinfo->args[0].value = datum;
232 fcinfo->args[0].isnull = false;
233
234 hkey = DatumGetUInt32(FunctionCallInvoke(fcinfo));
235
236 /* Check for null result, since caller is clearly not expecting one */
237 if (fcinfo->isnull)
238 elog(ERROR, "function %u returned NULL", fcinfo->flinfo->fn_oid);
239
240 hashkey = hkey;
241 }
242 else
243 hashkey = cdblegacyhash_null();
244 magic_hash_stash = FNV1_32_INIT;
245 }

Callers 9

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

Calls 2

DatumGetUInt32Function · 0.85
cdblegacyhash_nullFunction · 0.85

Tested by

no test coverage detected