Skip to content

Commit 577e21b

Browse files
committed
Hello.
The following patch extends the COMMENT ON functionality to the rest of the database objects beyond just tables, columns, and views. The grammer of the COMMENT ON statement now looks like: COMMENT ON [ [ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <objname> | COLUMN <relation>.<attribute> | AGGREGATE <aggname> <aggtype> | FUNCTION <funcname> (arg1, arg2, ...) | OPERATOR <op> (leftoperand_typ rightoperand_typ) | TRIGGER <triggername> ON relname> Mike Mascari (mascarim@yahoo.com)
1 parent 51f62d5 commit 577e21b

File tree

15 files changed

+1039
-238
lines changed

15 files changed

+1039
-238
lines changed

src/backend/catalog/heap.c

Lines changed: 11 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* 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 $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -45,6 +45,7 @@
4545
#include "catalog/pg_proc.h"
4646
#include "catalog/pg_relcheck.h"
4747
#include "catalog/pg_type.h"
48+
#include "commands/comment.h"
4849
#include "commands/trigger.h"
4950
#include "optimizer/clauses.h"
5051
#include "optimizer/planmain.h"
@@ -1276,146 +1277,18 @@ DeleteAttributeTuples(Relation rel)
12761277
Int16GetDatum(attnum),
12771278
0, 0)))
12781279
{
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(Oid oid, char *comment)
1301-
{
1280+
1281+
/*** Delete any comments associated with this attribute ***/
13021282

1303-
Relation description;
1304-
TupleDesc tupDesc;
1305-
HeapScanDesc scan;
1306-
ScanKeyData entry;
1307-
HeapTuple desctuple, searchtuple;
1308-
Datum values[Natts_pg_description];
1309-
char nulls[Natts_pg_description];
1310-
char replaces[Natts_pg_description];
1311-
bool modified = false;
1312-
int i;
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-
Relation idescs[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);
13751284

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);
13871287

1388-
void
1389-
DeleteComments(Oid oid)
1390-
{
1288+
}
1289+
}
13911290

1392-
Relation description;
1393-
TupleDesc tupDesc;
1394-
ScanKeyData entry;
1395-
HeapScanDesc scan;
1396-
HeapTuple searchtuple;
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);
14191292
}
14201293

14211294
/* --------------------------------
@@ -1529,6 +1402,7 @@ DeleteTypeTuple(Relation rel)
15291402
* we release the read lock on pg_type. -mer 13 Aug 1991
15301403
* ----------------
15311404
*/
1405+
15321406
heap_delete(pg_type_desc, &tup->t_self, NULL);
15331407

15341408
heap_endscan(pg_type_scan);

src/backend/catalog/index.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.91 1999/09/24 00:24:11 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.92 1999/10/26 03:12:33 momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -32,6 +32,7 @@
3232
#include "catalog/pg_index.h"
3333
#include "catalog/pg_proc.h"
3434
#include "catalog/pg_type.h"
35+
#include "commands/comment.h"
3536
#include "executor/executor.h"
3637
#include "miscadmin.h"
3738
#include "optimizer/clauses.h"
@@ -1127,6 +1128,13 @@ index_destroy(Oid indexId)
11271128
if (IsTransactionBlock() && ! userindexRelation->rd_myxactonly)
11281129
elog(NOTICE, "Caution: DROP INDEX cannot be rolled back, so don't abort now");
11291130

1131+
/* ----------------
1132+
* fix DESCRIPTION relation
1133+
* ----------------
1134+
*/
1135+
1136+
DeleteComments(indexId);
1137+
11301138
/* ----------------
11311139
* fix RELATION relation
11321140
* ----------------

src/backend/commands/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for commands
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.18 1999/02/27 21:42:33 tgl Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.19 1999/10/26 03:12:34 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -17,7 +17,7 @@ ifdef MULTIBYTE
1717
CFLAGS+= $(MBFLAGS)
1818
endif
1919

20-
OBJS = async.o creatinh.o command.o copy.o indexcmds.o define.o \
20+
OBJS = async.o creatinh.o command.o comment.o copy.o indexcmds.o define.o \
2121
remove.o rename.o vacuum.o view.o cluster.o \
2222
explain.o sequence.o trigger.o user.o proclang.o \
2323
dbcommands.o variable.o
@@ -27,6 +27,12 @@ all: SUBSYS.o
2727
SUBSYS.o: $(OBJS)
2828
$(LD) -r -o SUBSYS.o $(OBJS)
2929

30+
# The following declares a hard-coded dependency on parse.h since,
31+
# if compiled without make dep, comment.c would get compiled before
32+
# the parser.
33+
34+
comment.o: ../parse.h
35+
3036
depend dep:
3137
$(CC) -MM $(CFLAGS) *.c >depend
3238

0 commit comments

Comments
 (0)