PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pg_largeobject.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_largeobject_d.h"
#include "utils/snapshot.h"
Include dependency graph for pg_largeobject.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_largeobjectForm_pg_largeobject
 

Functions

 CATALOG (pg_largeobject, 2613, LargeObjectRelationId)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_largeobject_loid_pn_index, 2683, LargeObjectLOidPNIndexId, pg_largeobject, btree(loid oid_ops, pageno int4_ops))
 
Oid LargeObjectCreate (Oid loid)
 
void LargeObjectDrop (Oid loid)
 
bool LargeObjectExists (Oid loid)
 
bool LargeObjectExistsWithSnapshot (Oid loid, Snapshot snapshot)
 

Variables

 FormData_pg_largeobject
 

Typedef Documentation

◆ Form_pg_largeobject

Definition at line 46 of file pg_largeobject.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_largeobject  ,
2613  ,
LargeObjectRelationId   
)

Definition at line 30 of file pg_largeobject.h.

31{
32 Oid loid BKI_LOOKUP(pg_largeobject_metadata); /* Identifier of large
33 * object */
34 int32 pageno; /* Page number (starting from 0) */
35
36 /* data has variable length, but we allow direct access; see inv_api.c */
37 bytea data BKI_FORCE_NOT_NULL; /* Data for page (may be
38 * zero-length) */
int32_t int32
Definition: c.h:481
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:33
const void * data
FormData_pg_largeobject
unsigned int Oid
Definition: postgres_ext.h:31
Definition: c.h:641

References BKI_FORCE_NOT_NULL, BKI_LOOKUP, and data.

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_largeobject_loid_pn_index  ,
2683  ,
LargeObjectLOidPNIndexId  ,
pg_largeobject  ,
btree(loid oid_ops, pageno int4_ops)   
)

◆ LargeObjectCreate()

Oid LargeObjectCreate ( Oid  loid)

Definition at line 35 of file pg_largeobject.c.

36{
37 Relation pg_lo_meta;
38 HeapTuple ntup;
39 Oid loid_new;
40 Datum values[Natts_pg_largeobject_metadata];
41 bool nulls[Natts_pg_largeobject_metadata];
42
43 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
45
46 /*
47 * Insert metadata of the largeobject
48 */
49 memset(values, 0, sizeof(values));
50 memset(nulls, false, sizeof(nulls));
51
52 if (OidIsValid(loid))
53 loid_new = loid;
54 else
55 loid_new = GetNewOidWithIndex(pg_lo_meta,
56 LargeObjectMetadataOidIndexId,
57 Anum_pg_largeobject_metadata_oid);
58
59 values[Anum_pg_largeobject_metadata_oid - 1] = ObjectIdGetDatum(loid_new);
60 values[Anum_pg_largeobject_metadata_lomowner - 1]
62 nulls[Anum_pg_largeobject_metadata_lomacl - 1] = true;
63
64 ntup = heap_form_tuple(RelationGetDescr(pg_lo_meta),
65 values, nulls);
66
67 CatalogTupleInsert(pg_lo_meta, ntup);
68
69 heap_freetuple(ntup);
70
71 table_close(pg_lo_meta, RowExclusiveLock);
72
73 return loid_new;
74}
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define OidIsValid(objectId)
Definition: c.h:729
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:419
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:517
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
#define RelationGetDescr(relation)
Definition: rel.h:531
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References CatalogTupleInsert(), GetNewOidWithIndex(), GetUserId(), heap_form_tuple(), heap_freetuple(), ObjectIdGetDatum(), OidIsValid, RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.

Referenced by inv_create().

◆ LargeObjectDrop()

void LargeObjectDrop ( Oid  loid)

Definition at line 81 of file pg_largeobject.c.

82{
83 Relation pg_lo_meta;
84 Relation pg_largeobject;
85 ScanKeyData skey[1];
86 SysScanDesc scan;
87 HeapTuple tuple;
88
89 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
91
92 pg_largeobject = table_open(LargeObjectRelationId,
94
95 /*
96 * Delete an entry from pg_largeobject_metadata
97 */
98 ScanKeyInit(&skey[0],
99 Anum_pg_largeobject_metadata_oid,
100 BTEqualStrategyNumber, F_OIDEQ,
101 ObjectIdGetDatum(loid));
102
103 scan = systable_beginscan(pg_lo_meta,
104 LargeObjectMetadataOidIndexId, true,
105 NULL, 1, skey);
106
107 tuple = systable_getnext(scan);
108 if (!HeapTupleIsValid(tuple))
110 (errcode(ERRCODE_UNDEFINED_OBJECT),
111 errmsg("large object %u does not exist", loid)));
112
113 CatalogTupleDelete(pg_lo_meta, &tuple->t_self);
114
115 systable_endscan(scan);
116
117 /*
118 * Delete all the associated entries from pg_largeobject
119 */
120 ScanKeyInit(&skey[0],
121 Anum_pg_largeobject_loid,
122 BTEqualStrategyNumber, F_OIDEQ,
123 ObjectIdGetDatum(loid));
124
125 scan = systable_beginscan(pg_largeobject,
126 LargeObjectLOidPNIndexId, true,
127 NULL, 1, skey);
128 while (HeapTupleIsValid(tuple = systable_getnext(scan)))
129 {
130 CatalogTupleDelete(pg_largeobject, &tuple->t_self);
131 }
132
133 systable_endscan(scan);
134
135 table_close(pg_largeobject, RowExclusiveLock);
136
137 table_close(pg_lo_meta, RowExclusiveLock);
138}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:606
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:513
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
#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 153 of file pg_largeobject.c.

154{
155 return LargeObjectExistsWithSnapshot(loid, NULL);
156}
bool LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot)

References LargeObjectExistsWithSnapshot().

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

◆ LargeObjectExistsWithSnapshot()

bool LargeObjectExistsWithSnapshot ( Oid  loid,
Snapshot  snapshot 
)

Definition at line 162 of file pg_largeobject.c.

163{
164 Relation pg_lo_meta;
165 ScanKeyData skey[1];
166 SysScanDesc sd;
167 HeapTuple tuple;
168 bool retval = false;
169
170 ScanKeyInit(&skey[0],
171 Anum_pg_largeobject_metadata_oid,
172 BTEqualStrategyNumber, F_OIDEQ,
173 ObjectIdGetDatum(loid));
174
175 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
177
178 sd = systable_beginscan(pg_lo_meta,
179 LargeObjectMetadataOidIndexId, true,
180 snapshot, 1, skey);
181
182 tuple = systable_getnext(sd);
183 if (HeapTupleIsValid(tuple))
184 retval = true;
185
187
188 table_close(pg_lo_meta, AccessShareLock);
189
190 return retval;
191}
#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().

Variable Documentation

◆ FormData_pg_largeobject

FormData_pg_largeobject

Definition at line 39 of file pg_largeobject.h.