1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_largeobject relation
6 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.11 2002/05/20 23:51:42 tgl Exp $
13 *-------------------------------------------------------------------------
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "catalog/catname.h"
20 #include "catalog/indexing.h"
21 #include "catalog/pg_largeobject.h"
22 #include "miscadmin.h"
23 #include "utils/builtins.h"
24 #include "utils/fmgroids.h"
28 * Create a large object having the given LO identifier.
30 * We do this by inserting an empty first page, so that the object will
31 * appear to exist with size 0. Note that the unique index will reject
32 * an attempt to create a duplicate page.
35 LargeObjectCreate(Oid loid)
37 Relation pg_largeobject;
39 Relation idescs[Num_pg_largeobject_indices];
40 Datum values[Natts_pg_largeobject];
41 char nulls[Natts_pg_largeobject];
44 pg_largeobject = heap_openr(LargeObjectRelationName, RowExclusiveLock);
49 for (i = 0; i < Natts_pg_largeobject; i++)
51 values[i] = (Datum) NULL;
56 values[i++] = ObjectIdGetDatum(loid);
57 values[i++] = Int32GetDatum(0);
58 values[i++] = DirectFunctionCall1(byteain,
61 ntup = heap_formtuple(pg_largeobject->rd_att, values, nulls);
66 heap_insert(pg_largeobject, ntup);
71 if (!IsIgnoringSystemIndexes())
73 CatalogOpenIndices(Num_pg_largeobject_indices, Name_pg_largeobject_indices, idescs);
74 CatalogIndexInsert(idescs, Num_pg_largeobject_indices, pg_largeobject, ntup);
75 CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
78 heap_close(pg_largeobject, RowExclusiveLock);
84 LargeObjectDrop(Oid loid)
87 Relation pg_largeobject;
93 ScanKeyEntryInitialize(&skey[0],
96 (RegProcedure) F_OIDEQ,
97 ObjectIdGetDatum(loid));
99 pg_largeobject = heap_openr(LargeObjectRelationName, RowShareLock);
100 pg_lo_idx = index_openr(LargeObjectLOidPNIndex);
102 sd = index_beginscan(pg_largeobject, pg_lo_idx, SnapshotNow, 1, skey);
104 while ((tuple = index_getnext(sd, ForwardScanDirection)) != NULL)
106 simple_heap_delete(pg_largeobject, &tuple->t_self);
112 index_close(pg_lo_idx);
113 heap_close(pg_largeobject, RowShareLock);
116 elog(ERROR, "LargeObjectDrop: large object %u not found", loid);
120 LargeObjectExists(Oid loid)
123 Relation pg_largeobject;
130 * See if we can find any tuples belonging to the specified LO
132 ScanKeyEntryInitialize(&skey[0],
135 (RegProcedure) F_OIDEQ,
136 ObjectIdGetDatum(loid));
138 pg_largeobject = heap_openr(LargeObjectRelationName, RowShareLock);
139 pg_lo_idx = index_openr(LargeObjectLOidPNIndex);
141 sd = index_beginscan(pg_largeobject, pg_lo_idx, SnapshotNow, 1, skey);
143 if ((tuple = index_getnext(sd, ForwardScanDirection)) != NULL)
148 index_close(pg_lo_idx);
149 heap_close(pg_largeobject, RowShareLock);