88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.193 2002/03/29 19:05:59 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.194 2002/03/31 06:26:29 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
6161#include "utils/lsyscache.h"
6262#include "utils/relcache.h"
6363#include "utils/syscache.h"
64- #include "utils/temprel.h"
6564
6665
6766static void AddNewRelationTuple (Relation pg_class_desc ,
6867Relation new_rel_desc ,
6968Oid new_rel_oid ,Oid new_type_oid ,
70- char relkind ,bool relhasoids ,
71- char * temp_relname );
69+ char relkind ,bool relhasoids );
7270static void DeleteAttributeTuples (Relation rel );
7371static void DeleteRelationTuple (Relation rel );
7472static void DeleteTypeTuple (Relation rel );
@@ -205,34 +203,29 @@ SystemAttributeByName(const char *attname, bool relhasoids)
205203 *
206204 *Remove the system relation specific code to elsewhere eventually.
207205 *
208- * NOTE: if istemp is TRUE then heap_create will overwrite relname with
209- * the unique "real" name chosen for the temp relation.
210- *
211206 * If storage_create is TRUE then heap_storage_create is called here,
212207 * else caller must call heap_storage_create later.
213208 * ----------------------------------------------------------------
214209 */
215210Relation
216- heap_create (char * relname ,
211+ heap_create (const char * relname ,
217212Oid relnamespace ,
218213TupleDesc tupDesc ,
219- bool istemp ,
220214bool storage_create ,
221215bool allow_system_table_mods )
222216{
223- static unsignedint uniqueId = 0 ;
224-
225217Oid relid ;
226218Oid dbid = MyDatabaseId ;
227- RelFileNode rnode ;
228219bool nailme = false;
220+ RelFileNode rnode ;
229221Relation rel ;
230222
231223/*
232224 * sanity checks
233225 */
234- if (relname && !allow_system_table_mods &&
235- IsSystemRelationName (relname )&& IsNormalProcessingMode ())
226+ if (!allow_system_table_mods &&
227+ IsSystemRelationName (relname )&&
228+ IsNormalProcessingMode ())
236229elog (ERROR ,"invalid relation name \"%s\"; "
237230"the 'pg_' name prefix is reserved for system catalogs" ,
238231relname );
@@ -291,16 +284,6 @@ heap_create(char *relname,
291284else
292285relid = newoid ();
293286
294- if (istemp )
295- {
296- /*
297- * replace relname of caller with a unique name for a temp
298- * relation
299- */
300- snprintf (relname ,NAMEDATALEN ,"%s_%d_%u" ,
301- PG_TEMP_REL_PREFIX , (int )MyProcPid ,uniqueId ++ );
302- }
303-
304287/*
305288 * For now, the physical identifier of the relation is the same as the
306289 * logical identifier.
@@ -528,8 +511,7 @@ AddNewRelationTuple(Relation pg_class_desc,
528511Oid new_rel_oid ,
529512Oid new_type_oid ,
530513char relkind ,
531- bool relhasoids ,
532- char * temp_relname )
514+ bool relhasoids )
533515{
534516Form_pg_class new_rel_reltup ;
535517HeapTuple tup ;
@@ -599,9 +581,6 @@ AddNewRelationTuple(Relation pg_class_desc,
599581 */
600582heap_insert (pg_class_desc ,tup );
601583
602- if (temp_relname )
603- create_temp_relation (temp_relname ,tup );
604-
605584if (!IsIgnoringSystemIndexes ())
606585{
607586/*
@@ -669,19 +648,17 @@ AddNewRelationType(const char *typeName,
669648 * --------------------------------
670649 */
671650Oid
672- heap_create_with_catalog (char * relname ,
651+ heap_create_with_catalog (const char * relname ,
673652Oid relnamespace ,
674653TupleDesc tupdesc ,
675654char relkind ,
676655bool relhasoids ,
677- bool istemp ,
678656bool allow_system_table_mods )
679657{
680658Relation pg_class_desc ;
681659Relation new_rel_desc ;
682660Oid new_rel_oid ;
683661Oid new_type_oid ;
684- char * temp_relname = NULL ;
685662
686663/*
687664 * sanity checks
@@ -693,32 +670,17 @@ heap_create_with_catalog(char *relname,
693670
694671CheckAttributeNames (tupdesc ,relhasoids );
695672
696- /* temp tables can mask non-temp tables */
697- if ((!istemp && get_relname_relid (relname ,relnamespace ))||
698- (istemp && is_temp_rel_name (relname )))
673+ if (get_relname_relid (relname ,relnamespace ))
699674elog (ERROR ,"Relation '%s' already exists" ,relname );
700675
701- if (istemp )
702- {
703- /* save user relation name because heap_create changes it */
704- temp_relname = pstrdup (relname );/* save original value */
705- relname = palloc (NAMEDATALEN );
706- strcpy (relname ,temp_relname );/* heap_create will change this */
707- }
708-
709676/*
710677 * Tell heap_create not to create a physical file; we'll do that below
711678 * after all our catalog updates are done.(This isn't really
712679 * necessary anymore, but we may as well avoid the cycles of creating
713680 * and deleting the file in case we fail.)
714- *
715- * Note: The call to heap_create() changes relname for temp tables; it
716- * becomes the true physical relname. The call to
717- * heap_storage_create() does all the "real" work of creating the disk
718- * file for the relation.
719681 */
720682new_rel_desc = heap_create (relname ,relnamespace ,tupdesc ,
721- istemp , false,allow_system_table_mods );
683+ false,allow_system_table_mods );
722684
723685/* Fetch the relation OID assigned by heap_create */
724686new_rel_oid = new_rel_desc -> rd_att -> attrs [0 ]-> attrelid ;
@@ -740,8 +702,7 @@ heap_create_with_catalog(char *relname,
740702new_rel_oid ,
741703new_type_oid ,
742704relkind ,
743- relhasoids ,
744- temp_relname );
705+ relhasoids );
745706
746707/*
747708 * since defining a relation also defines a complex type, we add a new
@@ -780,12 +741,6 @@ heap_create_with_catalog(char *relname,
780741heap_close (new_rel_desc ,NoLock );/* do not unlock till end of xact */
781742heap_close (pg_class_desc ,RowExclusiveLock );
782743
783- if (istemp )
784- {
785- pfree (relname );
786- pfree (temp_relname );
787- }
788-
789744return new_rel_oid ;
790745}
791746
@@ -1226,26 +1181,19 @@ heap_drop_with_catalog(Oid rid,
12261181{
12271182Relation rel ;
12281183Oid toasttableOid ;
1229- bool has_toasttable ;
1230- bool istemp ;
12311184int i ;
12321185
12331186/*
12341187 * Open and lock the relation.
12351188 */
12361189rel = heap_open (rid ,AccessExclusiveLock );
1237- has_toasttable = rel -> rd_rel -> reltoastrelid != InvalidOid ;
12381190toasttableOid = rel -> rd_rel -> reltoastrelid ;
1239- istemp = is_temp_rel_name (RelationGetRelationName (rel ));
12401191
12411192/*
12421193 * prevent deletion of system relations
12431194 */
1244- /* allow temp of pg_class? Guess so. */
1245- if (!istemp &&
1246- !allow_system_table_mods &&
1247- IsSystemRelationName (RelationGetRelationName (rel ))&&
1248- !is_temp_relname (RelationGetRelationName (rel )))
1195+ if (!allow_system_table_mods &&
1196+ IsSystemRelationName (RelationGetRelationName (rel )))
12491197elog (ERROR ,"System relation \"%s\" may not be dropped" ,
12501198RelationGetRelationName (rel ));
12511199
@@ -1319,11 +1267,8 @@ heap_drop_with_catalog(Oid rid,
13191267 */
13201268RelationForgetRelation (rid );
13211269
1322- /* and from the temp-table map */
1323- if (istemp )
1324- remove_temp_rel_by_relid (rid );
1325-
1326- if (has_toasttable )
1270+ /* If it has a toast table, recurse to get rid of that too */
1271+ if (OidIsValid (toasttableOid ))
13271272heap_drop_with_catalog (toasttableOid , true);
13281273}
13291274