7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*
13
13
* INTERFACE ROUTINES
27
27
*-------------------------------------------------------------------------
28
28
*/
29
29
#include "postgres.h"
30
- #include "miscadmin.h"
31
30
32
31
#include "access/heapam.h"
33
32
#include "access/genam.h"
48
47
#include "catalog/pg_type.h"
49
48
#include "commands/comment.h"
50
49
#include "commands/trigger.h"
50
+ #include "miscadmin.h"
51
51
#include "optimizer/clauses.h"
52
52
#include "optimizer/planmain.h"
53
53
#include "optimizer/tlist.h"
67
67
68
68
69
69
static 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 );
72
73
static void AddToNoNameRelList (Relation r );
73
74
74
75
static void DeleteAttributeTuples (Relation rel );
@@ -199,7 +200,8 @@ heap_create(char *relname,
199
200
*/
200
201
AssertArg (natts > 0 );
201
202
202
- if (relname && !allowSystemTableMods && IsSystemRelationName (relname )&& IsNormalProcessingMode ())
203
+ if (relname && !allowSystemTableMods &&
204
+ IsSystemRelationName (relname )&& IsNormalProcessingMode ())
203
205
{
204
206
elog (ERROR ,"Illegal class name '%s'"
205
207
"\n\tThe 'pg_' name prefix is reserved for system catalogs" ,
@@ -361,7 +363,7 @@ heap_storage_create(Relation rel)
361
363
* descriptor contains a valid set of attribute names
362
364
*
363
365
*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
365
367
* same name already exists.
366
368
*
367
369
*3) heap_create_with_catalog() is called to create the new relation
@@ -474,8 +476,7 @@ CheckAttributeNames(TupleDesc tupdesc)
474
476
/* --------------------------------
475
477
*RelnameFindRelid
476
478
*
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.
479
480
* --------------------------------
480
481
*/
481
482
Oid
@@ -580,14 +581,10 @@ AddNewAttributeTuples(Oid new_rel_oid,
580
581
CatalogOpenIndices (Num_pg_attr_indices ,Name_pg_attr_indices ,idescs );
581
582
582
583
/* ----------------
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.
586
585
* ----------------
587
586
*/
588
- setheapoverride (true);
589
587
fillatt (tupdesc );
590
- setheapoverride (false);
591
588
592
589
/* ----------------
593
590
*first we add the user attributes..
@@ -655,7 +652,7 @@ static void
655
652
AddNewRelationTuple (Relation pg_class_desc ,
656
653
Relation new_rel_desc ,
657
654
Oid new_rel_oid ,
658
- unsigned natts ,
655
+ int natts ,
659
656
char relkind ,
660
657
char * temp_relname )
661
658
{
@@ -670,8 +667,6 @@ AddNewRelationTuple(Relation pg_class_desc,
670
667
*/
671
668
new_rel_reltup = new_rel_desc -> rd_rel ;
672
669
673
- /* CHECK should get new_rel_oid first via an insert then use XXX */
674
-
675
670
/* ----------------
676
671
* Here we insert bogus estimates of the size of the new relation.
677
672
* In reality, of course, the new relation has 0 tuples and pages,
@@ -791,7 +786,7 @@ heap_create_with_catalog(char *relname,
791
786
* ----------------
792
787
*/
793
788
Assert (IsNormalProcessingMode ()|| IsBootstrapProcessingMode ());
794
- if (natts = =0 || natts > MaxHeapAttributeNumber )
789
+ if (natts < =0 || natts > MaxHeapAttributeNumber )
795
790
elog (ERROR ,"Number of attributes is out of range"
796
791
"\n\tFrom 1 to %d attributes may be specified" ,
797
792
MaxHeapAttributeNumber );
@@ -1856,6 +1851,12 @@ StoreConstraints(Relation rel)
1856
1851
if (!constr )
1857
1852
return ;
1858
1853
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
+
1859
1860
for (i = 0 ;i < constr -> num_defval ;i ++ )
1860
1861
StoreAttrDefault (rel ,constr -> defval [i ].adnum ,
1861
1862
constr -> defval [i ].adbin , false);
@@ -1882,7 +1883,9 @@ StoreConstraints(Relation rel)
1882
1883
* expression.
1883
1884
*
1884
1885
* 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.
1886
1889
*/
1887
1890
void
1888
1891
AddRelationRawConstraints (Relation rel ,