1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-01 12:18:01 +03:00

Fix problems with cached tuple descriptors disappearing while still in use

by creating a reference-count mechanism, similar to what we did a long time
ago for catcache entries.  The back branches have an ugly solution involving
lots of extra copies, but this way is more efficient.  Reference counting is
only applied to tupdescs that are actually in caches --- there seems no need
to use it for tupdescs that are generated in the executor, since they'll go
away during plan shutdown by virtue of being in the per-query memory context.
Neil Conway and Tom Lane
This commit is contained in:
Tom Lane
2006-06-16 18:42:24 +00:00
parent b49ce32da1
commit 06e10abc0b
36 changed files with 581 additions and 246 deletions

View File

@@ -7,7 +7,7 @@
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/fmgr/funcapi.c,v 1.29 2006/03/05 15:58:46 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/fmgr/funcapi.c,v 1.30 2006/06/16 18:42:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -185,8 +185,7 @@ shutdown_MultiFuncCall(Datum arg)
* receives the actual datatype OID (this is mainly useful for scalar
* result types). If resultTupleDesc isn't NULL, *resultTupleDesc
* receives a pointer to a TupleDesc when the result is of a composite
* type, or NULL when it's a scalar result. NB: the tupledesc should
* be copied if it is to be accessed over a long period.
* type, or NULL when it's a scalar result.
*
* One hard case that this handles is resolution of actual rowtypes for
* functions returning RECORD (from either the function's OUT parameter
@@ -246,7 +245,7 @@ get_expr_result_type(Node *expr,
*resultTupleDesc = NULL;
result = get_type_func_class(typid);
if (result == TYPEFUNC_COMPOSITE && resultTupleDesc)
*resultTupleDesc = lookup_rowtype_tupdesc(typid, -1);
*resultTupleDesc = lookup_rowtype_tupdesc_copy(typid, -1);
}
return result;
@@ -363,7 +362,7 @@ internal_get_result_type(Oid funcid,
{
case TYPEFUNC_COMPOSITE:
if (resultTupleDesc)
*resultTupleDesc = lookup_rowtype_tupdesc(rettype, -1);
*resultTupleDesc = lookup_rowtype_tupdesc_copy(rettype, -1);
/* Named composite types can't have any polymorphic columns */
break;
case TYPEFUNC_SCALAR:
@@ -1053,7 +1052,7 @@ TypeGetTupleDesc(Oid typeoid, List *colaliases)
if (functypclass == TYPEFUNC_COMPOSITE)
{
/* Composite data type, e.g. a table's row type */
tupdesc = CreateTupleDescCopy(lookup_rowtype_tupdesc(typeoid, -1));
tupdesc = lookup_rowtype_tupdesc_copy(typeoid, -1);
if (colaliases != NIL)
{