if (tupleDesc == NULL)
return value; /* not a composite type */
+ tupleDesc = CreateTupleDescCopy(tupleDesc);
att = tupleDesc->attrs;
numAttrs = tupleDesc->natts;
* If nothing to untoast, just return the original tuple.
*/
if (!need_change)
+ {
+ FreeTupleDesc(tupleDesc);
return value;
+ }
/*
* Calculate the new size of the tuple. Header size should not change,
for (i = 0; i < numAttrs; i++)
if (toast_free[i])
pfree(DatumGetPointer(toast_values[i]));
+ FreeTupleDesc(tupleDesc);
return PointerGetDatum(new_data);
}
format_type_be(RECORDOID),
format_type_be(targetTypeId))));
- tupdesc = lookup_rowtype_tupdesc(targetTypeId, -1);
+ tupdesc = CreateTupleDescCopy(lookup_rowtype_tupdesc(targetTypeId, -1));
newargs = NIL;
ucolno = 1;
arg = list_head(args);
format_type_be(targetTypeId)),
errdetail("Input has too many columns.")));
+ FreeTupleDesc(tupdesc);
+
rowexpr = makeNode(RowExpr);
rowexpr->args = newargs;
rowexpr->row_typeid = targetTypeId;
((Var *) expr)->vartype == RECORDOID)
tupleDesc = expandRecordVariable(pstate, (Var *) expr, 0);
else if (get_expr_result_type(expr, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
- tupleDesc = lookup_rowtype_tupdesc(exprType(expr), exprTypmod(expr));
+ tupleDesc = CreateTupleDescCopy(lookup_rowtype_tupdesc(exprType(expr),
+ exprTypmod(expr)));
Assert(tupleDesc);
/* Generate a list of references to the individual fields */
* appropriate error message while failing.
*/
if (get_expr_result_type(expr, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
- tupleDesc = lookup_rowtype_tupdesc(exprType(expr), exprTypmod(expr));
+ tupleDesc = CreateTupleDescCopy(lookup_rowtype_tupdesc(exprType(expr),
+ exprTypmod(expr)));
return tupleDesc;
}
errmsg("input of anonymous composite types is not implemented")));
tupTypmod = -1; /* for all non-anonymous types */
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
ncolumns = tupdesc->natts;
/*
pfree(buf.data);
pfree(values);
pfree(nulls);
+ FreeTupleDesc(tupdesc);
PG_RETURN_HEAPTUPLEHEADER(result);
}
tupType = HeapTupleHeaderGetTypeId(rec);
tupTypmod = HeapTupleHeaderGetTypMod(rec);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
ncolumns = tupdesc->natts;
/* Build a temporary HeapTuple control structure */
pfree(values);
pfree(nulls);
+ FreeTupleDesc(tupdesc);
PG_RETURN_CSTRING(buf.data);
}
errmsg("input of anonymous composite types is not implemented")));
tupTypmod = -1; /* for all non-anonymous types */
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
ncolumns = tupdesc->natts;
/*
heap_freetuple(tuple);
pfree(values);
pfree(nulls);
+ FreeTupleDesc(tupdesc);
PG_RETURN_HEAPTUPLEHEADER(result);
}
tupType = HeapTupleHeaderGetTypeId(rec);
tupTypmod = HeapTupleHeaderGetTypMod(rec);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
ncolumns = tupdesc->natts;
/* Build a temporary HeapTuple control structure */
pfree(values);
pfree(nulls);
+ FreeTupleDesc(tupdesc);
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
/* Got the tupdesc, so we can extract the field name */
Assert(fieldno >= 1 && fieldno <= tupleDesc->natts);
- return NameStr(tupleDesc->attrs[fieldno - 1]->attname);
+ return pstrdup(NameStr(tupleDesc->attrs[fieldno - 1]->attname));
}
if (rowexpr->row_typeid != RECORDOID)
{
tupdesc = lookup_rowtype_tupdesc(rowexpr->row_typeid, -1);
+ tupdesc = CreateTupleDescCopy(tupdesc);
Assert(list_length(rowexpr->args) <= tupdesc->natts);
}
*
* Note: returned TupleDesc points to cached copy; caller must copy it
* if intending to scribble on it or keep a reference for a long time.
+ * ("A long time" basically means "across any possible cache flush",
+ * which typically could occur at any relation open or catalog lookup.)
*/
TupleDesc
lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
*resultTupleDesc = NULL;
result = get_type_func_class(typid);
if (result == TYPEFUNC_COMPOSITE && resultTupleDesc)
- *resultTupleDesc = lookup_rowtype_tupdesc(typid, -1);
+ *resultTupleDesc = CreateTupleDescCopy(lookup_rowtype_tupdesc(typid, -1));
}
return result;
{
case TYPEFUNC_COMPOSITE:
if (resultTupleDesc)
- *resultTupleDesc = lookup_rowtype_tupdesc(rettype, -1);
+ *resultTupleDesc = CreateTupleDescCopy(lookup_rowtype_tupdesc(rettype, -1));
/* Named composite types can't have any polymorphic columns */
break;
case TYPEFUNC_SCALAR:
tupType = HeapTupleHeaderGetTypeId(td);
tupTypmod = HeapTupleHeaderGetTypMod(td);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
/* Build a temporary HeapTuple control structure */
tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
tmptup.t_data = td;
hashref = plperl_hash_from_tuple(&tmptup, tupdesc);
XPUSHs(sv_2mortal(hashref));
+ FreeTupleDesc(tupdesc);
}
else
{
tupType = HeapTupleHeaderGetTypeId(td);
tupTypmod = HeapTupleHeaderGetTypMod(td);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
/* Build a temporary HeapTuple control structure */
tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
ItemPointerSetInvalid(&(tmptup.t_self));
tmptup.t_tableOid = InvalidOid;
tmptup.t_data = td;
exec_move_row(&estate, NULL, row, &tmptup, tupdesc);
+ FreeTupleDesc(tupdesc);
}
else
{
tupType = HeapTupleHeaderGetTypeId(td);
tupTypmod = HeapTupleHeaderGetTypMod(td);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
/* Build a temporary HeapTuple control structure */
tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
ItemPointerSetInvalid(&(tmptup.t_self));
tmptup.t_tableOid = InvalidOid;
tmptup.t_data = td;
exec_move_row(estate, NULL, row, &tmptup, tupdesc);
+ FreeTupleDesc(tupdesc);
}
break;
}
tupType = HeapTupleHeaderGetTypeId(td);
tupTypmod = HeapTupleHeaderGetTypMod(td);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
/* Build a temporary HeapTuple control structure */
tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
ItemPointerSetInvalid(&(tmptup.t_self));
tmptup.t_tableOid = InvalidOid;
tmptup.t_data = td;
exec_move_row(estate, rec, NULL, &tmptup, tupdesc);
+ FreeTupleDesc(tupdesc);
}
break;
}
tupType = HeapTupleHeaderGetTypeId(td);
tupTypmod = HeapTupleHeaderGetTypMod(td);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
/* Set up I/O funcs if not done yet */
if (proc->args[i].is_rowtype != 1)
tmptup.t_data = td;
arg = PLyDict_FromTuple(&(proc->args[i]), &tmptup, tupdesc);
+ FreeTupleDesc(tupdesc);
}
}
else
tupType = HeapTupleHeaderGetTypeId(td);
tupTypmod = HeapTupleHeaderGetTypMod(td);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = CreateTupleDescCopy(tupdesc);
/* Build a temporary HeapTuple control structure */
tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
tmptup.t_data = td;
pltcl_build_tuple_argument(&tmptup, tupdesc, &list_tmp);
Tcl_DStringAppendElement(&tcl_cmd,
Tcl_DStringValue(&list_tmp));
+ FreeTupleDesc(tupdesc);
}
}
else