|
6 | 6 | * Copyright (c) 1994, Regents of the University of California |
7 | 7 | * |
8 | 8 | * |
9 | | - * $Id: nodeHash.c,v 1.31 1999/02/13 23:15:22 momjian Exp $ |
| 9 | + * $Id: nodeHash.c,v 1.32 1999/04/07 23:33:30 tgl Exp $ |
10 | 10 | * |
11 | 11 | *------------------------------------------------------------------------- |
12 | 12 | */ |
@@ -41,7 +41,7 @@ extern intNBuffers; |
41 | 41 | staticintHashTBSize; |
42 | 42 |
|
43 | 43 | staticvoidmk_hj_temp(char*tempname); |
44 | | -staticinthashFunc(char*key,intlen); |
| 44 | +staticinthashFunc(Datumkey,intlen,boolbyVal); |
45 | 45 | staticintExecHashPartition(Hash*node); |
46 | 46 | staticRelativeAddrhashTableAlloc(intsize,HashJoinTablehashtable); |
47 | 47 | staticvoidExecHashOverflowInsert(HashJoinTablehashtable, |
@@ -580,10 +580,8 @@ ExecHashGetBucket(HashJoinTable hashtable, |
580 | 580 | *compute the hash function |
581 | 581 | * ------------------ |
582 | 582 | */ |
583 | | -if (execConstByVal) |
584 | | -bucketno=hashFunc((char*)&keyval,execConstLen) %hashtable->totalbuckets; |
585 | | -else |
586 | | -bucketno=hashFunc((char*)keyval,execConstLen) %hashtable->totalbuckets; |
| 583 | +bucketno=hashFunc(keyval,execConstLen,execConstByVal) %hashtable->totalbuckets; |
| 584 | + |
587 | 585 | #ifdefHJDEBUG |
588 | 586 | if (bucketno >=hashtable->nbuckets) |
589 | 587 | printf("hash(%d) = %d SAVED\n",keyval,bucketno); |
@@ -771,41 +769,45 @@ ExecScanHashBucket(HashJoinState *hjstate, |
771 | 769 | * ---------------------------------------------------------------- |
772 | 770 | */ |
773 | 771 | staticint |
774 | | -hashFunc(char*key,intlen) |
| 772 | +hashFunc(Datumkey,intlen,boolbyVal) |
775 | 773 | { |
776 | | -unsignedinth; |
777 | | -intl; |
778 | | -unsignedchar*k; |
| 774 | +unsignedinth=0; |
| 775 | +unsignedchar*k; |
779 | 776 |
|
780 | | -/* |
781 | | - * If this is a variable length type, then 'k' points to a "struct |
782 | | - * varlena" and len == -1. NOTE: VARSIZE returns the "real" data |
783 | | - * length plus the sizeof the "vl_len" attribute of varlena (the |
784 | | - * length information). 'k' points to the beginning of the varlena |
785 | | - * struct, so we have to use "VARDATA" to find the beginning of the |
786 | | - * "real" data. |
787 | | - */ |
788 | | -if (len==-1) |
789 | | -{ |
790 | | -l=VARSIZE(key)-VARHDRSZ; |
791 | | -k= (unsignedchar*)VARDATA(key); |
792 | | -} |
793 | | -else |
794 | | -{ |
795 | | -l=len; |
796 | | -k= (unsignedchar*)key; |
| 777 | +if (byVal) { |
| 778 | +/* |
| 779 | + * If it's a by-value data type, use the 'len' least significant bytes |
| 780 | + * of the Datum value. This should do the right thing on either |
| 781 | + * bigendian or littleendian hardware --- see the Datum access |
| 782 | + * macros in c.h. |
| 783 | + */ |
| 784 | +while (len-->0) { |
| 785 | +h= (h*PRIME1) ^ (key&0xFF); |
| 786 | +key >>=8; |
| 787 | +} |
| 788 | +}else { |
| 789 | +/* |
| 790 | + * If this is a variable length type, then 'k' points to a "struct |
| 791 | + * varlena" and len == -1. NOTE: VARSIZE returns the "real" data |
| 792 | + * length plus the sizeof the "vl_len" attribute of varlena (the |
| 793 | + * length information). 'k' points to the beginning of the varlena |
| 794 | + * struct, so we have to use "VARDATA" to find the beginning of the |
| 795 | + * "real" data. |
| 796 | + */ |
| 797 | +if (len==-1) |
| 798 | +{ |
| 799 | +len=VARSIZE(key)-VARHDRSZ; |
| 800 | +k= (unsignedchar*)VARDATA(key); |
| 801 | +} |
| 802 | +else |
| 803 | +{ |
| 804 | +k= (unsignedchar*)key; |
| 805 | +} |
| 806 | +while (len-->0) |
| 807 | +h= (h*PRIME1) ^ (*k++); |
797 | 808 | } |
798 | 809 |
|
799 | | -h=0; |
800 | | - |
801 | | -/* |
802 | | - * Convert string to integer |
803 | | - */ |
804 | | -while (l--) |
805 | | -h=h*PRIME1 ^ (*k++); |
806 | | -h %=PRIME2; |
807 | | - |
808 | | -returnh; |
| 810 | +returnh %PRIME2; |
809 | 811 | } |
810 | 812 |
|
811 | 813 | /* ---------------------------------------------------------------- |
|