Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7149b12

Browse files
committed
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 oldfunctions; hence, bump catversion.Dean Rasheed
1 parentc58b945 commit7149b12

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

‎src/backend/utils/adt/arrayfuncs.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,7 +3533,7 @@ hash_array(PG_FUNCTION_ARGS)
35333533
intndims=ARR_NDIM(array);
35343534
int*dims=ARR_DIMS(array);
35353535
Oidelement_type=ARR_ELEMTYPE(array);
3536-
uint32result=0;
3536+
uint32result=1;
35373537
intnitems;
35383538
TypeCacheEntry*typentry;
35393539
inttyplen;
@@ -3617,11 +3617,17 @@ hash_array(PG_FUNCTION_ARGS)
36173617
}
36183618

36193619
/*
3620-
* Combine hash values of successive elements by rotating the previous
3621-
* value left 1 bit, then XOR'ing in the new element's hash value.
3620+
* Combine hash values of successive elements by multiplying the
3621+
* current value by 31 and adding on the new element's hash value.
3622+
*
3623+
* The result is a sum in which each element's hash value is
3624+
* multiplied by a different power of 31. This is modulo 2^32
3625+
* arithmetic, and the powers of 31 modulo 2^32 form a cyclic group of
3626+
* order 2^27. So for arrays of up to 2^27 elements, each element's
3627+
* hash value is multiplied by a different (odd) number, resulting in
3628+
* a good mixing of all the elements' hash values.
36223629
*/
3623-
result= (result <<1) | (result >>31);
3624-
result ^=elthash;
3630+
result= (result <<5)-result+elthash;
36253631
}
36263632

36273633
/* Avoid leaking memory when handed toasted input. */

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201105131
56+
#defineCATALOG_VERSION_NO201105231
5757

5858
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp