PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_range.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_range.h"
#include "catalog/pg_type.h"
#include "utils/fmgroids.h"
#include "utils/rel.h"
#include "utils/tqual.h"
Include dependency graph for pg_range.c:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 37 of file pg_range.c.

References Anum_pg_range_rngcanonical, Anum_pg_range_rngcollation, Anum_pg_range_rngsubdiff, Anum_pg_range_rngsubopc, Anum_pg_range_rngsubtype, Anum_pg_range_rngtypid, CatalogTupleInsert(), ObjectAddress::classId, CollationRelationId, DEPENDENCY_NORMAL, heap_close, heap_form_tuple(), heap_freetuple(), heap_open(), Natts_pg_range, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OidIsValid, OperatorClassRelationId, ProcedureRelationId, RangeRelationId, recordDependencyOn(), RelationGetDescr, RowExclusiveLock, TypeRelationId, and values.

Referenced by DefineRange().

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

Definition at line 113 of file pg_range.c.

References Anum_pg_range_rngtypid, BTEqualStrategyNumber, CatalogTupleDelete(), heap_close, heap_open(), HeapTupleIsValid, NULL, ObjectIdGetDatum, RangeRelationId, RangeTypidIndexId, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by RemoveTypeById().

114 {
115  Relation pg_range;
116  ScanKeyData key[1];
117  SysScanDesc scan;
118  HeapTuple tup;
119 
121 
122  ScanKeyInit(&key[0],
124  BTEqualStrategyNumber, F_OIDEQ,
125  ObjectIdGetDatum(rangeTypeOid));
126 
127  scan = systable_beginscan(pg_range, RangeTypidIndexId, true,
128  NULL, 1, key);
129 
130  while (HeapTupleIsValid(tup = systable_getnext(scan)))
131  {
132  CatalogTupleDelete(pg_range, &tup->t_self);
133  }
134 
135  systable_endscan(scan);
136 
137  heap_close(pg_range, RowExclusiveLock);
138 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define Anum_pg_range_rngtypid
Definition: pg_range.h:56
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define RangeTypidIndexId
Definition: indexing.h:324
#define RangeRelationId
Definition: pg_range.h:32
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31