|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.104 1999/10/15 01:49:39 momjian Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.105 1999/10/26 03:12:33 momjian Exp $ |
11 | 11 | *
|
12 | 12 | *
|
13 | 13 | * INTERFACE ROUTINES
|
|
45 | 45 | #include"catalog/pg_proc.h"
|
46 | 46 | #include"catalog/pg_relcheck.h"
|
47 | 47 | #include"catalog/pg_type.h"
|
| 48 | +#include"commands/comment.h" |
48 | 49 | #include"commands/trigger.h"
|
49 | 50 | #include"optimizer/clauses.h"
|
50 | 51 | #include"optimizer/planmain.h"
|
@@ -1276,146 +1277,18 @@ DeleteAttributeTuples(Relation rel)
|
1276 | 1277 | Int16GetDatum(attnum),
|
1277 | 1278 | 0,0)))
|
1278 | 1279 | {
|
1279 |
| -DeleteComments(tup->t_data->t_oid); |
1280 |
| -heap_delete(pg_attribute_desc,&tup->t_self,NULL); |
1281 |
| -pfree(tup); |
1282 |
| -} |
1283 |
| -} |
1284 |
| - |
1285 |
| -heap_close(pg_attribute_desc,RowExclusiveLock); |
1286 |
| -} |
1287 |
| - |
1288 |
| -/* ---------------------------------------------------------- |
1289 |
| - * CreateComments |
1290 |
| - * |
1291 |
| - * This routine is handed the oid and the command associated |
1292 |
| - * with that id and will insert, update, or delete (if the |
1293 |
| - * comment is an empty string or a NULL pointer) the associated |
1294 |
| - * comment from the system cataloge, pg_description. |
1295 |
| - * |
1296 |
| - * ---------------------------------------------------------- |
1297 |
| - */ |
1298 |
| - |
1299 |
| -void |
1300 |
| -CreateComments(Oidoid,char*comment) |
1301 |
| -{ |
| 1280 | + |
| 1281 | +/*** Delete any comments associated with this attribute ***/ |
1302 | 1282 |
|
1303 |
| -Relationdescription; |
1304 |
| -TupleDesctupDesc; |
1305 |
| -HeapScanDescscan; |
1306 |
| -ScanKeyDataentry; |
1307 |
| -HeapTupledesctuple,searchtuple; |
1308 |
| -Datumvalues[Natts_pg_description]; |
1309 |
| -charnulls[Natts_pg_description]; |
1310 |
| -charreplaces[Natts_pg_description]; |
1311 |
| -boolmodified= false; |
1312 |
| -inti; |
1313 |
| - |
1314 |
| -/*** Open pg_description, form a new tuple, if necessary ***/ |
1315 |
| - |
1316 |
| -description=heap_openr(DescriptionRelationName,RowExclusiveLock); |
1317 |
| -tupDesc=description->rd_att; |
1318 |
| -if ((comment!=NULL)&& (strlen(comment)>0)) { |
1319 |
| -for (i=0;i<Natts_pg_description;i++) { |
1320 |
| -nulls[i]=' '; |
1321 |
| -replaces[i]='r'; |
1322 |
| -values[i]= (Datum)NULL; |
1323 |
| - } |
1324 |
| -i=0; |
1325 |
| -values[i++]=ObjectIdGetDatum(oid); |
1326 |
| -values[i++]= (Datum)fmgr(F_TEXTIN,comment); |
1327 |
| - } |
1328 |
| - |
1329 |
| -/*** Now, open pg_description and attempt to find the old tuple ***/ |
1330 |
| - |
1331 |
| -ScanKeyEntryInitialize(&entry,0x0,Anum_pg_description_objoid,F_OIDEQ, |
1332 |
| -ObjectIdGetDatum(oid)); |
1333 |
| -scan=heap_beginscan(description, false,SnapshotNow,1,&entry); |
1334 |
| -searchtuple=heap_getnext(scan,0); |
1335 |
| - |
1336 |
| -/*** If a previous tuple exists, either delete it or prepare a replacement ***/ |
1337 |
| - |
1338 |
| -if (HeapTupleIsValid(searchtuple)) { |
1339 |
| - |
1340 |
| -/*** If the comment is blank, call heap_delete, else heap_replace ***/ |
1341 |
| - |
1342 |
| -if ((comment==NULL)|| (strlen(comment)==0)) { |
1343 |
| -heap_delete(description,&searchtuple->t_self,NULL); |
1344 |
| - }else { |
1345 |
| -desctuple=heap_modifytuple(searchtuple,description,values,nulls,replaces); |
1346 |
| -setheapoverride(true); |
1347 |
| -heap_replace(description,&searchtuple->t_self,desctuple,NULL); |
1348 |
| -setheapoverride(false); |
1349 |
| -modified= TRUE; |
1350 |
| - } |
1351 |
| - |
1352 |
| - }else { |
1353 |
| -desctuple=heap_formtuple(tupDesc,values,nulls); |
1354 |
| -heap_insert(description,desctuple); |
1355 |
| -modified= TRUE; |
1356 |
| - } |
1357 |
| - |
1358 |
| -/*** Complete the scan, update indices, if necessary ***/ |
1359 |
| - |
1360 |
| -heap_endscan(scan); |
1361 |
| - |
1362 |
| -if (modified) { |
1363 |
| -if (RelationGetForm(description)->relhasindex) { |
1364 |
| -Relationidescs[Num_pg_description_indices]; |
1365 |
| - |
1366 |
| -CatalogOpenIndices(Num_pg_description_indices,Name_pg_description_indices,idescs); |
1367 |
| -CatalogIndexInsert(idescs,Num_pg_description_indices,description,desctuple); |
1368 |
| -CatalogCloseIndices(Num_pg_description_indices,idescs); |
1369 |
| - } |
1370 |
| -pfree(desctuple); |
1371 |
| - |
1372 |
| - } |
1373 |
| - |
1374 |
| -heap_close(description,RowExclusiveLock); |
| 1283 | +DeleteComments(tup->t_data->t_oid); |
1375 | 1284 |
|
1376 |
| -} |
1377 |
| - |
1378 |
| -/* -------------------------------- |
1379 |
| - * DeleteComments |
1380 |
| - * |
1381 |
| - * This routine is used to purge any comments |
1382 |
| - * associated with the Oid handed to this routine, |
1383 |
| - * regardless of the actual object type. It is |
1384 |
| - * called, for example, when a relation is destroyed. |
1385 |
| - * -------------------------------- |
1386 |
| - */ |
| 1285 | +heap_delete(pg_attribute_desc,&tup->t_self,NULL); |
| 1286 | +pfree(tup); |
1387 | 1287 |
|
1388 |
| -void |
1389 |
| -DeleteComments(Oidoid) |
1390 |
| -{ |
| 1288 | +} |
| 1289 | +} |
1391 | 1290 |
|
1392 |
| -Relationdescription; |
1393 |
| -TupleDesctupDesc; |
1394 |
| -ScanKeyDataentry; |
1395 |
| -HeapScanDescscan; |
1396 |
| -HeapTuplesearchtuple; |
1397 |
| - |
1398 |
| -description=heap_openr(DescriptionRelationName,RowExclusiveLock); |
1399 |
| -tupDesc=description->rd_att; |
1400 |
| - |
1401 |
| -/*** Now, open pg_description and attempt to find the old tuple ***/ |
1402 |
| - |
1403 |
| -ScanKeyEntryInitialize(&entry,0x0,Anum_pg_description_objoid,F_OIDEQ, |
1404 |
| -ObjectIdGetDatum(oid)); |
1405 |
| -scan=heap_beginscan(description, false,SnapshotNow,1,&entry); |
1406 |
| -searchtuple=heap_getnext(scan,0); |
1407 |
| - |
1408 |
| -/*** If a previous tuple exists, delete it ***/ |
1409 |
| - |
1410 |
| -if (HeapTupleIsValid(searchtuple)) { |
1411 |
| -heap_delete(description,&searchtuple->t_self,NULL); |
1412 |
| - } |
1413 |
| - |
1414 |
| -/*** Complete the scan, update indices, if necessary ***/ |
1415 |
| - |
1416 |
| -heap_endscan(scan); |
1417 |
| -heap_close(description,RowExclusiveLock); |
1418 |
| - |
| 1291 | +heap_close(pg_attribute_desc,RowExclusiveLock); |
1419 | 1292 | }
|
1420 | 1293 |
|
1421 | 1294 | /* --------------------------------
|
@@ -1529,6 +1402,7 @@ DeleteTypeTuple(Relation rel)
|
1529 | 1402 | *we release the read lock on pg_type. -mer 13 Aug 1991
|
1530 | 1403 | * ----------------
|
1531 | 1404 | */
|
| 1405 | + |
1532 | 1406 | heap_delete(pg_type_desc,&tup->t_self,NULL);
|
1533 | 1407 |
|
1534 | 1408 | heap_endscan(pg_type_scan);
|
|