From ae93e5fd6e8a7e2321e87d23165d9d7660cde598 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 5 Jun 2004 01:55:05 +0000 Subject: Make the world very nearly safe for composite-type columns in tables. 1. Solve the problem of not having TOAST references hiding inside composite values by establishing the rule that toasting only goes one level deep: a tuple can contain toasted fields, but a composite-type datum that is to be inserted into a tuple cannot. Enforcing this in heap_formtuple is relatively cheap and it avoids a large increase in the cost of running the tuptoaster during final storage of a row. 2. Fix some interesting problems in expansion of inherited queries that reference whole-row variables. We never really did this correctly before, but it's now relatively painless to solve by expanding the parent's whole-row Var into a RowExpr() selecting the proper columns from the child. If you dike out the preventive check in CheckAttributeType(), composite-type columns now seem to actually work. However, we surely cannot ship them like this --- without I/O for composite types, you can't get pg_dump to dump tables containing them. So a little more work still to do. --- src/backend/utils/cache/typcache.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/backend/utils/cache/typcache.c') diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index b3ef61c2d72..8ad60423c78 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -36,7 +36,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.6 2004/05/26 04:41:40 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.7 2004/06/05 01:55:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -384,6 +384,19 @@ lookup_default_opclass(Oid type_id, Oid am_id) */ TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod) +{ + return lookup_rowtype_tupdesc_noerror(type_id, typmod, false); +} + +/* + * lookup_rowtype_tupdesc_noerror + * + * As above, but if the type is not a known composite type and noError + * is true, returns NULL instead of ereport'ing. (Note that if a bogus + * type_id is passed, you'll get an ereport anyway.) + */ +TupleDesc +lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError) { if (type_id != RECORDOID) { @@ -393,8 +406,7 @@ lookup_rowtype_tupdesc(Oid type_id, int32 typmod) TypeCacheEntry *typentry; typentry = lookup_type_cache(type_id, TYPECACHE_TUPDESC); - /* this should not happen unless caller messed up: */ - if (typentry->tupDesc == NULL) + if (typentry->tupDesc == NULL && !noError) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("type %u is not composite", @@ -408,9 +420,11 @@ lookup_rowtype_tupdesc(Oid type_id, int32 typmod) */ if (typmod < 0 || typmod >= NextRecordTypmod) { - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("record type has not been registered"))); + if (!noError) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("record type has not been registered"))); + return NULL; } return RecordCacheArray[typmod]; } -- cgit v1.2.3