Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bbc227e

Browse files
committed
Always use ReleaseTupleDesc after lookup_rowtype_tupdesc et al.
The API spec for lookup_rowtype_tupdesc previously said you could use either ReleaseTupleDesc or DecrTupleDescRefCount. However, the latter choice means the caller must be certain that the returned tupdesc is refcounted. I don't recall right now whether that was always true when this spec was written, but it's certainly not always true since we introduced shared record typcaches for parallel workers. That means that callers using DecrTupleDescRefCount are dependent on typcache behavior details that they probably shouldn't be. Hence, change the API spec to say that you must call ReleaseTupleDesc, and fix the half-dozen callers that weren't. AFAICT this is just future-proofing, there's no live bug here. So no back-patch. Per gripe from Chapman Flack. Discussion: https://postgr.es/m/61B901A4.1050808@anastigmatix.net
1 parent 2a71206 commit bbc227e

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/backend/commands/tablecmds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15401,7 +15401,7 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
1540115401
errmsg("table \"%s\" has different type for column \"%s\"",
1540215402
RelationGetRelationName(rel), type_attname)));
1540315403
}
15404-
DecrTupleDescRefCount(typeTupleDesc);
15404+
ReleaseTupleDesc(typeTupleDesc);
1540515405

1540615406
/* Any remaining columns at the end of the table had better be dropped. */
1540715407
for (; table_attno <= tableTupleDesc->natts; table_attno++)

src/backend/executor/execExpr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ ExecInitExprRec(Expr *node, ExprState *state,
14651465
/* find out the number of columns in the composite type */
14661466
tupDesc = lookup_rowtype_tupdesc(fstore->resulttype, -1);
14671467
ncolumns = tupDesc->natts;
1468-
DecrTupleDescRefCount(tupDesc);
1468+
ReleaseTupleDesc(tupDesc);
14691469

14701470
/* create workspace for column values */
14711471
values = (Datum *) palloc(sizeof(Datum) * ncolumns);

src/backend/parser/parse_utilcmd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
14841484
n->location = -1;
14851485
cxt->columns = lappend(cxt->columns, n);
14861486
}
1487-
DecrTupleDescRefCount(tupdesc);
1487+
ReleaseTupleDesc(tupdesc);
14881488

14891489
ReleaseSysCache(tuple);
14901490
}

src/backend/utils/adt/expandedrecord.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ make_expanded_record_from_typeid(Oid type_id, int32 typmod,
171171

172172
/* If we called lookup_rowtype_tupdesc, release the pin it took */
173173
if (type_id == RECORDOID)
174-
DecrTupleDescRefCount(tupdesc);
174+
ReleaseTupleDesc(tupdesc);
175175
}
176176
else
177177
{
@@ -854,7 +854,7 @@ expanded_record_fetch_tupdesc(ExpandedRecordHeader *erh)
854854
tupdesc->tdrefcount++;
855855

856856
/* Release the pin lookup_rowtype_tupdesc acquired */
857-
DecrTupleDescRefCount(tupdesc);
857+
ReleaseTupleDesc(tupdesc);
858858
}
859859
else
860860
{

src/backend/utils/cache/typcache.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1820,8 +1820,11 @@ lookup_rowtype_tupdesc_internal(Oid type_id, int32 typmod, bool noError)
18201820
* for example from record_in().)
18211821
*
18221822
* Note: on success, we increment the refcount of the returned TupleDesc,
1823-
* and log the reference in CurrentResourceOwner. Caller should call
1824-
* ReleaseTupleDesc or DecrTupleDescRefCount when done using the tupdesc.
1823+
* and log the reference in CurrentResourceOwner. Caller must call
1824+
* ReleaseTupleDesc when done using the tupdesc. (There are some
1825+
* cases in which the returned tupdesc is not refcounted, in which
1826+
* case PinTupleDesc/ReleaseTupleDesc are no-ops; but in these cases
1827+
* the tupdesc is guaranteed to live till process exit.)
18251828
*/
18261829
TupleDesc
18271830
lookup_rowtype_tupdesc(Oid type_id, int32 typmod)

0 commit comments

Comments
 (0)