8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.180 2002/11/13 00:39:47 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.181 2002/11/15 17:18:49 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1333,8 +1333,8 @@ LookupOpclassInfo(Oid operatorClassOid,
1333
1333
* formrdesc is currently used for: pg_class, pg_attribute, pg_proc,
1334
1334
* and pg_type (see RelationCacheInitialize).
1335
1335
*
1336
- * Note that these catalogs can't have constraints, default values ,
1337
- * rules, or triggers, since we don't cope with any of that.
1336
+ * Note that these catalogs can't have constraints (except attnotnull) ,
1337
+ * default values, rules, or triggers, since we don't cope with any of that.
1338
1338
*
1339
1339
* NOTE: we assume we are already switched into CacheMemoryContext.
1340
1340
*/
@@ -1345,6 +1345,7 @@ formrdesc(const char *relationName,
1345
1345
{
1346
1346
Relation relation ;
1347
1347
int i ;
1348
+ bool has_not_null ;
1348
1349
1349
1350
/*
1350
1351
* allocate new relation desc
@@ -1408,19 +1409,30 @@ formrdesc(const char *relationName,
1408
1409
/*
1409
1410
* initialize tuple desc info
1410
1411
*/
1412
+ has_not_null = false;
1411
1413
for (i = 0 ; i < natts ; i ++ )
1412
1414
{
1413
1415
relation -> rd_att -> attrs [i ] = (Form_pg_attribute ) palloc (ATTRIBUTE_TUPLE_SIZE );
1414
1416
memcpy ((char * ) relation -> rd_att -> attrs [i ],
1415
1417
(char * ) & att [i ],
1416
1418
ATTRIBUTE_TUPLE_SIZE );
1419
+ has_not_null |= att [i ].attnotnull ;
1417
1420
/* make sure attcacheoff is valid */
1418
1421
relation -> rd_att -> attrs [i ]-> attcacheoff = -1 ;
1419
1422
}
1420
1423
1421
1424
/* initialize first attribute's attcacheoff, cf RelationBuildTupleDesc */
1422
1425
relation -> rd_att -> attrs [0 ]-> attcacheoff = 0 ;
1423
1426
1427
+ /* mark not-null status */
1428
+ if (has_not_null )
1429
+ {
1430
+ TupleConstr * constr = (TupleConstr * ) palloc0 (sizeof (TupleConstr ));
1431
+
1432
+ constr -> has_not_null = true;
1433
+ relation -> rd_att -> constr = constr ;
1434
+ }
1435
+
1424
1436
/*
1425
1437
* initialize relation id from info in att array (my, this is ugly)
1426
1438
*/
@@ -2035,6 +2047,7 @@ RelationBuildLocalRelation(const char *relname,
2035
2047
MemoryContext oldcxt ;
2036
2048
int natts = tupDesc -> natts ;
2037
2049
int i ;
2050
+ bool has_not_null ;
2038
2051
2039
2052
AssertArg (natts > 0 );
2040
2053
@@ -2081,8 +2094,20 @@ RelationBuildLocalRelation(const char *relname,
2081
2094
* however.
2082
2095
*/
2083
2096
rel -> rd_att = CreateTupleDescCopy (tupDesc );
2097
+ has_not_null = false;
2084
2098
for (i = 0 ; i < natts ; i ++ )
2099
+ {
2085
2100
rel -> rd_att -> attrs [i ]-> attnotnull = tupDesc -> attrs [i ]-> attnotnull ;
2101
+ has_not_null |= tupDesc -> attrs [i ]-> attnotnull ;
2102
+ }
2103
+
2104
+ if (has_not_null )
2105
+ {
2106
+ TupleConstr * constr = (TupleConstr * ) palloc0 (sizeof (TupleConstr ));
2107
+
2108
+ constr -> has_not_null = true;
2109
+ rel -> rd_att -> constr = constr ;
2110
+ }
2086
2111
2087
2112
/*
2088
2113
* initialize relation tuple form (caller may add/override data later)
@@ -2723,6 +2748,7 @@ load_relcache_init_file(void)
2723
2748
size_t nread ;
2724
2749
Relation rel ;
2725
2750
Form_pg_class relform ;
2751
+ bool has_not_null ;
2726
2752
2727
2753
/* first read the relation descriptor length */
2728
2754
if ((nread = fread (& len , 1 , sizeof (len ), fp )) != sizeof (len ))
@@ -2764,6 +2790,7 @@ load_relcache_init_file(void)
2764
2790
relform -> relhasoids );
2765
2791
2766
2792
/* next read all the attribute tuple form data entries */
2793
+ has_not_null = false;
2767
2794
for (i = 0 ; i < relform -> relnatts ; i ++ )
2768
2795
{
2769
2796
if ((nread = fread (& len , 1 , sizeof (len ), fp )) != sizeof (len ))
@@ -2773,6 +2800,17 @@ load_relcache_init_file(void)
2773
2800
2774
2801
if ((nread = fread (rel -> rd_att -> attrs [i ], 1 , len , fp )) != len )
2775
2802
goto read_failed ;
2803
+
2804
+ has_not_null |= rel -> rd_att -> attrs [i ]-> attnotnull ;
2805
+ }
2806
+
2807
+ /* mark not-null status */
2808
+ if (has_not_null )
2809
+ {
2810
+ TupleConstr * constr = (TupleConstr * ) palloc0 (sizeof (TupleConstr ));
2811
+
2812
+ constr -> has_not_null = true;
2813
+ rel -> rd_att -> constr = constr ;
2776
2814
}
2777
2815
2778
2816
/* If it's an index, there's more to do */
0 commit comments