Remove useless/superfluous Datum conversions

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 (80c758a2e1, 2242b26ce4).

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/8246d7ff-f4b7-4363-913e-827dadfeb145%40eisentraut.org
pull/239/head
Peter Eisentraut 1 month ago
parent 138750dde4
commit dcfc0f8912
  1. 2
      src/backend/commands/alter.c
  2. 6
      src/backend/executor/execExprInterp.c
  3. 5
      src/backend/rewrite/rewriteDefine.c
  4. 2
      src/backend/statistics/extended_stats.c
  5. 4
      src/backend/tsearch/ts_parse.c
  6. 2
      src/backend/utils/activity/pgstat.c
  7. 2
      src/backend/utils/adt/json.c
  8. 7
      src/backend/utils/adt/multirangetypes.c
  9. 4
      src/backend/utils/adt/rangetypes.c
  10. 5
      src/backend/utils/adt/varlena.c
  11. 2
      src/backend/utils/cache/relcache.c

@ -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);

@ -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
{

@ -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;

@ -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;
}

@ -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)

@ -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;
}
/*

@ -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

@ -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);

@ -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")));

@ -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)));
}
}

@ -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;

Loading…
Cancel
Save