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

Commit2c22afa

Browse files
committed
hash_any returns Datum, not uint32 (and definitely not "int").
The coding in JsonbHashScalarValue might have accidentally failed to failgiven current representational choices, but the key word there would be"accidental". Insert the appropriate datatype conversion macro. Anduse the right conversion macro for hash_numeric's result, too.In passing make the code a bit cleaner and less repetitive by factoringout the xor step from the switch.
1 parent35c0cd3 commit2c22afa

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ arrayToJsonbSortedArray(ArrayType *array)
11141114
}
11151115

11161116
/*
1117-
* Hash a JsonbValue scalar value, mixinginthe hash valuewith an existing
1117+
* Hash a JsonbValue scalar value, mixing the hash valueinto an existing
11181118
* hash provided by the caller.
11191119
*
11201120
* Some callers may wish to independently XOR in JB_FOBJECT and JB_FARRAY
@@ -1123,36 +1123,39 @@ arrayToJsonbSortedArray(ArrayType *array)
11231123
void
11241124
JsonbHashScalarValue(constJsonbValue*scalarVal,uint32*hash)
11251125
{
1126-
inttmp;
1126+
uint32tmp;
11271127

1128-
/*
1129-
* Combine hash values of successive keys, values and elements by rotating
1130-
* the previous value left 1 bit, then XOR'ing in the new
1131-
* key/value/element's hash value.
1132-
*/
1133-
*hash= (*hash <<1) | (*hash >>31);
1128+
/* Compute hash value for scalarVal */
11341129
switch (scalarVal->type)
11351130
{
11361131
casejbvNull:
1137-
*hash ^=0x01;
1138-
return;
1132+
tmp=0x01;
1133+
break;
11391134
casejbvString:
1140-
tmp=hash_any((unsignedchar*)scalarVal->val.string.val,
1141-
scalarVal->val.string.len);
1142-
*hash ^=tmp;
1143-
return;
1135+
tmp=DatumGetUInt32(hash_any((constunsignedchar*)scalarVal->val.string.val,
1136+
scalarVal->val.string.len));
1137+
break;
11441138
casejbvNumeric:
1145-
/* Mustbe unaffected by trailing zeroes */
1146-
tmp=DatumGetInt32(DirectFunctionCall1(hash_numeric,
1139+
/* Musthash equal numerics to equal hash codes */
1140+
tmp=DatumGetUInt32(DirectFunctionCall1(hash_numeric,
11471141
NumericGetDatum(scalarVal->val.numeric)));
1148-
*hash ^=tmp;
1149-
return;
1142+
break;
11501143
casejbvBool:
1151-
*hash ^=scalarVal->val.boolean ?0x02 :0x04;
1152-
return;
1144+
tmp=scalarVal->val.boolean ?0x02 :0x04;
1145+
break;
11531146
default:
11541147
elog(ERROR,"invalid jsonb scalar type");
1148+
tmp=0;/* keep compiler quiet */
1149+
break;
11551150
}
1151+
1152+
/*
1153+
* Combine hash values of successive keys, values and elements by rotating
1154+
* the previous value left 1 bit, then XOR'ing in the new
1155+
* key/value/element's hash value.
1156+
*/
1157+
*hash= (*hash <<1) | (*hash >>31);
1158+
*hash ^=tmp;
11561159
}
11571160

11581161
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp