PostgreSQL Source Code  git master
pg_range.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_range_d.h"
Include dependency graph for pg_range.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_rangeForm_pg_range
 

Functions

 CATALOG (pg_range, 3541, RangeRelationId)
 
void RangeCreate (Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation, Oid rangeSubOpclass, RegProcedure rangeCanonical, RegProcedure rangeSubDiff)
 
void RangeDelete (Oid rangeTypeOid)
 

Variables

 FormData_pg_range
 

Typedef Documentation

◆ Form_pg_range

Definition at line 55 of file pg_range.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_range  ,
3541  ,
RangeRelationId   
)

Definition at line 29 of file pg_range.h.

References BKI_DEFAULT, and BKI_LOOKUP.

30 {
31  /* OID of owning range type */
32  Oid rngtypid BKI_LOOKUP(pg_type);
33 
34  /* OID of range's element type (subtype) */
35  Oid rngsubtype BKI_LOOKUP(pg_type);
36 
37  /* collation for this range type, or 0 */
38  Oid rngcollation BKI_DEFAULT(0);
39 
40  /* subtype's btree opclass */
41  Oid rngsubopc BKI_LOOKUP(pg_opclass);
42 
43  /* canonicalize range, or 0 */
44  regproc rngcanonical BKI_LOOKUP(pg_proc);
45 
46  /* subtype difference as a float8, or 0 */
47  regproc rngsubdiff BKI_LOOKUP(pg_proc);
FormData_pg_range
Definition: pg_range.h:48
unsigned int Oid
Definition: postgres_ext.h:31
#define BKI_DEFAULT(value)
Definition: genbki.h:35
#define BKI_LOOKUP(catalog)
Definition: genbki.h:42
Oid regproc
Definition: c.h:504

◆ RangeCreate()

void RangeCreate ( Oid  rangeTypeOid,
Oid  rangeSubType,
Oid  rangeCollation,
Oid  rangeSubOpclass,
RegProcedure  rangeCanonical,
RegProcedure  rangeSubDiff 
)

Definition at line 36 of file pg_range.c.

References CatalogTupleInsert(), ObjectAddress::classId, DEPENDENCY_NORMAL, heap_form_tuple(), heap_freetuple(), ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OidIsValid, recordDependencyOn(), RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.

Referenced by DefineRange().

39 {
40  Relation pg_range;
41  Datum values[Natts_pg_range];
42  bool nulls[Natts_pg_range];
43  HeapTuple tup;
44  ObjectAddress myself;
45  ObjectAddress referenced;
46 
47  pg_range = table_open(RangeRelationId, RowExclusiveLock);
48 
49  memset(nulls, 0, sizeof(nulls));
50 
51  values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
52  values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
53  values[Anum_pg_range_rngcollation - 1] = ObjectIdGetDatum(rangeCollation);
54  values[Anum_pg_range_rngsubopc - 1] = ObjectIdGetDatum(rangeSubOpclass);
55  values[Anum_pg_range_rngcanonical - 1] = ObjectIdGetDatum(rangeCanonical);
56  values[Anum_pg_range_rngsubdiff - 1] = ObjectIdGetDatum(rangeSubDiff);
57 
58  tup = heap_form_tuple(RelationGetDescr(pg_range), values, nulls);
59 
60  CatalogTupleInsert(pg_range, tup);
61  heap_freetuple(tup);
62 
63  /* record type's dependencies on range-related items */
64 
65  myself.classId = TypeRelationId;
66  myself.objectId = rangeTypeOid;
67  myself.objectSubId = 0;
68 
69  referenced.classId = TypeRelationId;
70  referenced.objectId = rangeSubType;
71  referenced.objectSubId = 0;
72  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
73 
74  referenced.classId = OperatorClassRelationId;
75  referenced.objectId = rangeSubOpclass;
76  referenced.objectSubId = 0;
77  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
78 
79  if (OidIsValid(rangeCollation))
80  {
81  referenced.classId = CollationRelationId;
82  referenced.objectId = rangeCollation;
83  referenced.objectSubId = 0;
84  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
85  }
86 
87  if (OidIsValid(rangeCanonical))
88  {
89  referenced.classId = ProcedureRelationId;
90  referenced.objectId = rangeCanonical;
91  referenced.objectSubId = 0;
92  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
93  }
94 
95  if (OidIsValid(rangeSubDiff))
96  {
97  referenced.classId = ProcedureRelationId;
98  referenced.objectId = rangeSubDiff;
99  referenced.objectSubId = 0;
100  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
101  }
102 
103  table_close(pg_range, RowExclusiveLock);
104 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define RelationGetDescr(relation)
Definition: rel.h:445
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:43
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define OidIsValid(objectId)
Definition: c.h:638
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:367
static Datum values[MAXATTR]
Definition: bootstrap.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:183

◆ RangeDelete()

void RangeDelete ( Oid  rangeTypeOid)

Definition at line 112 of file pg_range.c.

References BTEqualStrategyNumber, CatalogTupleDelete(), HeapTupleIsValid, sort-test::key, ObjectIdGetDatum, RangeTypidIndexId, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by RemoveTypeById().

113 {
114  Relation pg_range;
115  ScanKeyData key[1];
116  SysScanDesc scan;
117  HeapTuple tup;
118 
119  pg_range = table_open(RangeRelationId, RowExclusiveLock);
120 
121  ScanKeyInit(&key[0],
122  Anum_pg_range_rngtypid,
123  BTEqualStrategyNumber, F_OIDEQ,
124  ObjectIdGetDatum(rangeTypeOid));
125 
126  scan = systable_beginscan(pg_range, RangeTypidIndexId, true,
127  NULL, 1, key);
128 
129  while (HeapTupleIsValid(tup = systable_getnext(scan)))
130  {
131  CatalogTupleDelete(pg_range, &tup->t_self);
132  }
133 
134  systable_endscan(scan);
135 
136  table_close(pg_range, RowExclusiveLock);
137 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:269
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define RangeTypidIndexId
Definition: indexing.h:331
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

Variable Documentation

◆ FormData_pg_range

FormData_pg_range

Definition at line 48 of file pg_range.h.