#include <LhxHashGenerator.h>
Public Member Functions | |
void | init (uint levelInit) |
Initialize the generator. | |
uint | getLevel () |
Get level information for this hash generator. | |
uint | hash (TupleData const &inputTuple, TupleProjection const &keyProjection, vector< LhxHashTrim > const &isKeyColVarChar) |
Compute hash value for a TupleData, on both value and length information. | |
uint | hash (TupleDatum const &inputCol, LhxHashTrim isVarChar) |
Compute hash value for a TupleDatum, on both value and length information. | |
uint | hash (PConstBuffer pBuf, uint bufSize) |
Compute hash value from value stored in a buffer. | |
Private Member Functions | |
void | hashOneBuffer (uint &hashValue, PConstBuffer pBuf, uint bufSize) |
Compute hash value from value stored in a buffer. | |
void | hashOneColumn (uint &hashValue, TupleDatum const &inputCol, LhxHashTrim isVarChar) |
Compute hash value, from both value and length information, for a TupleDatum. | |
Private Attributes | |
uint | level |
uint | hashValueSeed |
uint8_t * | magicTable |
Definition at line 43 of file LhxHashGenerator.h.
void LhxHashGenerator::hashOneBuffer | ( | uint & | hashValue, | |
PConstBuffer | pBuf, | |||
uint | bufSize | |||
) | [private] |
Compute hash value from value stored in a buffer.
[out] | hashValue | |
[in] | pBuf | buffer containing the value |
[in] | bufSize | size of the buffer |
Definition at line 86 of file LhxHashGenerator.cpp.
References count(), and magicTable.
Referenced by hash(), and hashOneColumn().
00090 { 00091 uint numValueBytes = sizeof(uint); 00092 uint8_t byteForNull = 0xff; 00093 00094 if (pBuf == NULL) { 00095 bufSize = 1; 00096 pBuf = &byteForNull; 00097 } 00098 00099 for (int count = 0; count < bufSize; count ++) { 00100 PBuffer pByte = (PBuffer) &hashValue; 00101 00102 for (int i = 0; i < numValueBytes; i++) { 00103 *pByte = magicTable[(*pByte) ^ (*pBuf)]; 00104 pByte ++; 00105 } 00106 00107 pBuf ++; 00108 } 00109 }
void LhxHashGenerator::hashOneColumn | ( | uint & | hashValue, | |
TupleDatum const & | inputCol, | |||
LhxHashTrim | isVarChar | |||
) | [private] |
Compute hash value, from both value and length information, for a TupleDatum.
[out] | hashValue | |
[in] | inputCol | input TupleDatum |
[in] | isVarChar | if col is varchar type |
Definition at line 111 of file LhxHashGenerator.cpp.
References TupleDatum::cbData, HASH_TRIM_UNICODE_VARCHAR, HASH_TRIM_VARCHAR, hashOneBuffer(), and TupleDatum::pData.
Referenced by hash().
00115 { 00116 uint trimmedLength = inputCol.cbData; 00117 PConstBuffer pData = inputCol.pData; 00118 00119 if (pData) { 00120 /* 00121 * Only hash to the trimmed value. 00122 */ 00123 if (isVarChar == HASH_TRIM_VARCHAR) { 00124 PConstBuffer pChar = pData + trimmedLength - 1; 00125 while ((pChar >= pData) && (*pChar == ' ')) { 00126 --pChar; 00127 } 00128 trimmedLength = pChar - pData + 1; 00129 } else if (isVarChar == HASH_TRIM_UNICODE_VARCHAR) { 00130 PConstBuffer pChar = pData + trimmedLength - 2; 00131 while ((pChar >= pData) 00132 && (*reinterpret_cast<uint16_t const *>(pChar) == ' ')) 00133 { 00134 pChar -= 2; 00135 } 00136 trimmedLength = pChar - pData + 2; 00137 } 00138 } 00139 00140 // REVIEW jvs 25-Aug-2006: Since the call below uses 00141 // sizeof(TupleStorageByteLength), shouldn't trimmedLength 00142 // be declared to match? 00143 00144 /* 00145 * First hash the length 00146 * However, ignore length field if pData is NULL. 00147 */ 00148 if (pData) { 00149 hashOneBuffer( 00150 hashValue, 00151 (PConstBuffer) &(trimmedLength), 00152 sizeof(TupleStorageByteLength)); 00153 } 00154 00155 /* 00156 * then hash the data buffer 00157 */ 00158 hashOneBuffer( 00159 hashValue, 00160 pData, 00161 trimmedLength); 00162 }
void LhxHashGenerator::init | ( | uint | levelInit | ) |
Initialize the generator.
Different levels have different seed values.
Definition at line 58 of file LhxHashGenerator.cpp.
References hashValueSeed, level, LhxHashGeneratorMagicTable, and magicTable.
Referenced by LhxPlan::createChildren(), LhxPlan::generatePartitions(), and LhxHashTable::init().
00059 { 00060 /* 00061 * The seed computation can generate different seeds for only levels 0 - 63 00062 * Level 64 will have the same seed as level 0. So if recursive 00063 * partitioning goes to 64 level, no further partitioning is possible. 00064 */ 00065 if (levelInit > 63) { 00066 ostringstream errMsg; 00067 errMsg << " Hash recursion level can not be deeper than 63"; 00068 throw FennelExcn(errMsg.str()); 00069 } 00070 00071 level = levelInit; 00072 magicTable = LhxHashGeneratorMagicTable; 00073 00074 uint base = level * 4; 00075 hashValueSeed 00076 = (uint8_t(base) << 24) 00077 | (uint8_t(base + 1) << 16) 00078 | (uint8_t(base + 2) << 8) 00079 | (uint8_t(base + 3)); 00080 }
uint LhxHashGenerator::getLevel | ( | ) | [inline] |
Get level information for this hash generator.
Definition at line 138 of file LhxHashGenerator.h.
References level.
00139 { 00140 return level; 00141 }
uint LhxHashGenerator::hash | ( | TupleData const & | inputTuple, | |
TupleProjection const & | keyProjection, | |||
vector< LhxHashTrim > const & | isKeyColVarChar | |||
) |
Compute hash value for a TupleData, on both value and length information.
[in] | inputTuple | |
[in] | keyProjection | which fields in the input tuple are used |
[in] | isKeyColVarChar | a vector indicating if the corresponding hash key is of varchar type. The trailing blanks in varchar types are insignificant in both comparison and hash value computation. |
Definition at line 164 of file LhxHashGenerator.cpp.
References hashOneColumn(), and hashValueSeed.
Referenced by LhxHashTable::addKeyData(), LhxPlan::createChildren(), LhxHashTable::findKeyLocation(), and LhxPlan::generatePartitions().
00168 { 00169 uint keyLength = keyProjection.size(); 00170 00171 /* 00172 * get initial hash value of 4 bytes. 00173 */ 00174 uint hashValue = hashValueSeed; 00175 00176 for (int i = 0; i < keyLength; i++) { 00177 TupleDatum const &col = inputTuple[keyProjection[i]]; 00178 hashOneColumn(hashValue, col, isKeyColVarChar[i]); 00179 } 00180 00181 /* 00182 * Note: if key size == 0 then the hash value is the same as the seed value. 00183 * This is the case for single group aggregate. 00184 */ 00185 return hashValue; 00186 }
uint LhxHashGenerator::hash | ( | TupleDatum const & | inputCol, | |
LhxHashTrim | isVarChar | |||
) | [inline] |
Compute hash value for a TupleDatum, on both value and length information.
[in] | inputCol | |
[in] | isVarChar | if col is varchar type |
Definition at line 143 of file LhxHashGenerator.h.
References hashOneColumn(), and hashValueSeed.
00145 { 00146 uint hashValue = hashValueSeed; 00147 hashOneColumn(hashValue, inputCol, isVarChar); 00148 return hashValue; 00149 }
uint LhxHashGenerator::hash | ( | PConstBuffer | pBuf, | |
uint | bufSize | |||
) | [inline] |
Compute hash value from value stored in a buffer.
[in] | pBuf | buffer containing the value |
[in] | bufSize | size of the buffer |
Definition at line 151 of file LhxHashGenerator.h.
References hashOneBuffer(), and hashValueSeed.
00152 { 00153 uint hashValue = hashValueSeed; 00154 hashOneBuffer(hashValue, pBuf, bufSize); 00155 return hashValue; 00156 }
uint LhxHashGenerator::level [private] |
uint LhxHashGenerator::hashValueSeed [private] |
uint8_t* LhxHashGenerator::magicTable [private] |