Re: lookup_rowtype_tupdesc considered harmful

From: Neil Conway <neilc(at)samurai(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: lookup_rowtype_tupdesc considered harmful
Date: 2006-01-09 22:38:35
Message-ID: 1136846315.9116.20.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 2006-01-09 at 14:51 -0500, Tom Lane wrote:
> Nah, I don't think this works. The problem is that after an inval,
> you may have to provide an updated TupleDesc to new callers while
> old callers still have open reference counts to the old TupleDesc.

Good point.

> However, you might be able to adopt the same trick used in catcache.c:
> the callers think they have pointers to HeapTuples and are unaware that
> that is just a field of a larger struct. Add a reference count and a
> "dead" flag, and a "magic" value for safety checking, and you've got it.

Hmm, okay. There's the additional complication that we need to handle
record types (see RecordCacheArray in typcache.c). Since I don't think
we need reference counting for those, I'm envisioning something like:

TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
void release_rowtype_tupdesc(TupleDesc tdesc); /* better name? */

TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
void release_type_cache(TypeCacheEntry *tentry);

where lookup_rowtype_tupdesc() returns a pointer to this struct:

typedef struct
{
struct tupleDesc tdesc; /* must be first field */

TypeCacheEntry *tentry; /* pointer to owning TypeCacheEntry,
or NULL if this is a record type */
} MagicTupleDesc;

and where TypeCacheEntry has been modified to contain a reference count
and an "is dead?" flag. Is there actually a need for the (ugly) "magic
value" hackery used by catcache?

-Neil

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-01-09 22:49:12 Re: lookup_rowtype_tupdesc considered harmful
Previous Message Tom Lane 2006-01-09 21:23:35 Re: plperl vs LC_COLLATE (was Re: Possible savepoint bug)