77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.114 1999/12/20 10:40:40 wieck Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.115 2000/01/16 19:57:00 tgl Exp $
1111 *
1212 *
1313 * INTERFACE ROUTINES
2727 *-------------------------------------------------------------------------
2828 */
2929#include "postgres.h"
30- #include "miscadmin.h"
3130
3231#include "access/heapam.h"
3332#include "access/genam.h"
4847#include "catalog/pg_type.h"
4948#include "commands/comment.h"
5049#include "commands/trigger.h"
50+ #include "miscadmin.h"
5151#include "optimizer/clauses.h"
5252#include "optimizer/planmain.h"
5353#include "optimizer/tlist.h"
6767
6868
6969static void AddNewRelationTuple (Relation pg_class_desc ,
70- Relation new_rel_desc ,Oid new_rel_oid ,unsigned natts ,
71- char relkind ,char * temp_relname );
70+ Relation new_rel_desc ,Oid new_rel_oid ,
71+ int natts ,
72+ char relkind ,char * temp_relname );
7273static void AddToNoNameRelList (Relation r );
7374
7475static void DeleteAttributeTuples (Relation rel );
@@ -199,7 +200,8 @@ heap_create(char *relname,
199200 */
200201AssertArg (natts > 0 );
201202
202- if (relname && !allowSystemTableMods && IsSystemRelationName (relname )&& IsNormalProcessingMode ())
203+ if (relname && !allowSystemTableMods &&
204+ IsSystemRelationName (relname )&& IsNormalProcessingMode ())
203205{
204206elog (ERROR ,"Illegal class name '%s'"
205207"\n\tThe 'pg_' name prefix is reserved for system catalogs" ,
@@ -361,7 +363,7 @@ heap_storage_create(Relation rel)
361363 * descriptor contains a valid set of attribute names
362364 *
363365 *2) pg_class is opened and RelationFindRelid()
364- *preforms a scan to ensure that no relation with the
366+ *performs a scan to ensure that no relation with the
365367 * same name already exists.
366368 *
367369 *3) heap_create_with_catalog() is called to create the new relation
@@ -474,8 +476,7 @@ CheckAttributeNames(TupleDesc tupdesc)
474476/* --------------------------------
475477 *RelnameFindRelid
476478 *
477- *this preforms a scan of pg_class to ensure that
478- *no relation with the same name already exists.
479+ *Find any existing relation of the given name.
479480 * --------------------------------
480481 */
481482Oid
@@ -580,14 +581,10 @@ AddNewAttributeTuples(Oid new_rel_oid,
580581CatalogOpenIndices (Num_pg_attr_indices ,Name_pg_attr_indices ,idescs );
581582
582583/* ----------------
583- *initialize tuple descriptor. Note we use setheapoverride()
584- *so that we can see the effects of our TypeDefine() done
585- *previously.
584+ *initialize tuple descriptor.
586585 * ----------------
587586 */
588- setheapoverride (true);
589587fillatt (tupdesc );
590- setheapoverride (false);
591588
592589/* ----------------
593590 *first we add the user attributes..
@@ -655,7 +652,7 @@ static void
655652AddNewRelationTuple (Relation pg_class_desc ,
656653Relation new_rel_desc ,
657654Oid new_rel_oid ,
658- unsigned natts ,
655+ int natts ,
659656char relkind ,
660657char * temp_relname )
661658{
@@ -670,8 +667,6 @@ AddNewRelationTuple(Relation pg_class_desc,
670667 */
671668new_rel_reltup = new_rel_desc -> rd_rel ;
672669
673- /* CHECK should get new_rel_oid first via an insert then use XXX */
674-
675670/* ----------------
676671 * Here we insert bogus estimates of the size of the new relation.
677672 * In reality, of course, the new relation has 0 tuples and pages,
@@ -791,7 +786,7 @@ heap_create_with_catalog(char *relname,
791786 * ----------------
792787 */
793788Assert (IsNormalProcessingMode ()|| IsBootstrapProcessingMode ());
794- if (natts = =0 || natts > MaxHeapAttributeNumber )
789+ if (natts < =0 || natts > MaxHeapAttributeNumber )
795790elog (ERROR ,"Number of attributes is out of range"
796791"\n\tFrom 1 to %d attributes may be specified" ,
797792MaxHeapAttributeNumber );
@@ -1856,6 +1851,12 @@ StoreConstraints(Relation rel)
18561851if (!constr )
18571852return ;
18581853
1854+ /* deparsing of constraint expressions will fail unless the just-created
1855+ * pg_attribute tuples for this relation are made visible. So, bump
1856+ * the command counter.
1857+ */
1858+ CommandCounterIncrement ();
1859+
18591860for (i = 0 ;i < constr -> num_defval ;i ++ )
18601861StoreAttrDefault (rel ,constr -> defval [i ].adnum ,
18611862constr -> defval [i ].adbin , false);
@@ -1882,7 +1883,9 @@ StoreConstraints(Relation rel)
18821883 * expression.
18831884 *
18841885 * NB: caller should have opened rel with AccessExclusiveLock, and should
1885- * hold that lock till end of transaction.
1886+ * hold that lock till end of transaction. Also, we assume the caller has
1887+ * done a CommandCounterIncrement if necessary to make the relation's catalog
1888+ * tuples visible.
18861889 */
18871890void
18881891AddRelationRawConstraints (Relation rel ,