* 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. */
| 186 | * the attributes in a different order, you get a different hash value. |
| 187 | */ |
| 188 | void |
| 189 | cdbhash(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 | } |
no test coverage detected