]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix various hash function uses
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 5 Aug 2025 09:38:34 +0000 (11:38 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 5 Aug 2025 09:47:23 +0000 (11:47 +0200)
These instances were using Datum-returning functions where a
lower-level function returning uint32 would be more appropriate.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/8246d7ff-f4b7-4363-913e-827dadfeb145%40eisentraut.org

contrib/sepgsql/uavc.c
src/backend/access/common/tupdesc.c
src/backend/storage/file/fileset.c
src/backend/utils/adt/multirangetypes.c
src/backend/utils/adt/rangetypes.c
src/backend/utils/cache/catcache.c

index 65ea8e7946a6e9c1a688394c3152d9e1a052a67b..d9ccbc38bc538e9f73286ef42ba054a50f42afab 100644 (file)
@@ -66,8 +66,8 @@ static char *avc_unlabeled;           /* system 'unlabeled' label */
 static uint32
 sepgsql_avc_hash(const char *scontext, const char *tcontext, uint16 tclass)
 {
-       return hash_any((const unsigned char *) scontext, strlen(scontext))
-               ^ hash_any((const unsigned char *) tcontext, strlen(tcontext))
+       return hash_bytes((const unsigned char *) scontext, strlen(scontext))
+               ^ hash_bytes((const unsigned char *) tcontext, strlen(tcontext))
                ^ tclass;
 }
 
index 020d00cd01ce76f9aa263d46178b7c27d85fd1eb..be60005ae46005a6223b3f6e9ab5dc8a64d8981b 100644 (file)
@@ -815,10 +815,10 @@ hashRowType(TupleDesc desc)
        uint32          s;
        int                     i;
 
-       s = hash_combine(0, hash_uint32(desc->natts));
-       s = hash_combine(s, hash_uint32(desc->tdtypeid));
+       s = hash_combine(0, hash_bytes_uint32(desc->natts));
+       s = hash_combine(s, hash_bytes_uint32(desc->tdtypeid));
        for (i = 0; i < desc->natts; ++i)
-               s = hash_combine(s, hash_uint32(TupleDescAttr(desc, i)->atttypid));
+               s = hash_combine(s, hash_bytes_uint32(TupleDescAttr(desc, i)->atttypid));
 
        return s;
 }
index 64141c7cb91c99588d8e719859de2b61736ce980..4d5ee353fd7a078688164730f6c71b0058f7ed06 100644 (file)
@@ -185,7 +185,7 @@ FileSetPath(char *path, FileSet *fileset, Oid tablespace)
 static Oid
 ChooseTablespace(const FileSet *fileset, const char *name)
 {
-       uint32          hash = hash_any((const unsigned char *) name, strlen(name));
+       uint32          hash = hash_bytes((const unsigned char *) name, strlen(name));
 
        return fileset->tablespaces[hash % fileset->ntablespaces];
 }
index cd84ced5b487cd8af23d2ba1772dfc7167b36115..626b5513fe71a0aca7611caf8c64c60e259d0896 100644 (file)
@@ -2833,7 +2833,7 @@ hash_multirange(PG_FUNCTION_ARGS)
                        upper_hash = 0;
 
                /* Merge hashes of flags and bounds */
-               range_hash = hash_uint32((uint32) flags);
+               range_hash = hash_bytes_uint32((uint32) flags);
                range_hash ^= lower_hash;
                range_hash = pg_rotate_left32(range_hash, 1);
                range_hash ^= upper_hash;
index 66cc0acf4a71244b56c1263caad2a21c9403134a..691679388df71c6e6212286906c86929bf98fda8 100644 (file)
@@ -1444,7 +1444,7 @@ hash_range(PG_FUNCTION_ARGS)
                upper_hash = 0;
 
        /* Merge hashes of flags and bounds */
-       result = hash_uint32((uint32) flags);
+       result = hash_bytes_uint32((uint32) flags);
        result ^= lower_hash;
        result = pg_rotate_left32(result, 1);
        result ^= upper_hash;
index d1b25214376ed5b74d6fd01ec3fcfd65b049a0d1..e2cd3feaf81d3e5cdf330408c38638f8d129c261 100644 (file)
@@ -213,7 +213,7 @@ namehashfast(Datum datum)
 {
        char       *key = NameStr(*DatumGetName(datum));
 
-       return hash_any((unsigned char *) key, strlen(key));
+       return hash_bytes((unsigned char *) key, strlen(key));
 }
 
 static bool