* If tuple is NULL, use the input slot instead. This convention avoids the * need to materialize virtual input tuples unless they actually need to get * copied into the table. * * Also, the caller must select an appropriate memory context for running * the hash functions. (dynahash.c doesn't change CurrentMemoryContext.) */
| 434 | * the hash functions. (dynahash.c doesn't change CurrentMemoryContext.) |
| 435 | */ |
| 436 | static uint32 |
| 437 | TupleHashTableHash_internal(struct tuplehash_hash *tb, |
| 438 | const MinimalTuple tuple) |
| 439 | { |
| 440 | TupleHashTable hashtable = (TupleHashTable) tb->private_data; |
| 441 | int numCols = hashtable->numCols; |
| 442 | AttrNumber *keyColIdx = hashtable->keyColIdx; |
| 443 | uint32 hashkey = hashtable->hash_iv; |
| 444 | TupleTableSlot *slot; |
| 445 | FmgrInfo *hashfunctions; |
| 446 | int i; |
| 447 | |
| 448 | if (tuple == NULL) |
| 449 | { |
| 450 | /* Process the current input tuple for the table */ |
| 451 | slot = hashtable->inputslot; |
| 452 | hashfunctions = hashtable->in_hash_funcs; |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | /* |
| 457 | * Process a tuple already stored in the table. |
| 458 | * |
| 459 | * (this case never actually occurs due to the way simplehash.h is |
| 460 | * used, as the hash-value is stored in the entries) |
| 461 | */ |
| 462 | slot = hashtable->tableslot; |
| 463 | ExecStoreMinimalTuple(tuple, slot, false); |
| 464 | hashfunctions = hashtable->tab_hash_funcs; |
| 465 | } |
| 466 | |
| 467 | for (i = 0; i < numCols; i++) |
| 468 | { |
| 469 | AttrNumber att = keyColIdx[i]; |
| 470 | Datum attr; |
| 471 | bool isNull; |
| 472 | |
| 473 | /* rotate hashkey left 1 bit at each step */ |
| 474 | hashkey = (hashkey << 1) | ((hashkey & 0x80000000) ? 1 : 0); |
| 475 | |
| 476 | attr = slot_getattr(slot, att, &isNull); |
| 477 | |
| 478 | if (!isNull) /* treat nulls as having hash key 0 */ |
| 479 | { |
| 480 | uint32 hkey; |
| 481 | |
| 482 | hkey = DatumGetUInt32(FunctionCall1Coll(&hashfunctions[i], |
| 483 | hashtable->tab_collations[i], |
| 484 | attr)); |
| 485 | hashkey ^= hkey; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * The way hashes are combined above, among each other and with the IV, |
| 491 | * doesn't lead to good bit perturbation. As the IV's goal is to lead to |
| 492 | * achieve that, perform a round of hashing of the combined hash - |
| 493 | * resulting in near perfect perturbation. |
no test coverage detected