88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.132 2000/06/17 23:41:31 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.133 2000/06/18 22:43:55 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -70,14 +70,11 @@ static void AddNewRelationTuple(Relation pg_class_desc,
7070Relation new_rel_desc ,Oid new_rel_oid ,
7171int natts ,
7272char relkind ,char * temp_relname );
73- static void AddToNoNameRelList (Relation r );
74-
7573static void DeleteAttributeTuples (Relation rel );
7674static void DeleteRelationTuple (Relation rel );
7775static void DeleteTypeTuple (Relation rel );
7876static void RelationRemoveIndexes (Relation relation );
7977static void RelationRemoveInheritance (Relation relation );
80- static void RemoveFromNoNameRelList (Relation r );
8178static void AddNewRelationType (char * typeName ,Oid new_rel_oid );
8279static void StoreAttrDefault (Relation rel ,AttrNumber attnum ,char * adbin ,
8380bool updatePgAttribute );
@@ -141,22 +138,6 @@ static Form_pg_attribute HeapAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6};
141138 * ----------------------------------------------------------------
142139 */
143140
144- /* the tempRelList holds
145- the list of temporary uncatalogued relations that are created.
146- these relations should be destroyed at the end of transactions
147- */
148- typedef struct tempRelList
149- {
150- Relation * rels ;/* array of relation descriptors */
151- int num ;/* number of temporary relations */
152- int size ;/* size of space allocated for the rels
153- * array */
154- }TempRelList ;
155-
156- #define NONAME_REL_LIST_SIZE 32
157-
158- static TempRelList * tempRels = NULL ;
159-
160141
161142/* ----------------------------------------------------------------
162143 *heap_create- Create an uncataloged heap relation
@@ -170,15 +151,16 @@ static TempRelList *tempRels = NULL;
170151 *Eventually, must place information about this temporary relation
171152 *into the transaction context block.
172153 *
154+ * NOTE: if istemp is TRUE then heap_create will overwrite relname with
155+ * the unique "real" name chosen for the temp relation.
173156 *
174- *if heap_create iscalled with "" as the name, then heap_create will create
175- *a temporary name "pg_noname.$PID.$SEQUENCE" for the relation
157+ *If storage_create isTRUE then heap_storage_create is called here,
158+ *else caller must call heap_storage_create later.
176159 * ----------------------------------------------------------------
177160 */
178161Relation
179162heap_create (char * relname ,
180163TupleDesc tupDesc ,
181- bool isnoname ,
182164bool istemp ,
183165bool storage_create )
184166{
@@ -245,18 +227,11 @@ heap_create(char *relname,
245227else
246228relid = newoid ();
247229
248- if (isnoname )
249- {
250- Assert (!relname );
251- relname = palloc (NAMEDATALEN );
252- snprintf (relname ,NAMEDATALEN ,"pg_noname.%d.%u" ,
253- (int )MyProcPid ,uniqueId ++ );
254- }
255-
256230if (istemp )
257231{
258- /* replace relname of caller */
259- snprintf (relname ,NAMEDATALEN ,"pg_temp.%d.%u" ,MyProcPid ,uniqueId ++ );
232+ /* replace relname of caller with a unique name for a temp relation */
233+ snprintf (relname ,NAMEDATALEN ,"pg_temp.%d.%u" ,
234+ (int )MyProcPid ,uniqueId ++ );
260235}
261236
262237/* ----------------
@@ -268,7 +243,7 @@ heap_create(char *relname,
268243rel = (Relation )palloc (len );
269244MemSet ((char * )rel ,0 ,len );
270245rel -> rd_fd = -1 ;/* table is not open */
271- rel -> rd_unlinked = TRUE ;/* table is not created yet */
246+ rel -> rd_unlinked = true ;/* table is not created yet */
272247
273248/*
274249 * create a new tuple descriptor from the one passed in
@@ -310,12 +285,6 @@ heap_create(char *relname,
310285rel -> rd_rel -> reltype = relid ;
311286}
312287
313- /* ----------------
314- *remember if this is a noname relation
315- * ----------------
316- */
317- rel -> rd_isnoname = isnoname ;
318-
319288/* ----------------
320289 *have the storage manager create the relation.
321290 * ----------------
@@ -329,13 +298,6 @@ heap_create(char *relname,
329298
330299MemoryContextSwitchTo (oldcxt );
331300
332- /*
333- * add all noname relations to the tempRels list so they can be
334- * properly disposed of at the end of transaction
335- */
336- if (isnoname )
337- AddToNoNameRelList (rel );
338-
339301return rel ;
340302}
341303
@@ -347,7 +309,7 @@ heap_storage_create(Relation rel)
347309if (rel -> rd_unlinked )
348310{
349311rel -> rd_fd = (File )smgrcreate (DEFAULT_SMGR ,rel );
350- rel -> rd_unlinked = FALSE ;
312+ rel -> rd_unlinked = false ;
351313smgrcall = true;
352314}
353315return smgrcall ;
@@ -810,7 +772,7 @@ heap_create_with_catalog(char *relname,
810772 *get_temp_rel_by_username() couldn't check the simultaneous
811773 *creation. Uniqueness will be really checked by unique
812774 *indexes of system tables but we couldn't check it here.
813- *We have topospone to create the disk file for this
775+ *We have topostpone creating the disk file for this
814776 *relation.
815777 *Another boolean parameter "storage_create" was added
816778 *to heap_create() function. If the parameter is false
@@ -821,12 +783,12 @@ heap_create_with_catalog(char *relname,
821783 *relation descriptor.
822784 *
823785 *Note: The call to heap_create() changes relname for
824- *noname and temp tables.
786+ *temp tables; it becomes the true physical relname .
825787 *The call to heap_storage_create() does all the "real"
826788 *work of creating the disk file for the relation.
827789 * ----------------
828790 */
829- new_rel_desc = heap_create (relname ,tupdesc ,false, istemp , false);
791+ new_rel_desc = heap_create (relname ,tupdesc ,istemp , false);
830792
831793new_rel_oid = new_rel_desc -> rd_att -> attrs [0 ]-> attrelid ;
832794
@@ -1546,10 +1508,9 @@ heap_drop_with_catalog(const char *relname)
15461508 *unlink the relation's physical file and finish up.
15471509 * ----------------
15481510 */
1549- if (!( rel -> rd_isnoname ) || !( rel -> rd_unlinked ) )
1511+ if (!rel -> rd_unlinked )
15501512smgrunlink (DEFAULT_SMGR ,rel );
1551-
1552- rel -> rd_unlinked = TRUE;
1513+ rel -> rd_unlinked = true;
15531514
15541515/*
15551516 * Close relcache entry, but *keep* AccessExclusiveLock on the
@@ -1568,133 +1529,6 @@ heap_drop_with_catalog(const char *relname)
15681529remove_temp_relation (rid );
15691530}
15701531
1571- /*
1572- * heap_drop
1573- * destroy and close temporary relations
1574- *
1575- */
1576-
1577- void
1578- heap_drop (Relation rel )
1579- {
1580- Oid rid = RelationGetRelid (rel );
1581-
1582- ReleaseRelationBuffers (rel );
1583- if (!(rel -> rd_isnoname )|| !(rel -> rd_unlinked ))
1584- smgrunlink (DEFAULT_SMGR ,rel );
1585- rel -> rd_unlinked = TRUE;
1586- heap_close (rel ,NoLock );
1587- RemoveFromNoNameRelList (rel );
1588- RelationForgetRelation (rid );
1589- }
1590-
1591-
1592- /**************************************************************
1593- functions to deal with the list of temporary relations
1594- **************************************************************/
1595-
1596- /* --------------
1597- InitTempRellist():
1598-
1599- initialize temporary relations list
1600- the tempRelList is a list of temporary relations that
1601- are created in the course of the transactions
1602- they need to be destroyed properly at the end of the transactions
1603-
1604- MODIFIES the global variable tempRels
1605-
1606- >> NOTE <<
1607-
1608- malloc is used instead of palloc because we KNOW when we are
1609- going to free these things.Keeps us away from the memory context
1610- hairyness
1611-
1612- */
1613- void
1614- InitNoNameRelList (void )
1615- {
1616- if (tempRels )
1617- {
1618- free (tempRels -> rels );
1619- free (tempRels );
1620- }
1621-
1622- tempRels = (TempRelList * )malloc (sizeof (TempRelList ));
1623- tempRels -> size = NONAME_REL_LIST_SIZE ;
1624- tempRels -> rels = (Relation * )malloc (sizeof (Relation )* tempRels -> size );
1625- MemSet (tempRels -> rels ,0 ,sizeof (Relation )* tempRels -> size );
1626- tempRels -> num = 0 ;
1627- }
1628-
1629- /*
1630- removes a relation from the TempRelList
1631-
1632- MODIFIES the global variable tempRels
1633- we don't really remove it, just mark it as NULL
1634- and DropNoNameRels will look for NULLs
1635- */
1636- static void
1637- RemoveFromNoNameRelList (Relation r )
1638- {
1639- int i ;
1640-
1641- if (!tempRels )
1642- return ;
1643-
1644- for (i = 0 ;i < tempRels -> num ;i ++ )
1645- {
1646- if (tempRels -> rels [i ]== r )
1647- {
1648- tempRels -> rels [i ]= NULL ;
1649- break ;
1650- }
1651- }
1652- }
1653-
1654- /*
1655- add a temporary relation to the TempRelList
1656-
1657- MODIFIES the global variable tempRels
1658- */
1659- static void
1660- AddToNoNameRelList (Relation r )
1661- {
1662- if (!tempRels )
1663- return ;
1664-
1665- if (tempRels -> num == tempRels -> size )
1666- {
1667- tempRels -> size += NONAME_REL_LIST_SIZE ;
1668- tempRels -> rels = realloc (tempRels -> rels ,
1669- sizeof (Relation )* tempRels -> size );
1670- }
1671- tempRels -> rels [tempRels -> num ]= r ;
1672- tempRels -> num ++ ;
1673- }
1674-
1675- /*
1676- go through the tempRels list and destroy each of the relations
1677- */
1678- void
1679- DropNoNameRels (void )
1680- {
1681- int i ;
1682- Relation rel ;
1683-
1684- if (!tempRels )
1685- return ;
1686-
1687- for (i = 0 ;i < tempRels -> num ;i ++ )
1688- {
1689- rel = tempRels -> rels [i ];
1690- /* rel may be NULL if it has been removed from the list already */
1691- if (rel )
1692- heap_drop (rel );
1693- }
1694- free (tempRels -> rels );
1695- free (tempRels );
1696- tempRels = NULL ;
1697- }
16981532
16991533/*
17001534 * Store a default expression for column attnum of relation rel.