1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_range relation
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/catalog/pg_range.c
13 *-------------------------------------------------------------------------
17 #include "access/genam.h"
18 #include "access/htup_details.h"
19 #include "access/table.h"
20 #include "catalog/dependency.h"
21 #include "catalog/indexing.h"
22 #include "catalog/pg_collation.h"
23 #include "catalog/pg_opclass.h"
24 #include "catalog/pg_proc.h"
25 #include "catalog/pg_range.h"
26 #include "catalog/pg_type.h"
27 #include "utils/fmgroids.h"
28 #include "utils/rel.h"
33 * Create an entry in pg_range.
36 RangeCreate(Oid rangeTypeOid
, Oid rangeSubType
, Oid rangeCollation
,
37 Oid rangeSubOpclass
, RegProcedure rangeCanonical
,
38 RegProcedure rangeSubDiff
, Oid multirangeTypeOid
)
41 Datum values
[Natts_pg_range
];
42 bool nulls
[Natts_pg_range
];
45 ObjectAddress referenced
;
46 ObjectAddress referencing
;
47 ObjectAddresses
*addrs
;
49 pg_range
= table_open(RangeRelationId
, RowExclusiveLock
);
51 memset(nulls
, 0, sizeof(nulls
));
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
);
61 tup
= heap_form_tuple(RelationGetDescr(pg_range
), values
, nulls
);
63 CatalogTupleInsert(pg_range
, tup
);
66 /* record type's dependencies on range-related items */
67 addrs
= new_object_addresses();
69 ObjectAddressSet(myself
, TypeRelationId
, rangeTypeOid
);
71 ObjectAddressSet(referenced
, TypeRelationId
, rangeSubType
);
72 add_exact_object_address(&referenced
, addrs
);
74 ObjectAddressSet(referenced
, OperatorClassRelationId
, rangeSubOpclass
);
75 add_exact_object_address(&referenced
, addrs
);
77 if (OidIsValid(rangeCollation
))
79 ObjectAddressSet(referenced
, CollationRelationId
, rangeCollation
);
80 add_exact_object_address(&referenced
, addrs
);
83 if (OidIsValid(rangeCanonical
))
85 ObjectAddressSet(referenced
, ProcedureRelationId
, rangeCanonical
);
86 add_exact_object_address(&referenced
, addrs
);
89 if (OidIsValid(rangeSubDiff
))
91 ObjectAddressSet(referenced
, ProcedureRelationId
, rangeSubDiff
);
92 add_exact_object_address(&referenced
, addrs
);
95 record_object_address_dependencies(&myself
, addrs
, DEPENDENCY_NORMAL
);
96 free_object_addresses(addrs
);
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
);
104 table_close(pg_range
, RowExclusiveLock
);
110 * Remove the pg_range entry for the specified type.
113 RangeDelete(Oid rangeTypeOid
)
120 pg_range
= table_open(RangeRelationId
, RowExclusiveLock
);
123 Anum_pg_range_rngtypid
,
124 BTEqualStrategyNumber
, F_OIDEQ
,
125 ObjectIdGetDatum(rangeTypeOid
));
127 scan
= systable_beginscan(pg_range
, RangeTypidIndexId
, true,
130 while (HeapTupleIsValid(tup
= systable_getnext(scan
)))
132 CatalogTupleDelete(pg_range
, &tup
->t_self
);
135 systable_endscan(scan
);
137 table_close(pg_range
, RowExclusiveLock
);