]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove useless/superfluous Datum conversions
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 8 Aug 2025 20:05:05 +0000 (22:05 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 8 Aug 2025 20:06:57 +0000 (22:06 +0200)
Remove useless DatumGetFoo() and FooGetDatum() calls.  These are
places where no conversion from or to Datum was actually happening.

We think these extra calls covered here were harmless.  Some actual
bugs that were discovered during this process have been committed
separately (80c758a2e1d2242b26ce47).

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

src/backend/commands/alter.c
src/backend/executor/execExprInterp.c
src/backend/rewrite/rewriteDefine.c
src/backend/statistics/extended_stats.c
src/backend/tsearch/ts_parse.c
src/backend/utils/activity/pgstat.c
src/backend/utils/adt/json.c
src/backend/utils/adt/multirangetypes.c
src/backend/utils/adt/rangetypes.c
src/backend/utils/adt/varlena.c
src/backend/utils/cache/relcache.c

index c801c869c1cfc5f5edad4244b12c8060b06ea8d7..cb75e11fced622c11ffca97796894ac3f4904459 100644 (file)
@@ -220,7 +220,7 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
                Assert(!isnull);
                ownerId = DatumGetObjectId(datum);
 
-               if (!has_privs_of_role(GetUserId(), DatumGetObjectId(ownerId)))
+               if (!has_privs_of_role(GetUserId(), ownerId))
                        aclcheck_error(ACLCHECK_NOT_OWNER, get_object_type(classId, objectId),
                                                   old_name);
 
index 1a37737d4a23599a0170a63d9aaf8e0300833fd0..a5cfe246e638069093ac8ac2823deddc2e95a66e 100644 (file)
@@ -2815,7 +2815,7 @@ ExecJustHashVarImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)
        *isnull = false;
 
        if (!fcinfo->args[0].isnull)
-               return DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
+               return hashop->d.hashdatum.fn_addr(fcinfo);
        else
                return (Datum) 0;
 }
@@ -2849,7 +2849,7 @@ ExecJustHashVarVirtImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)
        *isnull = false;
 
        if (!fcinfo->args[0].isnull)
-               return DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
+               return hashop->d.hashdatum.fn_addr(fcinfo);
        else
                return (Datum) 0;
 }
@@ -2892,7 +2892,7 @@ ExecJustHashOuterVarStrict(ExprState *state, ExprContext *econtext,
        if (!fcinfo->args[0].isnull)
        {
                *isnull = false;
-               return DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
+               return hashop->d.hashdatum.fn_addr(fcinfo);
        }
        else
        {
index 8aa90b0d6fb75ff2b67d8817588fb43b6b09fd53..a96fbdc1ddd64a2596aa535b7a4287dc7c0a353e 100644 (file)
@@ -725,10 +725,9 @@ EnableDisableRule(Relation rel, const char *rulename,
        /*
         * Change ev_enabled if it is different from the desired new state.
         */
-       if (DatumGetChar(ruleform->ev_enabled) !=
-               fires_when)
+       if (ruleform->ev_enabled != fires_when)
        {
-               ruleform->ev_enabled = CharGetDatum(fires_when);
+               ruleform->ev_enabled = fires_when;
                CatalogTupleUpdate(pg_rewrite_desc, &ruletup->t_self, ruletup);
 
                changed = true;
index a8b63ec0884a987b7fc8862f9c7181313f28d115..3e031cf831a26f945ad4b35fee00fb42e16e84d1 100644 (file)
@@ -2618,7 +2618,7 @@ make_build_data(Relation rel, StatExtEntry *stat, int numrows, HeapTuple *rows,
                        }
                        else
                        {
-                               result->values[idx][i] = (Datum) datum;
+                               result->values[idx][i] = datum;
                                result->nulls[idx][i] = false;
                        }
 
index e5da6cf17ec19ed4396d34a10b8faf39f4a36aab..cba421892bf45aaef31548a6838e8472588365cd 100644 (file)
@@ -218,7 +218,7 @@ LexizeExec(LexizeData *ld, ParsedLex **correspondLexem)
                                         * position and go to multiword mode
                                         */
 
-                                       ld->curDictId = DatumGetObjectId(map->dictIds[i]);
+                                       ld->curDictId = map->dictIds[i];
                                        ld->posDict = i + 1;
                                        ld->curSub = curVal->next;
                                        if (res)
@@ -275,7 +275,7 @@ LexizeExec(LexizeData *ld, ParsedLex **correspondLexem)
                                 * dictionaries ?
                                 */
                                for (i = 0; i < map->len && !dictExists; i++)
-                                       if (ld->curDictId == DatumGetObjectId(map->dictIds[i]))
+                                       if (ld->curDictId == map->dictIds[i])
                                                dictExists = true;
 
                                if (!dictExists)
index 6bc91ce0daddac461bbee3c456591e04b652fcd0..ffb5b8cce34417b3abd26d41ef73e3ce12b8ecab 100644 (file)
@@ -821,7 +821,7 @@ pgstat_force_next_flush(void)
 static bool
 match_db_entries(PgStatShared_HashEntry *entry, Datum match_data)
 {
-       return entry->key.dboid == DatumGetObjectId(MyDatabaseId);
+       return entry->key.dboid == MyDatabaseId;
 }
 
 /*
index 51452755f5868bc8a9c0f04c8555779672de9a0f..e9d370cb3da8e976d10592173bd0b36defd8cfea 100644 (file)
@@ -904,7 +904,7 @@ json_unique_hash(const void *key, Size keysize)
 
        hash ^= hash_bytes((const unsigned char *) entry->key, entry->key_len);
 
-       return DatumGetUInt32(hash);
+       return hash;
 }
 
 static int
index 46f2ec0c29fbd682e219e1d19b12c2448850ae59..e64feeaeccb7c83528678169be3a3e4da0835fc0 100644 (file)
@@ -2082,15 +2082,14 @@ range_overleft_multirange_internal(TypeCacheEntry *rangetyp,
        bool            empty;
 
        if (RangeIsEmpty(r) || MultirangeIsEmpty(mr))
-               PG_RETURN_BOOL(false);
-
+               return false;
 
        range_deserialize(rangetyp, r, &lower1, &upper1, &empty);
        Assert(!empty);
        multirange_get_bounds(rangetyp, mr, mr->rangeCount - 1,
                                                  &lower2, &upper2);
 
-       PG_RETURN_BOOL(range_cmp_bounds(rangetyp, &upper1, &upper2) <= 0);
+       return (range_cmp_bounds(rangetyp, &upper1, &upper2) <= 0);
 }
 
 Datum
@@ -2167,7 +2166,7 @@ range_overright_multirange_internal(TypeCacheEntry *rangetyp,
        bool            empty;
 
        if (RangeIsEmpty(r) || MultirangeIsEmpty(mr))
-               PG_RETURN_BOOL(false);
+               return false;
 
        range_deserialize(rangetyp, r, &lower1, &upper1, &empty);
        Assert(!empty);
index c83b239b3bb2893486359642dd87a5858bfa50a7..254b8f65c21a671bc54a1aabb677ae86ca408b28 100644 (file)
@@ -1075,8 +1075,8 @@ range_union_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2,
                return r1;
 
        if (strict &&
-               !DatumGetBool(range_overlaps_internal(typcache, r1, r2)) &&
-               !DatumGetBool(range_adjacent_internal(typcache, r1, r2)))
+               !range_overlaps_internal(typcache, r1, r2) &&
+               !range_adjacent_internal(typcache, r1, r2))
                ereport(ERROR,
                                (errcode(ERRCODE_DATA_EXCEPTION),
                                 errmsg("result of range union would not be contiguous")));
index ffae8c23abfafe8fca1d407a2a5f018a7d2cde5e..11b442a5941c9899673bb6192fc4f445017ce556 100644 (file)
@@ -408,13 +408,12 @@ text_length(Datum str)
 {
        /* fastpath when max encoding length is one */
        if (pg_database_encoding_max_length() == 1)
-               PG_RETURN_INT32(toast_raw_datum_size(str) - VARHDRSZ);
+               return (toast_raw_datum_size(str) - VARHDRSZ);
        else
        {
                text       *t = DatumGetTextPP(str);
 
-               PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA_ANY(t),
-                                                                                        VARSIZE_ANY_EXHDR(t)));
+               return (pg_mbstrlen_with_len(VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)));
        }
 }
 
index 559ba9cdb2cdedf4aa37c7a97645ecbdaa0c269f..153d2fde6fd3dec28f58777fcf653a304ed84bb6 100644 (file)
@@ -3184,7 +3184,7 @@ AssertPendingSyncs_RelationCache(void)
                if ((LockTagType) locallock->tag.lock.locktag_type !=
                        LOCKTAG_RELATION)
                        continue;
-               relid = ObjectIdGetDatum(locallock->tag.lock.locktag_field2);
+               relid = locallock->tag.lock.locktag_field2;
                r = RelationIdGetRelation(relid);
                if (!RelationIsValid(r))
                        continue;