Improve hash_array() logic for combining hash values.
The new logic is less vulnerable to transpositions. This invalidates the contents of hash indexes built with the old functions; hence, bump catversion. Dean Rasheed
This commit is contained in:
parent
c58b945e23
commit
7149b128dc
@ -3533,7 +3533,7 @@ hash_array(PG_FUNCTION_ARGS)
|
|||||||
int ndims = ARR_NDIM(array);
|
int ndims = ARR_NDIM(array);
|
||||||
int *dims = ARR_DIMS(array);
|
int *dims = ARR_DIMS(array);
|
||||||
Oid element_type = ARR_ELEMTYPE(array);
|
Oid element_type = ARR_ELEMTYPE(array);
|
||||||
uint32 result = 0;
|
uint32 result = 1;
|
||||||
int nitems;
|
int nitems;
|
||||||
TypeCacheEntry *typentry;
|
TypeCacheEntry *typentry;
|
||||||
int typlen;
|
int typlen;
|
||||||
@ -3617,11 +3617,17 @@ hash_array(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Combine hash values of successive elements by rotating the previous
|
* Combine hash values of successive elements by multiplying the
|
||||||
* value left 1 bit, then XOR'ing in the new element's hash value.
|
* current value by 31 and adding on the new element's hash value.
|
||||||
|
*
|
||||||
|
* The result is a sum in which each element's hash value is
|
||||||
|
* multiplied by a different power of 31. This is modulo 2^32
|
||||||
|
* arithmetic, and the powers of 31 modulo 2^32 form a cyclic group of
|
||||||
|
* order 2^27. So for arrays of up to 2^27 elements, each element's
|
||||||
|
* hash value is multiplied by a different (odd) number, resulting in
|
||||||
|
* a good mixing of all the elements' hash values.
|
||||||
*/
|
*/
|
||||||
result = (result << 1) | (result >> 31);
|
result = (result << 5) - result + elthash;
|
||||||
result ^= elthash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Avoid leaking memory when handed toasted input. */
|
/* Avoid leaking memory when handed toasted input. */
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 201105131
|
#define CATALOG_VERSION_NO 201105231
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user