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)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_range_rngtypid_index, 3542, RangeTypidIndexId, pg_range, btree(rngtypid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_range_rngmultitypid_index, 2228, RangeMultirangeTypidIndexId, pg_range, btree(rngmultitypid oid_ops))
 
 MAKE_SYSCACHE (RANGETYPE, pg_range_rngtypid_index, 4)
 
 MAKE_SYSCACHE (RANGEMULTIRANGE, pg_range_rngmultitypid_index, 4)
 
void RangeCreate (Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation, Oid rangeSubOpclass, RegProcedure rangeCanonical, RegProcedure rangeSubDiff, Oid multirangeTypeOid)
 
void RangeDelete (Oid rangeTypeOid)
 

Variables

 FormData_pg_range
 

Typedef Documentation

◆ Form_pg_range

Definition at line 58 of file pg_range.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_range  ,
3541  ,
RangeRelationId   
)

Definition at line 29 of file pg_range.h.

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  /* OID of the range's multirange type */
38  Oid rngmultitypid BKI_LOOKUP(pg_type);
39 
40  /* collation for this range type, or 0 */
41  Oid rngcollation BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_collation);
42 
43  /* subtype's btree opclass */
44  Oid rngsubopc BKI_LOOKUP(pg_opclass);
45 
46  /* canonicalize range, or 0 */
47  regproc rngcanonical BKI_LOOKUP_OPT(pg_proc);
48 
49  /* subtype difference as a float8, or 0 */
50  regproc rngsubdiff BKI_LOOKUP_OPT(pg_proc);
Oid regproc
Definition: c.h:649
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_DEFAULT(value)
Definition: genbki.h:35
#define BKI_LOOKUP_OPT(catalog)
Definition: genbki.h:47
FormData_pg_range
Definition: pg_range.h:51
unsigned int Oid
Definition: postgres_ext.h:31

References BKI_DEFAULT, BKI_LOOKUP, and BKI_LOOKUP_OPT.

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_range_rngmultitypid_index  ,
2228  ,
RangeMultirangeTypidIndexId  ,
pg_range  ,
btree(rngmultitypid oid_ops)   
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_range_rngtypid_index  ,
3542  ,
RangeTypidIndexId  ,
pg_range  ,
btree(rngtypid oid_ops)   
)

◆ MAKE_SYSCACHE() [1/2]

MAKE_SYSCACHE ( RANGEMULTIRANGE  ,
pg_range_rngmultitypid_index  ,
 
)

◆ MAKE_SYSCACHE() [2/2]

MAKE_SYSCACHE ( RANGETYPE  ,
pg_range_rngtypid_index  ,
 
)

◆ RangeCreate()

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

Definition at line 36 of file pg_range.c.

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  ObjectAddress referencing;
47  ObjectAddresses *addrs;
48 
49  pg_range = table_open(RangeRelationId, RowExclusiveLock);
50 
51  memset(nulls, 0, sizeof(nulls));
52 
53  values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
54  values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
55  values[Anum_pg_range_rngcollation - 1] = ObjectIdGetDatum(rangeCollation);
56  values[Anum_pg_range_rngsubopc - 1] = ObjectIdGetDatum(rangeSubOpclass);
57  values[Anum_pg_range_rngcanonical - 1] = ObjectIdGetDatum(rangeCanonical);
58  values[Anum_pg_range_rngsubdiff - 1] = ObjectIdGetDatum(rangeSubDiff);
59  values[Anum_pg_range_rngmultitypid - 1] = ObjectIdGetDatum(multirangeTypeOid);
60 
61  tup = heap_form_tuple(RelationGetDescr(pg_range), values, nulls);
62 
63  CatalogTupleInsert(pg_range, tup);
64  heap_freetuple(tup);
65 
66  /* record type's dependencies on range-related items */
67  addrs = new_object_addresses();
68 
69  ObjectAddressSet(myself, TypeRelationId, rangeTypeOid);
70 
71  ObjectAddressSet(referenced, TypeRelationId, rangeSubType);
72  add_exact_object_address(&referenced, addrs);
73 
74  ObjectAddressSet(referenced, OperatorClassRelationId, rangeSubOpclass);
75  add_exact_object_address(&referenced, addrs);
76 
77  if (OidIsValid(rangeCollation))
78  {
79  ObjectAddressSet(referenced, CollationRelationId, rangeCollation);
80  add_exact_object_address(&referenced, addrs);
81  }
82 
83  if (OidIsValid(rangeCanonical))
84  {
85  ObjectAddressSet(referenced, ProcedureRelationId, rangeCanonical);
86  add_exact_object_address(&referenced, addrs);
87  }
88 
89  if (OidIsValid(rangeSubDiff))
90  {
91  ObjectAddressSet(referenced, ProcedureRelationId, rangeSubDiff);
92  add_exact_object_address(&referenced, addrs);
93  }
94 
96  free_object_addresses(addrs);
97 
98  /* record multirange type's dependency on the range type */
99  referencing.classId = TypeRelationId;
100  referencing.objectId = multirangeTypeOid;
101  referencing.objectSubId = 0;
102  recordDependencyOn(&referencing, &myself, DEPENDENCY_INTERNAL);
103 
104  table_close(pg_range, RowExclusiveLock);
105 }
static Datum values[MAXATTR]
Definition: bootstrap.c:152
#define OidIsValid(objectId)
Definition: c.h:775
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2740
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2485
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2531
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2771
@ DEPENDENCY_INTERNAL
Definition: dependency.h:35
@ DEPENDENCY_NORMAL
Definition: dependency.h:33
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1434
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
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 add_exact_object_address(), CatalogTupleInsert(), ObjectAddress::classId, DEPENDENCY_INTERNAL, DEPENDENCY_NORMAL, free_object_addresses(), heap_form_tuple(), heap_freetuple(), new_object_addresses(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, record_object_address_dependencies(), recordDependencyOn(), RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.

Referenced by DefineRange().

◆ RangeDelete()

void RangeDelete ( Oid  rangeTypeOid)

Definition at line 113 of file pg_range.c.

114 {
115  Relation pg_range;
116  ScanKeyData key[1];
117  SysScanDesc scan;
118  HeapTuple tup;
119 
120  pg_range = table_open(RangeRelationId, RowExclusiveLock);
121 
122  ScanKeyInit(&key[0],
123  Anum_pg_range_rngtypid,
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  table_close(pg_range, RowExclusiveLock);
138 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:596
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:503
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:384
#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(), HeapTupleIsValid, sort-test::key, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by RemoveTypeById().

Variable Documentation

◆ FormData_pg_range

FormData_pg_range

Definition at line 51 of file pg_range.h.