Skip to content

Commit dcfc0f8

Browse files
committed
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 (80c758a, 2242b26). Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/8246d7ff-f4b7-4363-913e-827dadfeb145%40eisentraut.org
1 parent 138750d commit dcfc0f8

File tree

11 files changed

+19
-22
lines changed

11 files changed

+19
-22
lines changed

src/backend/commands/alter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
220220
Assert(!isnull);
221221
ownerId = DatumGetObjectId(datum);
222222

223-
if (!has_privs_of_role(GetUserId(), DatumGetObjectId(ownerId)))
223+
if (!has_privs_of_role(GetUserId(), ownerId))
224224
aclcheck_error(ACLCHECK_NOT_OWNER, get_object_type(classId, objectId),
225225
old_name);
226226

src/backend/executor/execExprInterp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ ExecJustHashVarImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)
28152815
*isnull = false;
28162816

28172817
if (!fcinfo->args[0].isnull)
2818-
return DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
2818+
return hashop->d.hashdatum.fn_addr(fcinfo);
28192819
else
28202820
return (Datum) 0;
28212821
}
@@ -2849,7 +2849,7 @@ ExecJustHashVarVirtImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)
28492849
*isnull = false;
28502850

28512851
if (!fcinfo->args[0].isnull)
2852-
return DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
2852+
return hashop->d.hashdatum.fn_addr(fcinfo);
28532853
else
28542854
return (Datum) 0;
28552855
}
@@ -2892,7 +2892,7 @@ ExecJustHashOuterVarStrict(ExprState *state, ExprContext *econtext,
28922892
if (!fcinfo->args[0].isnull)
28932893
{
28942894
*isnull = false;
2895-
return DatumGetUInt32(hashop->d.hashdatum.fn_addr(fcinfo));
2895+
return hashop->d.hashdatum.fn_addr(fcinfo);
28962896
}
28972897
else
28982898
{

src/backend/rewrite/rewriteDefine.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,9 @@ EnableDisableRule(Relation rel, const char *rulename,
725725
/*
726726
* Change ev_enabled if it is different from the desired new state.
727727
*/
728-
if (DatumGetChar(ruleform->ev_enabled) !=
729-
fires_when)
728+
if (ruleform->ev_enabled != fires_when)
730729
{
731-
ruleform->ev_enabled = CharGetDatum(fires_when);
730+
ruleform->ev_enabled = fires_when;
732731
CatalogTupleUpdate(pg_rewrite_desc, &ruletup->t_self, ruletup);
733732

734733
changed = true;

src/backend/statistics/extended_stats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ make_build_data(Relation rel, StatExtEntry *stat, int numrows, HeapTuple *rows,
26182618
}
26192619
else
26202620
{
2621-
result->values[idx][i] = (Datum) datum;
2621+
result->values[idx][i] = datum;
26222622
result->nulls[idx][i] = false;
26232623
}
26242624

src/backend/tsearch/ts_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ LexizeExec(LexizeData *ld, ParsedLex **correspondLexem)
218218
* position and go to multiword mode
219219
*/
220220

221-
ld->curDictId = DatumGetObjectId(map->dictIds[i]);
221+
ld->curDictId = map->dictIds[i];
222222
ld->posDict = i + 1;
223223
ld->curSub = curVal->next;
224224
if (res)
@@ -275,7 +275,7 @@ LexizeExec(LexizeData *ld, ParsedLex **correspondLexem)
275275
* dictionaries ?
276276
*/
277277
for (i = 0; i < map->len && !dictExists; i++)
278-
if (ld->curDictId == DatumGetObjectId(map->dictIds[i]))
278+
if (ld->curDictId == map->dictIds[i])
279279
dictExists = true;
280280

281281
if (!dictExists)

src/backend/utils/activity/pgstat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ pgstat_force_next_flush(void)
821821
static bool
822822
match_db_entries(PgStatShared_HashEntry *entry, Datum match_data)
823823
{
824-
return entry->key.dboid == DatumGetObjectId(MyDatabaseId);
824+
return entry->key.dboid == MyDatabaseId;
825825
}
826826

827827
/*

src/backend/utils/adt/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ json_unique_hash(const void *key, Size keysize)
904904

905905
hash ^= hash_bytes((const unsigned char *) entry->key, entry->key_len);
906906

907-
return DatumGetUInt32(hash);
907+
return hash;
908908
}
909909

910910
static int

src/backend/utils/adt/multirangetypes.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,15 +2082,14 @@ range_overleft_multirange_internal(TypeCacheEntry *rangetyp,
20822082
bool empty;
20832083

20842084
if (RangeIsEmpty(r) || MultirangeIsEmpty(mr))
2085-
PG_RETURN_BOOL(false);
2086-
2085+
return false;
20872086

20882087
range_deserialize(rangetyp, r, &lower1, &upper1, &empty);
20892088
Assert(!empty);
20902089
multirange_get_bounds(rangetyp, mr, mr->rangeCount - 1,
20912090
&lower2, &upper2);
20922091

2093-
PG_RETURN_BOOL(range_cmp_bounds(rangetyp, &upper1, &upper2) <= 0);
2092+
return (range_cmp_bounds(rangetyp, &upper1, &upper2) <= 0);
20942093
}
20952094

20962095
Datum
@@ -2167,7 +2166,7 @@ range_overright_multirange_internal(TypeCacheEntry *rangetyp,
21672166
bool empty;
21682167

21692168
if (RangeIsEmpty(r) || MultirangeIsEmpty(mr))
2170-
PG_RETURN_BOOL(false);
2169+
return false;
21712170

21722171
range_deserialize(rangetyp, r, &lower1, &upper1, &empty);
21732172
Assert(!empty);

src/backend/utils/adt/rangetypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,8 @@ range_union_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2,
10751075
return r1;
10761076

10771077
if (strict &&
1078-
!DatumGetBool(range_overlaps_internal(typcache, r1, r2)) &&
1079-
!DatumGetBool(range_adjacent_internal(typcache, r1, r2)))
1078+
!range_overlaps_internal(typcache, r1, r2) &&
1079+
!range_adjacent_internal(typcache, r1, r2))
10801080
ereport(ERROR,
10811081
(errcode(ERRCODE_DATA_EXCEPTION),
10821082
errmsg("result of range union would not be contiguous")));

src/backend/utils/adt/varlena.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,12 @@ text_length(Datum str)
408408
{
409409
/* fastpath when max encoding length is one */
410410
if (pg_database_encoding_max_length() == 1)
411-
PG_RETURN_INT32(toast_raw_datum_size(str) - VARHDRSZ);
411+
return (toast_raw_datum_size(str) - VARHDRSZ);
412412
else
413413
{
414414
text *t = DatumGetTextPP(str);
415415

416-
PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA_ANY(t),
417-
VARSIZE_ANY_EXHDR(t)));
416+
return (pg_mbstrlen_with_len(VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)));
418417
}
419418
}
420419

0 commit comments

Comments
 (0)