7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.4 1996/11/05 11:57:50 scrappy Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.5 1996/11/06 06:47:03 scrappy Exp $
11
11
*
12
12
* INTERFACE ROUTINES
13
13
* heap_creatr() - Create an uncataloged heap relation
24
24
*
25
25
*-------------------------------------------------------------------------
26
26
*/
27
- #include <stdio.h> /* for sprintf() */
28
- #include <sys/file.h>
29
- #include <string.h>
30
-
31
- #include "postgres.h"
27
+ #include <postgres.h>
28
+
29
+ #include <utils/mcxt.h>
30
+ #include <parser/catalog_utils.h>
31
+ #include <catalog/index.h>
32
+ #include <fmgr.h>
33
+ #include <catalog/pg_index.h>
34
+ #include <catalog/pg_type.h>
35
+ #include <catalog/catname.h>
36
+ #include <utils/relcache.h>
37
+ #include <storage/bufmgr.h>
38
+ #include <catalog/heap.h>
39
+ #include <rewrite/rewriteRemove.h>
40
+ #include <storage/lmgr.h>
41
+ #include <storage/smgr.h>
42
+ #include <access/relscan.h>
43
+ #include <utils/tqual.h>
32
44
45
+ /*
33
46
#include <catalog/heap.h>
34
47
#include <catalog/pg_proc.h>
35
-
36
- #include "parser/catalog_utils.h"
37
-
38
- #include "access/heapam.h"
39
- #include "access/genam.h"
40
- #include "access/istrat.h"
41
- #include "storage/bufmgr.h"
42
- #include "lib/hasht.h"
43
- #include "miscadmin.h"
44
- #include "fmgr.h"
45
- #include "utils/builtins.h"
46
- #include "utils/mcxt.h"
47
- #include "utils/palloc.h"
48
- #include "utils/relcache.h"
49
-
50
- #include "catalog/catname.h"
51
- #include "catalog/pg_attribute.h"
52
- #include "catalog/pg_index.h"
53
- #include "catalog/pg_inherits.h"
54
- #include "catalog/pg_ipl.h"
55
- #include "catalog/index.h"
56
- #include "catalog/indexing.h"
57
-
58
- #include "catalog/catalog.h"
59
-
60
- #include "storage/lmgr.h"
61
-
62
- #include "rewrite/rewriteRemove.h"
63
-
64
- #include "storage/smgr.h"
48
+ #include <parser/catalog_utils.h>
49
+ #include <access/heapam.h>
50
+ #include <access/genam.h>
51
+ #include <access/istrat.h>
52
+ #include <storage/bufmgr.h>
53
+ #include <lib/hasht.h>
54
+ #include <miscadmin.h>
55
+ #include <fmgr.h>
56
+ #include <utils/builtins.h>
57
+ #include <utils/mcxt.h>
58
+ #include <utils/relcache.h>
59
+ #include <catalog/catname.h>
60
+ #include <catalog/pg_index.h>
61
+ #include <catalog/pg_inherits.h>
62
+ #include <catalog/pg_ipl.h>
63
+ #include <catalog/index.h>
64
+ #include <catalog/indexing.h>
65
+ #include <catalog/catalog.h>
66
+ #include <storage/lmgr.h>
67
+ #include <rewrite/rewriteRemove.h>
68
+ #include <storage/smgr.h>
69
+ */
65
70
66
71
static void AddNewAttributeTuples (Oid new_rel_oid , TupleDesc tupdesc );
67
72
static void CheckAttributeNames (TupleDesc tupdesc );
@@ -1174,263 +1179,4 @@ DeletePgTypeTuple(Relation rdesc)
1174
1179
1175
1180
/* -- -- -- -- -- -- -- --
1176
1181
* now scan pg_attribute . if any other relations have
1177
- * attributes of the type of the relation we are deleteing
1178
- * then we have to disallow the deletion. should talk to
1179
- * stonebraker about this. -cim 6/19/90
1180
- * ----------------
1181
- */
1182
- typoid = tup -> t_oid ;
1183
-
1184
- pg_attribute_desc = heap_openr (AttributeRelationName );
1185
-
1186
- ScanKeyEntryInitialize (& attkey ,
1187
- 0 , Anum_pg_attribute_atttypid , F_INT4EQ ,
1188
- typoid );
1189
-
1190
- pg_attribute_scan = heap_beginscan (pg_attribute_desc ,
1191
- 0 ,
1192
- NowTimeQual ,
1193
- 1 ,
1194
- & attkey );
1195
-
1196
- /* ----------------
1197
- * try and get a pg_attribute tuple. if we succeed it means
1198
- * we cant delete the relation because something depends on
1199
- * the schema.
1200
- * ----------------
1201
- */
1202
- atttup = heap_getnext (pg_attribute_scan , 0 , (Buffer * )NULL );
1203
-
1204
- if (PointerIsValid (atttup )) {
1205
- Oid relid = ((AttributeTupleForm ) GETSTRUCT (atttup ))-> attrelid ;
1206
-
1207
- heap_endscan (pg_type_scan );
1208
- heap_close (pg_type_desc );
1209
- heap_endscan (pg_attribute_scan );
1210
- heap_close (pg_attribute_desc );
1211
-
1212
- elog (WARN , "DeletePgTypeTuple: att of type %s exists in relation %d" ,
1213
- & rdesc -> rd_rel -> relname , relid );
1214
- }
1215
- heap_endscan (pg_attribute_scan );
1216
- heap_close (pg_attribute_desc );
1217
-
1218
- /* ----------------
1219
- * Ok, it's safe so we delete the relation tuple
1220
- * from pg_type and finish up. But first end the scan so that
1221
- * we release the read lock on pg_type. -mer 13 Aug 1991
1222
- * ----------------
1223
- */
1224
- heap_endscan (pg_type_scan );
1225
- heap_delete (pg_type_desc , & tup -> t_ctid );
1226
-
1227
- heap_close (pg_type_desc );
1228
- }
1229
-
1230
- /* --------------------------------
1231
- * heap_destroy
1232
- *
1233
- * --------------------------------
1234
- */
1235
- void
1236
- heap_destroy (char * relname )
1237
- {
1238
- Relation rdesc ;
1239
-
1240
- /* ----------------
1241
- * first open the relation. if the relation does exist,
1242
- * heap_openr() returns NULL.
1243
- * ----------------
1244
- */
1245
- rdesc = heap_openr (relname );
1246
- if (rdesc == NULL )
1247
- elog (WARN ,"Relation %s Does Not Exist!" , relname );
1248
-
1249
- /* ----------------
1250
- * prevent deletion of system relations
1251
- * ----------------
1252
- */
1253
- if (IsSystemRelationName (RelationGetRelationName (rdesc )-> data ))
1254
- elog (WARN , "amdestroy: cannot destroy %s relation" ,
1255
- & rdesc -> rd_rel -> relname );
1256
-
1257
- /* ----------------
1258
- * remove inheritance information
1259
- * ----------------
1260
- */
1261
- RelationRemoveInheritance (rdesc );
1262
-
1263
- /* ----------------
1264
- * remove indexes if necessary
1265
- * ----------------
1266
- */
1267
- if (rdesc -> rd_rel -> relhasindex ) {
1268
- RelationRemoveIndexes (rdesc );
1269
- }
1270
-
1271
- /* ----------------
1272
- * remove rules if necessary
1273
- * ----------------
1274
- */
1275
- if (rdesc -> rd_rules != NULL ) {
1276
- RelationRemoveRules (rdesc -> rd_id );
1277
- }
1278
-
1279
- /* ----------------
1280
- * delete attribute tuples
1281
- * ----------------
1282
- */
1283
- DeletePgAttributeTuples (rdesc );
1284
-
1285
- /* ----------------
1286
- * delete type tuple. here we want to see the effects
1287
- * of the deletions we just did, so we use setheapoverride().
1288
- * ----------------
1289
- */
1290
- setheapoverride (true);
1291
- DeletePgTypeTuple (rdesc );
1292
- setheapoverride (false);
1293
-
1294
- /* ----------------
1295
- * delete relation tuple
1296
- * ----------------
1297
- */
1298
- DeletePgRelationTuple (rdesc );
1299
-
1300
- /* ----------------
1301
- * flush the relation from the relcache
1302
- * ----------------
1303
- */
1304
- RelationIdInvalidateRelationCacheByRelationId (rdesc -> rd_id );
1305
-
1306
- /* ----------------
1307
- * unlink the relation and finish up.
1308
- * ----------------
1309
- */
1310
- (void ) smgrunlink (rdesc -> rd_rel -> relsmgr , rdesc );
1311
- if (rdesc -> rd_istemp ) {
1312
- rdesc -> rd_tmpunlinked = TRUE;
1313
- }
1314
- heap_close (rdesc );
1315
- }
1316
-
1317
- /*
1318
- * heap_destroyr
1319
- * destroy and close temporary relations
1320
- *
1321
- */
1322
-
1323
- void
1324
- heap_destroyr (Relation rdesc )
1325
- {
1326
- ReleaseTmpRelBuffers (rdesc );
1327
- (void ) smgrunlink (rdesc -> rd_rel -> relsmgr , rdesc );
1328
- if (rdesc -> rd_istemp ) {
1329
- rdesc -> rd_tmpunlinked = TRUE;
1330
- }
1331
- heap_close (rdesc );
1332
- RemoveFromTempRelList (rdesc );
1333
- }
1334
-
1335
-
1336
- /**************************************************************
1337
- functions to deal with the list of temporary relations
1338
- **************************************************************/
1339
-
1340
- /* --------------
1341
- InitTempRellist():
1342
-
1343
- initialize temporary relations list
1344
- the tempRelList is a list of temporary relations that
1345
- are created in the course of the transactions
1346
- they need to be destroyed properly at the end of the transactions
1347
-
1348
- MODIFIES the global variable tempRels
1349
-
1350
- >> NOTE <<
1351
-
1352
- malloc is used instead of palloc because we KNOW when we are
1353
- going to free these things. Keeps us away from the memory context
1354
- hairyness
1355
-
1356
- */
1357
- void
1358
- InitTempRelList ()
1359
- {
1360
- if (tempRels ) {
1361
- free (tempRels -> rels );
1362
- free (tempRels );
1363
- };
1364
-
1365
- tempRels = (TempRelList * )malloc (sizeof (TempRelList ));
1366
- tempRels -> size = TEMP_REL_LIST_SIZE ;
1367
- tempRels -> rels = (Relation * )malloc (sizeof (Relation ) * tempRels -> size );
1368
- memset (tempRels -> rels , 0 , sizeof (Relation ) * tempRels -> size );
1369
- tempRels -> num = 0 ;
1370
- }
1371
-
1372
- /*
1373
- removes a relation from the TempRelList
1374
-
1375
- MODIFIES the global variable tempRels
1376
- we don't really remove it, just mark it as NULL
1377
- and DestroyTempRels will look for NULLs
1378
- */
1379
- void
1380
- RemoveFromTempRelList (Relation r )
1381
- {
1382
- int i ;
1383
-
1384
- if (!tempRels )
1385
- return ;
1386
-
1387
- for (i = 0 ; i < tempRels -> num ; i ++ ) {
1388
- if (tempRels -> rels [i ] == r ) {
1389
- tempRels -> rels [i ] = NULL ;
1390
- break ;
1391
- }
1392
- }
1393
- }
1394
-
1395
- /*
1396
- add a temporary relation to the TempRelList
1397
-
1398
- MODIFIES the global variable tempRels
1399
- */
1400
- void
1401
- AddToTempRelList (Relation r )
1402
- {
1403
- if (!tempRels )
1404
- return ;
1405
-
1406
- if (tempRels -> num == tempRels -> size ) {
1407
- tempRels -> size += TEMP_REL_LIST_SIZE ;
1408
- tempRels -> rels = realloc (tempRels -> rels , tempRels -> size );
1409
- }
1410
- tempRels -> rels [tempRels -> num ] = r ;
1411
- tempRels -> num ++ ;
1412
- }
1413
-
1414
- /*
1415
- go through the tempRels list and destroy each of the relations
1416
- */
1417
- void
1418
- DestroyTempRels ()
1419
- {
1420
- int i ;
1421
- Relation rdesc ;
1422
-
1423
- if (!tempRels )
1424
- return ;
1425
-
1426
- for (i = 0 ;i < tempRels -> num ;i ++ ) {
1427
- rdesc = tempRels -> rels [i ];
1428
- /* rdesc may be NULL if it has been removed from the list already */
1429
- if (rdesc )
1430
- heap_destroyr (rdesc );
1431
- }
1432
- free (tempRels -> rels );
1433
- free (tempRels );
1434
- tempRels = NULL ;
1435
- }
1436
-
1182
+ * attributes of the type of the relation we are de
0 commit comments