PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_largeobject.c File Reference
#include "postgres.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "miscadmin.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/rel.h"
Include dependency graph for pg_largeobject.c:

Go to the source code of this file.

Functions

Oid LargeObjectCreate (Oid loid)
 
void LargeObjectDrop (Oid loid)
 
bool LargeObjectExists (Oid loid)
 
bool LargeObjectExistsWithSnapshot (Oid loid, Snapshot snapshot)
 

Function Documentation

◆ LargeObjectCreate()

Oid LargeObjectCreate ( Oid  loid)

Definition at line 36 of file pg_largeobject.c.

37{
38 Relation pg_lo_meta;
39 HeapTuple ntup;
40 Oid loid_new;
41 Datum values[Natts_pg_largeobject_metadata];
42 bool nulls[Natts_pg_largeobject_metadata];
43 Oid ownerId;
44 Acl *lomacl;
45
46 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
48
49 /*
50 * Insert metadata of the largeobject
51 */
52 memset(values, 0, sizeof(values));
53 memset(nulls, false, sizeof(nulls));
54
55 if (OidIsValid(loid))
56 loid_new = loid;
57 else
58 loid_new = GetNewOidWithIndex(pg_lo_meta,
59 LargeObjectMetadataOidIndexId,
60 Anum_pg_largeobject_metadata_oid);
61 ownerId = GetUserId();
63
64 values[Anum_pg_largeobject_metadata_oid - 1] = ObjectIdGetDatum(loid_new);
65 values[Anum_pg_largeobject_metadata_lomowner - 1]
66 = ObjectIdGetDatum(ownerId);
67
68 if (lomacl != NULL)
69 values[Anum_pg_largeobject_metadata_lomacl - 1]
70 = PointerGetDatum(lomacl);
71 else
72 nulls[Anum_pg_largeobject_metadata_lomacl - 1] = true;
73
74 ntup = heap_form_tuple(RelationGetDescr(pg_lo_meta),
75 values, nulls);
76
77 CatalogTupleInsert(pg_lo_meta, ntup);
78
79 heap_freetuple(ntup);
80
81 table_close(pg_lo_meta, RowExclusiveLock);
82
83 /* dependencies on roles mentioned in default ACL */
84 recordDependencyOnNewAcl(LargeObjectRelationId, loid_new, 0,
85 ownerId, lomacl);
86
87 return loid_new;
88}
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Definition: aclchk.c:4312
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition: aclchk.c:4232
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define OidIsValid(objectId)
Definition: c.h:746
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:450
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:520
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2339
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
uintptr_t Datum
Definition: postgres.h:69
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
#define InvalidOid
Definition: postgres_ext.h:35
unsigned int Oid
Definition: postgres_ext.h:30
#define RelationGetDescr(relation)
Definition: rel.h:542
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References CatalogTupleInsert(), get_user_default_acl(), GetNewOidWithIndex(), GetUserId(), heap_form_tuple(), heap_freetuple(), InvalidOid, OBJECT_LARGEOBJECT, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), recordDependencyOnNewAcl(), RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.

Referenced by inv_create().

◆ LargeObjectDrop()

void LargeObjectDrop ( Oid  loid)

Definition at line 95 of file pg_largeobject.c.

96{
97 Relation pg_lo_meta;
98 Relation pg_largeobject;
99 ScanKeyData skey[1];
100 SysScanDesc scan;
101 HeapTuple tuple;
102
103 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
105
106 pg_largeobject = table_open(LargeObjectRelationId,
108
109 /*
110 * Delete an entry from pg_largeobject_metadata
111 */
112 ScanKeyInit(&skey[0],
113 Anum_pg_largeobject_metadata_oid,
114 BTEqualStrategyNumber, F_OIDEQ,
115 ObjectIdGetDatum(loid));
116
117 scan = systable_beginscan(pg_lo_meta,
118 LargeObjectMetadataOidIndexId, true,
119 NULL, 1, skey);
120
121 tuple = systable_getnext(scan);
122 if (!HeapTupleIsValid(tuple))
124 (errcode(ERRCODE_UNDEFINED_OBJECT),
125 errmsg("large object %u does not exist", loid)));
126
127 CatalogTupleDelete(pg_lo_meta, &tuple->t_self);
128
129 systable_endscan(scan);
130
131 /*
132 * Delete all the associated entries from pg_largeobject
133 */
134 ScanKeyInit(&skey[0],
135 Anum_pg_largeobject_loid,
136 BTEqualStrategyNumber, F_OIDEQ,
137 ObjectIdGetDatum(loid));
138
139 scan = systable_beginscan(pg_largeobject,
140 LargeObjectLOidPNIndexId, true,
141 NULL, 1, skey);
142 while (HeapTupleIsValid(tuple = systable_getnext(scan)))
143 {
144 CatalogTupleDelete(pg_largeobject, &tuple->t_self);
145 }
146
147 systable_endscan(scan);
148
149 table_close(pg_largeobject, RowExclusiveLock);
150
151 table_close(pg_lo_meta, RowExclusiveLock);
152}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:388
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:365
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
ItemPointerData t_self
Definition: htup.h:65

References BTEqualStrategyNumber, CatalogTupleDelete(), ereport, errcode(), errmsg(), ERROR, HeapTupleIsValid, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

◆ LargeObjectExists()

bool LargeObjectExists ( Oid  loid)

Definition at line 167 of file pg_largeobject.c.

168{
169 return LargeObjectExistsWithSnapshot(loid, NULL);
170}
bool LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot)

References LargeObjectExistsWithSnapshot().

Referenced by be_lo_unlink(), get_object_address(), getObjectDescription(), and getObjectIdentityParts().

◆ LargeObjectExistsWithSnapshot()

bool LargeObjectExistsWithSnapshot ( Oid  loid,
Snapshot  snapshot 
)

Definition at line 176 of file pg_largeobject.c.

177{
178 Relation pg_lo_meta;
179 ScanKeyData skey[1];
180 SysScanDesc sd;
181 HeapTuple tuple;
182 bool retval = false;
183
184 ScanKeyInit(&skey[0],
185 Anum_pg_largeobject_metadata_oid,
186 BTEqualStrategyNumber, F_OIDEQ,
187 ObjectIdGetDatum(loid));
188
189 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
191
192 sd = systable_beginscan(pg_lo_meta,
193 LargeObjectMetadataOidIndexId, true,
194 snapshot, 1, skey);
195
196 tuple = systable_getnext(sd);
197 if (HeapTupleIsValid(tuple))
198 retval = true;
199
201
202 table_close(pg_lo_meta, AccessShareLock);
203
204 return retval;
205}
#define AccessShareLock
Definition: lockdefs.h:36

References AccessShareLock, BTEqualStrategyNumber, HeapTupleIsValid, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by has_lo_priv_byid(), inv_open(), and LargeObjectExists().