Re: Life cycles of tuple descriptors
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chapman Flack <chap@anastigmatix.net>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>,
Thomas Munro <thomas.munro@gmail.com>
Date: 2021-12-15T22:50:41Z
Lists: pgsql-hackers
Attachments
- tighten-API-spec-for-lookup_rowtype_tupdesc.patch (text/x-diff) patch
I wrote: > Chapman Flack <chap@anastigmatix.net> writes: >> Oh, hmm, maybe one thing in that API comment ought to be changed. It says >> I must call ReleaseTupleDesc *or* DecrTupleDescRefCount. Maybe that dates >> from before the shared registry? ReleaseTupleDesc is safe, but anybody who >> uses DecrTupleDescRefCount on a lookup_rowtype_tupdesc result could be >> in for an assertion failure if a non-refcounted tupdesc is returned. > Yeah, I was just wondering the same. I think DecrTupleDescRefCount > is safe if you know you are looking up a named composite type, but > maybe that's still too much familiarity with typcache innards. Here's a draft patch for this. There are several places that are directly using DecrTupleDescRefCount after lookup_rowtype_tupdesc or equivalent, which'd now be forbidden. I think they are all safe given the assumption that the typcache's tupdescs for named composites are refcounted. (The calls in expandedrecord.c could be working with RECORD, but those code paths just checked that the tupdesc is refcounted.) So there's no actual bug here, and no reason to back-patch, but this seems like a good idea to decouple callers a bit more from typcache's internal logic. None of these call sites are so performance-critical that one extra test will hurt. regards, tom lane
Commits
-
Always use ReleaseTupleDesc after lookup_rowtype_tupdesc et al.
- bbc227e951ec 15.0 landed