Re: lookup_rowtype_tupdesc considered harmful

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: lookup_rowtype_tupdesc considered harmful
Date: 2006-01-10 14:47:50
Message-ID: 29393.1136904470@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I had a further thought about this. What we're really talking about
here is a reference-counted TupleDesc structure: it's got no necessary
connection to TypeCacheEntry at all. And in fact there are other places
in the system that could use such a facility. For instance,
TupleTableSlot has a "shouldFreeDesc" flag that sort of allows partial,
one-way sharing of descs between slots, but it would work a lot better
if the descriptors contained reference counts instead. And it might be
worth insisting that users of a relation tupledesc from the relcache
increment its refcount while they use it --- that would get rid of some
rather shaky assumptions about when it's OK to free the tupledesc during
relcache updates.

I'm thinking it might be worth the cost to just add a refcount field to
the standard tupleDesc struct. (We don't need an isdead flag: more
elegantly, just include the TypeCacheEntry's own reference to the
tupdesc in the refcount.) Add macros IncrTupleDescRefCount and
DecrTupleDescRefCount, the latter freeing the struct if the count
goes to zero, and voila.

I'm not quite sure whether the tupledesc creation routines should
initialize the count to zero or to one, but otherwise it all seems
pretty clear. Thoughts?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-01-10 15:01:36 Re: current_setting returns 'unset'
Previous Message Peter Eisentraut 2006-01-10 10:41:18 current_setting returns 'unset'