PostgreSQL Source Code  git master
multirangetypes.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * multirangetypes.h
4  * Declarations for Postgres multirange types.
5  *
6  *
7  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/utils/multirangetypes.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef MULTIRANGETYPES_H
15 #define MULTIRANGETYPES_H
16 
17 #include "utils/rangetypes.h"
18 #include "utils/typcache.h"
19 
20 
21 /*
22  * Multiranges are varlena objects, so must meet the varlena convention that
23  * the first int32 of the object contains the total object size in bytes.
24  * Be sure to use VARSIZE() and SET_VARSIZE() to access it, though!
25  */
26 typedef struct
27 {
28  int32 vl_len_; /* varlena header (do not touch directly!) */
29  Oid multirangetypid; /* multirange type's own OID */
30  uint32 rangeCount; /* the number of ranges */
31 
32  /*
33  * Following the count are the range objects themselves, as ShortRangeType
34  * structs. Note that ranges are varlena too, depending on whether they
35  * have lower/upper bounds and because even their base types can be
36  * varlena. So we can't really index into this list.
37  */
39 
40 /* Use these macros in preference to accessing these fields directly */
41 #define MultirangeTypeGetOid(mr) ((mr)->multirangetypid)
42 #define MultirangeIsEmpty(mr) ((mr)->rangeCount == 0)
43 
44 /*
45  * fmgr functions for multirange type objects
46  */
47 static inline MultirangeType *
49 {
50  return (MultirangeType *) PG_DETOAST_DATUM(X);
51 }
52 
53 static inline MultirangeType *
55 {
57 }
58 
59 static inline Datum
61 {
62  return PointerGetDatum(X);
63 }
64 
65 #define PG_GETARG_MULTIRANGE_P(n) DatumGetMultirangeTypeP(PG_GETARG_DATUM(n))
66 #define PG_GETARG_MULTIRANGE_P_COPY(n) DatumGetMultirangeTypePCopy(PG_GETARG_DATUM(n))
67 #define PG_RETURN_MULTIRANGE_P(x) return MultirangeTypePGetDatum(x)
68 
69 /*
70  * prototypes for functions defined in multirangetypes.c
71  */
72 
73 /* internal versions of the above */
74 extern bool multirange_eq_internal(TypeCacheEntry *rangetyp,
75  const MultirangeType *mr1,
76  const MultirangeType *mr2);
77 extern bool multirange_ne_internal(TypeCacheEntry *rangetyp,
78  const MultirangeType *mr1,
79  const MultirangeType *mr2);
81  const MultirangeType *mr,
82  Datum val);
84  const MultirangeType *mr,
85  const RangeType *r);
87  const RangeType *r,
88  const MultirangeType *mr);
90  const MultirangeType *mr1,
91  const MultirangeType *mr2);
93  const RangeType *r,
94  const MultirangeType *mr);
96  const MultirangeType *mr1,
97  const MultirangeType *mr2);
99  const RangeType *r,
100  const MultirangeType *mr);
102  const RangeType *r,
103  const MultirangeType *mr);
105  const RangeType *r,
106  const MultirangeType *mr);
107 extern bool range_after_multirange_internal(TypeCacheEntry *rangetyp,
108  const RangeType *r,
109  const MultirangeType *mr);
111  const RangeType *r,
112  const MultirangeType *mr);
114  const MultirangeType *mr1,
115  const MultirangeType *mr2);
116 extern MultirangeType *multirange_minus_internal(Oid mltrngtypoid,
117  TypeCacheEntry *rangetyp,
118  int32 range_count1,
119  RangeType **ranges1,
120  int32 range_count2,
121  RangeType **ranges2);
123  TypeCacheEntry *rangetyp,
124  int32 range_count1,
125  RangeType **ranges1,
126  int32 range_count2,
127  RangeType **ranges2);
128 
129 /* assorted support functions */
131  Oid mltrngtypid);
132 extern void multirange_deserialize(TypeCacheEntry *rangetyp,
133  const MultirangeType *multirange,
134  int32 *range_count,
135  RangeType ***ranges);
136 extern MultirangeType *make_multirange(Oid mltrngtypoid,
137  TypeCacheEntry *rangetyp,
138  int32 range_count, RangeType **ranges);
139 extern MultirangeType *make_empty_multirange(Oid mltrngtypoid,
140  TypeCacheEntry *rangetyp);
141 extern void multirange_get_bounds(TypeCacheEntry *rangetyp,
142  const MultirangeType *multirange,
143  uint32 i,
146  const MultirangeType *multirange, int i);
148  const MultirangeType *mr);
149 
150 #endif /* MULTIRANGETYPES_H */
unsigned int uint32
Definition: c.h:509
signed int int32
Definition: c.h:497
#define PG_DETOAST_DATUM_COPY(datum)
Definition: fmgr.h:242
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
long val
Definition: informix.c:689
int i
Definition: isn.c:73
bool multirange_contains_elem_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr, Datum val)
TypeCacheEntry * multirange_get_typcache(FunctionCallInfo fcinfo, Oid mltrngtypid)
MultirangeType * multirange_minus_internal(Oid mltrngtypoid, TypeCacheEntry *rangetyp, int32 range_count1, RangeType **ranges1, int32 range_count2, RangeType **ranges2)
bool multirange_before_multirange_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr1, const MultirangeType *mr2)
MultirangeType * multirange_intersect_internal(Oid mltrngtypoid, TypeCacheEntry *rangetyp, int32 range_count1, RangeType **ranges1, int32 range_count2, RangeType **ranges2)
bool multirange_eq_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr1, const MultirangeType *mr2)
static Datum MultirangeTypePGetDatum(const MultirangeType *X)
bool multirange_contains_multirange_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr1, const MultirangeType *mr2)
void multirange_get_bounds(TypeCacheEntry *rangetyp, const MultirangeType *multirange, uint32 i, RangeBound *lower, RangeBound *upper)
static MultirangeType * DatumGetMultirangeTypeP(Datum X)
RangeType * multirange_get_range(TypeCacheEntry *rangetyp, const MultirangeType *multirange, int i)
MultirangeType * make_empty_multirange(Oid mltrngtypoid, TypeCacheEntry *rangetyp)
static MultirangeType * DatumGetMultirangeTypePCopy(Datum X)
MultirangeType * make_multirange(Oid mltrngtypoid, TypeCacheEntry *rangetyp, int32 range_count, RangeType **ranges)
bool range_adjacent_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
bool range_after_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
bool multirange_contains_range_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr, const RangeType *r)
bool multirange_overlaps_multirange_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr1, const MultirangeType *mr2)
void multirange_deserialize(TypeCacheEntry *rangetyp, const MultirangeType *multirange, int32 *range_count, RangeType ***ranges)
RangeType * multirange_get_union_range(TypeCacheEntry *rangetyp, const MultirangeType *mr)
bool range_before_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
bool range_overright_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
bool range_contains_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
bool multirange_ne_internal(TypeCacheEntry *rangetyp, const MultirangeType *mr1, const MultirangeType *mr2)
bool range_overlaps_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
bool range_overleft_multirange_internal(TypeCacheEntry *rangetyp, const RangeType *r, const MultirangeType *mr)
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:49
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:80
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31