Refactoring SearchSysCache + HeapTupleIsValid

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Refactoring SearchSysCache + HeapTupleIsValid
Date: 2008-12-11 11:37:36
Message-ID: 4940FB80.90303@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Our code contains about 200 copies of the following code:

tuple = SearchSysCache[Copy](FOOOID, ObjectIdGetDatum(fooid), 0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for foo %u", fooid);

This only counts elog() calls, not user-facing error messages
constructed with ereport().

Shouldn't we try to refactor this, maybe like this:

HeapTuple
SearchSysCache[Copy]Oid(int cacheId, Oid key)
{
HeapTuple tuple;

tuple = SearchSysCache[Copy](cacheId, ObjectIdGetDatum(key),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed in cache %d (relation %u) for
OID %u",
cacheId, cacheinfo[cacheId].reloid, key);

return tuple;
}

Maybe some other verb than "Search" could be used to make it clearer
that this function has its own error handler.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sreejesh O S 2008-12-11 11:43:38 Re: COCOMO & Indians
Previous Message Zdenek Kotala 2008-12-11 11:31:27 Re: visibility maps