PostgreSQL Source Code  git master
rangetypes.h File Reference
#include "utils/typcache.h"
Include dependency graph for rangetypes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RangeType
 
struct  RangeBound
 

Macros

#define RangeTypeGetOid(r)   ((r)->rangetypid)
 
#define RANGE_EMPTY   0x01 /* range is empty */
 
#define RANGE_LB_INC   0x02 /* lower bound is inclusive */
 
#define RANGE_UB_INC   0x04 /* upper bound is inclusive */
 
#define RANGE_LB_INF   0x08 /* lower bound is -infinity */
 
#define RANGE_UB_INF   0x10 /* upper bound is +infinity */
 
#define RANGE_LB_NULL   0x20 /* lower bound is null (NOT USED) */
 
#define RANGE_UB_NULL   0x40 /* upper bound is null (NOT USED) */
 
#define RANGE_CONTAIN_EMPTY
 
#define RANGE_HAS_LBOUND(flags)
 
#define RANGE_HAS_UBOUND(flags)
 
#define RangeIsEmpty(r)   ((range_get_flags(r) & RANGE_EMPTY) != 0)
 
#define RangeIsOrContainsEmpty(r)   ((range_get_flags(r) & (RANGE_EMPTY | RANGE_CONTAIN_EMPTY)) != 0)
 
#define DatumGetRangeTypeP(X)   ((RangeType *) PG_DETOAST_DATUM(X))
 
#define DatumGetRangeTypePCopy(X)   ((RangeType *) PG_DETOAST_DATUM_COPY(X))
 
#define RangeTypePGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_RANGE_P(n)   DatumGetRangeTypeP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_RANGE_P_COPY(n)   DatumGetRangeTypePCopy(PG_GETARG_DATUM(n))
 
#define PG_RETURN_RANGE_P(x)   return RangeTypePGetDatum(x)
 
#define RANGESTRAT_BEFORE   RTLeftStrategyNumber
 
#define RANGESTRAT_OVERLEFT   RTOverLeftStrategyNumber
 
#define RANGESTRAT_OVERLAPS   RTOverlapStrategyNumber
 
#define RANGESTRAT_OVERRIGHT   RTOverRightStrategyNumber
 
#define RANGESTRAT_AFTER   RTRightStrategyNumber
 
#define RANGESTRAT_ADJACENT   RTSameStrategyNumber
 
#define RANGESTRAT_CONTAINS   RTContainsStrategyNumber
 
#define RANGESTRAT_CONTAINED_BY   RTContainedByStrategyNumber
 
#define RANGESTRAT_CONTAINS_ELEM   RTContainsElemStrategyNumber
 
#define RANGESTRAT_EQ   RTEqualStrategyNumber
 

Functions

bool range_contains_elem_internal (TypeCacheEntry *typcache, RangeType *r, Datum val)
 
bool range_eq_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_ne_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_contains_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_contained_by_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_before_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_after_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_adjacent_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_overlaps_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_overleft_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
bool range_overright_internal (TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
 
TypeCacheEntryrange_get_typcache (FunctionCallInfo fcinfo, Oid rngtypid)
 
RangeTyperange_serialize (TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
 
void range_deserialize (TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
 
char range_get_flags (RangeType *range)
 
void range_set_contain_empty (RangeType *range)
 
RangeTypemake_range (TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
 
int range_cmp_bounds (TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
 
int range_cmp_bound_values (TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
 
bool bounds_adjacent (TypeCacheEntry *typcache, RangeBound bound1, RangeBound bound2)
 
RangeTypemake_empty_range (TypeCacheEntry *typcache)
 

Macro Definition Documentation

◆ DatumGetRangeTypeP

◆ DatumGetRangeTypePCopy

#define DatumGetRangeTypePCopy (   X)    ((RangeType *) PG_DETOAST_DATUM_COPY(X))

Definition at line 72 of file rangetypes.h.

◆ PG_GETARG_RANGE_P

◆ PG_GETARG_RANGE_P_COPY

#define PG_GETARG_RANGE_P_COPY (   n)    DatumGetRangeTypePCopy(PG_GETARG_DATUM(n))

Definition at line 75 of file rangetypes.h.

◆ PG_RETURN_RANGE_P

◆ RANGE_CONTAIN_EMPTY

#define RANGE_CONTAIN_EMPTY
Value:
0x80 /* marks a GiST internal-page entry whose
* subtree contains some empty ranges */

Definition at line 43 of file rangetypes.h.

Referenced by get_gist_range_class(), range_set_contain_empty(), and range_super_union().

◆ RANGE_EMPTY

#define RANGE_EMPTY   0x01 /* range is empty */

◆ RANGE_HAS_LBOUND

#define RANGE_HAS_LBOUND (   flags)
Value:
(!((flags) & (RANGE_EMPTY | \
#define RANGE_EMPTY
Definition: rangetypes.h:36
#define RANGE_LB_INF
Definition: rangetypes.h:39
#define RANGE_LB_NULL
Definition: rangetypes.h:41

Definition at line 46 of file rangetypes.h.

Referenced by hash_range(), hash_range_extended(), range_deparse(), range_deserialize(), range_in(), range_out(), range_recv(), range_send(), and range_serialize().

◆ RANGE_HAS_UBOUND

#define RANGE_HAS_UBOUND (   flags)
Value:
(!((flags) & (RANGE_EMPTY | \
#define RANGE_EMPTY
Definition: rangetypes.h:36
#define RANGE_UB_NULL
Definition: rangetypes.h:42
#define RANGE_UB_INF
Definition: rangetypes.h:40

Definition at line 50 of file rangetypes.h.

Referenced by hash_range(), hash_range_extended(), range_deparse(), range_deserialize(), range_in(), range_out(), range_recv(), range_send(), and range_serialize().

◆ RANGE_LB_INC

#define RANGE_LB_INC   0x02 /* lower bound is inclusive */

◆ RANGE_LB_INF

#define RANGE_LB_INF   0x08 /* lower bound is -infinity */

◆ RANGE_LB_NULL

#define RANGE_LB_NULL   0x20 /* lower bound is null (NOT USED) */

Definition at line 41 of file rangetypes.h.

◆ RANGE_UB_INC

#define RANGE_UB_INC   0x04 /* upper bound is inclusive */

◆ RANGE_UB_INF

#define RANGE_UB_INF   0x10 /* upper bound is +infinity */

◆ RANGE_UB_NULL

#define RANGE_UB_NULL   0x40 /* upper bound is null (NOT USED) */

Definition at line 42 of file rangetypes.h.

◆ RangeIsEmpty

#define RangeIsEmpty (   r)    ((range_get_flags(r) & RANGE_EMPTY) != 0)

◆ RangeIsOrContainsEmpty

#define RangeIsOrContainsEmpty (   r)    ((range_get_flags(r) & (RANGE_EMPTY | RANGE_CONTAIN_EMPTY)) != 0)

Definition at line 55 of file rangetypes.h.

Referenced by range_gist_consistent_int(), and range_gist_penalty().

◆ RANGESTRAT_ADJACENT

◆ RANGESTRAT_AFTER

◆ RANGESTRAT_BEFORE

◆ RANGESTRAT_CONTAINED_BY

◆ RANGESTRAT_CONTAINS

◆ RANGESTRAT_CONTAINS_ELEM

◆ RANGESTRAT_EQ

◆ RANGESTRAT_OVERLAPS

◆ RANGESTRAT_OVERLEFT

◆ RANGESTRAT_OVERRIGHT

◆ RangeTypeGetOid

◆ RangeTypePGetDatum

Function Documentation

◆ bounds_adjacent()

bool bounds_adjacent ( TypeCacheEntry typcache,
RangeBound  bound1,
RangeBound  bound2 
)

Definition at line 741 of file rangetypes.c.

References Assert, cmp(), FmgrInfo::fn_oid, RangeBound::inclusive, RangeBound::lower, make_range(), OidIsValid, range_cmp_bound_values(), RangeIsEmpty, and TypeCacheEntry::rng_canonical_finfo.

Referenced by adjacent_cmp_bounds(), and range_adjacent_internal().

742 {
743  int cmp;
744 
745  Assert(!boundA.lower && boundB.lower);
746 
747  cmp = range_cmp_bound_values(typcache, &boundA, &boundB);
748  if (cmp < 0)
749  {
750  RangeType *r;
751 
752  /*
753  * Bounds do not overlap; see if there are points in between.
754  */
755 
756  /* in a continuous subtype, there are assumed to be points between */
757  if (!OidIsValid(typcache->rng_canonical_finfo.fn_oid))
758  return false;
759 
760  /*
761  * The bounds are of a discrete range type; so make a range A..B and
762  * see if it's empty.
763  */
764 
765  /* flip the inclusion flags */
766  boundA.inclusive = !boundA.inclusive;
767  boundB.inclusive = !boundB.inclusive;
768  /* change upper/lower labels to avoid Assert failures */
769  boundA.lower = true;
770  boundB.lower = false;
771  r = make_range(typcache, &boundA, &boundB, false);
772  return RangeIsEmpty(r);
773  }
774  else if (cmp == 0)
775  return boundA.inclusive != boundB.inclusive;
776  else
777  return false; /* bounds overlap */
778 }
RangeType * make_range(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
Definition: rangetypes.c:1795
#define RangeIsEmpty(r)
Definition: rangetypes.h:54
#define OidIsValid(objectId)
Definition: c.h:638
FmgrInfo rng_canonical_finfo
Definition: typcache.h:98
Oid fn_oid
Definition: fmgr.h:59
int range_cmp_bound_values(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1909
#define Assert(condition)
Definition: c.h:732
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ make_empty_range()

RangeType* make_empty_range ( TypeCacheEntry typcache)

Definition at line 1944 of file rangetypes.c.

References RangeBound::inclusive, RangeBound::infinite, lower(), RangeBound::lower, make_range(), upper(), and RangeBound::val.

Referenced by range_intersect(), and range_minus().

1945 {
1946  RangeBound lower;
1947  RangeBound upper;
1948 
1949  lower.val = (Datum) 0;
1950  lower.infinite = false;
1951  lower.inclusive = false;
1952  lower.lower = true;
1953 
1954  upper.val = (Datum) 0;
1955  upper.infinite = false;
1956  upper.inclusive = false;
1957  upper.lower = false;
1958 
1959  return make_range(typcache, &lower, &upper, true);
1960 }
RangeType * make_range(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
Definition: rangetypes.c:1795
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:44
Datum val
Definition: rangetypes.h:62
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:75
bool inclusive
Definition: rangetypes.h:64
bool lower
Definition: rangetypes.h:65
uintptr_t Datum
Definition: postgres.h:367
bool infinite
Definition: rangetypes.h:63

◆ make_range()

RangeType* make_range ( TypeCacheEntry typcache,
RangeBound lower,
RangeBound upper,
bool  empty 
)

Definition at line 1795 of file rangetypes.c.

References DatumGetRangeTypeP, FmgrInfo::fn_oid, FunctionCall1, OidIsValid, range(), range_serialize(), RangeIsEmpty, RangeTypePGetDatum, and TypeCacheEntry::rng_canonical_finfo.

Referenced by bounds_adjacent(), make_empty_range(), range_constructor2(), range_constructor3(), range_in(), range_intersect(), range_minus(), range_recv(), range_super_union(), and range_union_internal().

1797 {
1798  RangeType *range;
1799 
1800  range = range_serialize(typcache, lower, upper, empty);
1801 
1802  /* no need to call canonical on empty ranges ... */
1803  if (OidIsValid(typcache->rng_canonical_finfo.fn_oid) &&
1804  !RangeIsEmpty(range))
1806  RangeTypePGetDatum(range)));
1807 
1808  return range;
1809 }
#define RangeIsEmpty(r)
Definition: rangetypes.h:54
#define OidIsValid(objectId)
Definition: c.h:638
#define RangeTypePGetDatum(X)
Definition: rangetypes.h:73
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
Definition: regc_locale.c:416
RangeType * range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
Definition: rangetypes.c:1570
FmgrInfo rng_canonical_finfo
Definition: typcache.h:98
Oid fn_oid
Definition: fmgr.h:59
#define DatumGetRangeTypeP(X)
Definition: rangetypes.h:71
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:635

◆ range_adjacent_internal()

bool range_adjacent_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 782 of file rangetypes.c.

References bounds_adjacent(), elog, ERROR, range_deserialize(), and RangeTypeGetOid.

Referenced by range_adjacent(), range_gist_consistent_int(), range_gist_consistent_leaf(), range_union_internal(), and spg_range_quad_leaf_consistent().

783 {
784  RangeBound lower1,
785  lower2;
786  RangeBound upper1,
787  upper2;
788  bool empty1,
789  empty2;
790 
791  /* Different types should be prevented by ANYRANGE matching rules */
792  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
793  elog(ERROR, "range types do not match");
794 
795  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
796  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
797 
798  /* An empty range is not adjacent to any other range */
799  if (empty1 || empty2)
800  return false;
801 
802  /*
803  * Given two ranges A..B and C..D, the ranges are adjacent if and only if
804  * B is adjacent to C, or D is adjacent to A.
805  */
806  return (bounds_adjacent(typcache, upper1, lower2) ||
807  bounds_adjacent(typcache, upper2, lower1));
808 }
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
bool bounds_adjacent(TypeCacheEntry *typcache, RangeBound boundA, RangeBound boundB)
Definition: rangetypes.c:741
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_after_internal()

bool range_after_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 686 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_after(), range_gist_consistent_int(), range_gist_consistent_leaf(), and spg_range_quad_leaf_consistent().

687 {
688  RangeBound lower1,
689  lower2;
690  RangeBound upper1,
691  upper2;
692  bool empty1,
693  empty2;
694 
695  /* Different types should be prevented by ANYRANGE matching rules */
696  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
697  elog(ERROR, "range types do not match");
698 
699  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
700  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
701 
702  /* An empty range is neither before nor after any other range */
703  if (empty1 || empty2)
704  return false;
705 
706  return (range_cmp_bounds(typcache, &lower1, &upper2) > 0);
707 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_before_internal()

bool range_before_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 648 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_before(), range_gist_consistent_int(), range_gist_consistent_leaf(), and spg_range_quad_leaf_consistent().

649 {
650  RangeBound lower1,
651  lower2;
652  RangeBound upper1,
653  upper2;
654  bool empty1,
655  empty2;
656 
657  /* Different types should be prevented by ANYRANGE matching rules */
658  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
659  elog(ERROR, "range types do not match");
660 
661  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
662  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
663 
664  /* An empty range is neither before nor after any other range */
665  if (empty1 || empty2)
666  return false;
667 
668  return (range_cmp_bounds(typcache, &upper1, &lower2) < 0);
669 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_cmp_bound_values()

int range_cmp_bound_values ( TypeCacheEntry typcache,
RangeBound b1,
RangeBound b2 
)

Definition at line 1909 of file rangetypes.c.

References DatumGetInt32, FunctionCall2Coll(), RangeBound::infinite, RangeBound::lower, TypeCacheEntry::rng_cmp_proc_finfo, TypeCacheEntry::rng_collation, and RangeBound::val.

Referenced by bounds_adjacent(), and range_serialize().

1911 {
1912  /*
1913  * First, handle cases involving infinity, which don't require invoking
1914  * the comparison proc.
1915  */
1916  if (b1->infinite && b2->infinite)
1917  {
1918  /*
1919  * Both are infinity, so they are equal unless one is lower and the
1920  * other not.
1921  */
1922  if (b1->lower == b2->lower)
1923  return 0;
1924  else
1925  return b1->lower ? -1 : 1;
1926  }
1927  else if (b1->infinite)
1928  return b1->lower ? -1 : 1;
1929  else if (b2->infinite)
1930  return b2->lower ? 1 : -1;
1931 
1932  /*
1933  * Both boundaries are finite, so compare the held values.
1934  */
1936  typcache->rng_collation,
1937  b1->val, b2->val));
1938 }
FmgrInfo rng_cmp_proc_finfo
Definition: typcache.h:97
#define DatumGetInt32(X)
Definition: postgres.h:472
Datum val
Definition: rangetypes.h:62
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1150
bool lower
Definition: rangetypes.h:65
bool infinite
Definition: rangetypes.h:63
Oid rng_collation
Definition: typcache.h:96

◆ range_cmp_bounds()

int range_cmp_bounds ( TypeCacheEntry typcache,
RangeBound b1,
RangeBound b2 
)

Definition at line 1835 of file rangetypes.c.

References DatumGetInt32, FunctionCall2Coll(), RangeBound::inclusive, RangeBound::infinite, RangeBound::lower, TypeCacheEntry::rng_cmp_proc_finfo, TypeCacheEntry::rng_collation, and RangeBound::val.

Referenced by adjacent_cmp_bounds(), adjacent_inner_consistent(), bound_cmp(), calc_hist_selectivity_contained(), getQuadrant(), interval_cmp_lower(), interval_cmp_upper(), range_after_internal(), range_before_internal(), range_bound_qsort_cmp(), range_cmp(), range_contains_internal(), range_eq_internal(), range_gist_double_sorting_split(), range_gist_penalty(), range_intersect(), range_minus(), range_overlaps_internal(), range_overleft_internal(), range_overright_internal(), range_super_union(), range_union_internal(), rbound_bsearch(), single_bound_cmp(), and spg_range_quad_inner_consistent().

1836 {
1837  int32 result;
1838 
1839  /*
1840  * First, handle cases involving infinity, which don't require invoking
1841  * the comparison proc.
1842  */
1843  if (b1->infinite && b2->infinite)
1844  {
1845  /*
1846  * Both are infinity, so they are equal unless one is lower and the
1847  * other not.
1848  */
1849  if (b1->lower == b2->lower)
1850  return 0;
1851  else
1852  return b1->lower ? -1 : 1;
1853  }
1854  else if (b1->infinite)
1855  return b1->lower ? -1 : 1;
1856  else if (b2->infinite)
1857  return b2->lower ? 1 : -1;
1858 
1859  /*
1860  * Both boundaries are finite, so compare the held values.
1861  */
1863  typcache->rng_collation,
1864  b1->val, b2->val));
1865 
1866  /*
1867  * If the comparison is anything other than equal, we're done. If they
1868  * compare equal though, we still have to consider whether the boundaries
1869  * are inclusive or exclusive.
1870  */
1871  if (result == 0)
1872  {
1873  if (!b1->inclusive && !b2->inclusive)
1874  {
1875  /* both are exclusive */
1876  if (b1->lower == b2->lower)
1877  return 0;
1878  else
1879  return b1->lower ? 1 : -1;
1880  }
1881  else if (!b1->inclusive)
1882  return b1->lower ? 1 : -1;
1883  else if (!b2->inclusive)
1884  return b2->lower ? -1 : 1;
1885  else
1886  {
1887  /*
1888  * Both are inclusive and the values held are equal, so they are
1889  * equal regardless of whether they are upper or lower boundaries,
1890  * or a mix.
1891  */
1892  return 0;
1893  }
1894  }
1895 
1896  return result;
1897 }
FmgrInfo rng_cmp_proc_finfo
Definition: typcache.h:97
#define DatumGetInt32(X)
Definition: postgres.h:472
Datum val
Definition: rangetypes.h:62
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1150
signed int int32
Definition: c.h:346
bool inclusive
Definition: rangetypes.h:64
bool lower
Definition: rangetypes.h:65
bool infinite
Definition: rangetypes.h:63
Oid rng_collation
Definition: typcache.h:96

◆ range_contained_by_internal()

bool range_contained_by_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 2335 of file rangetypes.c.

References range_contains_internal().

Referenced by range_contained_by(), range_gist_consistent_leaf(), and spg_range_quad_leaf_consistent().

2336 {
2337  return range_contains_internal(typcache, r2, r1);
2338 }
bool range_contains_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
Definition: rangetypes.c:2303

◆ range_contains_elem_internal()

bool range_contains_elem_internal ( TypeCacheEntry typcache,
RangeType r,
Datum  val 
)

Definition at line 2344 of file rangetypes.c.

References cmp(), DatumGetInt32, FunctionCall2Coll(), RangeBound::inclusive, RangeBound::infinite, lower(), range_deserialize(), TypeCacheEntry::rng_cmp_proc_finfo, TypeCacheEntry::rng_collation, upper(), and RangeBound::val.

Referenced by elem_contained_by_range(), range_contains_elem(), range_gist_consistent_int(), range_gist_consistent_leaf(), and spg_range_quad_leaf_consistent().

2345 {
2346  RangeBound lower;
2347  RangeBound upper;
2348  bool empty;
2349  int32 cmp;
2350 
2351  range_deserialize(typcache, r, &lower, &upper, &empty);
2352 
2353  if (empty)
2354  return false;
2355 
2356  if (!lower.infinite)
2357  {
2359  typcache->rng_collation,
2360  lower.val, val));
2361  if (cmp > 0)
2362  return false;
2363  if (cmp == 0 && !lower.inclusive)
2364  return false;
2365  }
2366 
2367  if (!upper.infinite)
2368  {
2370  typcache->rng_collation,
2371  upper.val, val));
2372  if (cmp < 0)
2373  return false;
2374  if (cmp == 0 && !upper.inclusive)
2375  return false;
2376  }
2377 
2378  return true;
2379 }
FmgrInfo rng_cmp_proc_finfo
Definition: typcache.h:97
#define DatumGetInt32(X)
Definition: postgres.h:472
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:44
Datum val
Definition: rangetypes.h:62
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:75
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1150
signed int int32
Definition: c.h:346
bool inclusive
Definition: rangetypes.h:64
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
bool infinite
Definition: rangetypes.h:63
Oid rng_collation
Definition: typcache.h:96
long val
Definition: informix.c:684
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ range_contains_internal()

bool range_contains_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 2303 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_contained_by_internal(), range_contains(), range_gist_consistent_int(), range_gist_consistent_leaf(), and spg_range_quad_leaf_consistent().

2304 {
2305  RangeBound lower1;
2306  RangeBound upper1;
2307  bool empty1;
2308  RangeBound lower2;
2309  RangeBound upper2;
2310  bool empty2;
2311 
2312  /* Different types should be prevented by ANYRANGE matching rules */
2313  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
2314  elog(ERROR, "range types do not match");
2315 
2316  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
2317  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
2318 
2319  /* If either range is empty, the answer is easy */
2320  if (empty2)
2321  return true;
2322  else if (empty1)
2323  return false;
2324 
2325  /* Else we must have lower1 <= lower2 and upper1 >= upper2 */
2326  if (range_cmp_bounds(typcache, &lower1, &lower2) > 0)
2327  return false;
2328  if (range_cmp_bounds(typcache, &upper1, &upper2) < 0)
2329  return false;
2330 
2331  return true;
2332 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_deserialize()

void range_deserialize ( TypeCacheEntry typcache,
RangeType range,
RangeBound lower,
RangeBound upper,
bool empty 
)

Definition at line 1699 of file rangetypes.c.

References Assert, att_addlength_pointer, att_align_pointer, fetch_att, RangeBound::inclusive, RangeBound::infinite, RangeBound::lower, RANGE_EMPTY, RANGE_HAS_LBOUND, RANGE_HAS_UBOUND, RANGE_LB_INC, RANGE_LB_INF, RANGE_UB_INC, RANGE_UB_INF, RangeTypeGetOid, TypeCacheEntry::rngelemtype, TypeCacheEntry::typalign, typalign, TypeCacheEntry::typbyval, TypeCacheEntry::type_id, TypeCacheEntry::typlen, RangeBound::val, and VARSIZE.

Referenced by calc_hist_selectivity(), compute_range_stats(), daterange_canonical(), getQuadrant(), hash_range(), hash_range_extended(), int4range_canonical(), int8range_canonical(), range_adjacent_internal(), range_after_internal(), range_before_internal(), range_cmp(), range_contains_elem_internal(), range_contains_internal(), range_eq_internal(), range_gist_double_sorting_split(), range_gist_penalty(), range_gist_single_sorting_split(), range_intersect(), range_lower(), range_minus(), range_out(), range_overlaps_internal(), range_overleft_internal(), range_overright_internal(), range_send(), range_super_union(), range_union_internal(), range_upper(), spg_range_quad_inner_consistent(), and spg_range_quad_picksplit().

1701 {
1702  char flags;
1703  int16 typlen;
1704  bool typbyval;
1705  char typalign;
1706  Pointer ptr;
1707  Datum lbound;
1708  Datum ubound;
1709 
1710  /* assert caller passed the right typcache entry */
1711  Assert(RangeTypeGetOid(range) == typcache->type_id);
1712 
1713  /* fetch the flag byte from datum's last byte */
1714  flags = *((char *) range + VARSIZE(range) - 1);
1715 
1716  /* fetch information about range's element type */
1717  typlen = typcache->rngelemtype->typlen;
1718  typbyval = typcache->rngelemtype->typbyval;
1719  typalign = typcache->rngelemtype->typalign;
1720 
1721  /* initialize data pointer just after the range OID */
1722  ptr = (Pointer) (range + 1);
1723 
1724  /* fetch lower bound, if any */
1725  if (RANGE_HAS_LBOUND(flags))
1726  {
1727  /* att_align_pointer cannot be necessary here */
1728  lbound = fetch_att(ptr, typbyval, typlen);
1729  ptr = (Pointer) att_addlength_pointer(ptr, typlen, ptr);
1730  }
1731  else
1732  lbound = (Datum) 0;
1733 
1734  /* fetch upper bound, if any */
1735  if (RANGE_HAS_UBOUND(flags))
1736  {
1737  ptr = (Pointer) att_align_pointer(ptr, typalign, typlen, ptr);
1738  ubound = fetch_att(ptr, typbyval, typlen);
1739  /* no need for att_addlength_pointer */
1740  }
1741  else
1742  ubound = (Datum) 0;
1743 
1744  /* emit results */
1745 
1746  *empty = (flags & RANGE_EMPTY) != 0;
1747 
1748  lower->val = lbound;
1749  lower->infinite = (flags & RANGE_LB_INF) != 0;
1750  lower->inclusive = (flags & RANGE_LB_INC) != 0;
1751  lower->lower = true;
1752 
1753  upper->val = ubound;
1754  upper->infinite = (flags & RANGE_UB_INF) != 0;
1755  upper->inclusive = (flags & RANGE_UB_INC) != 0;
1756  upper->lower = false;
1757 }
#define RANGE_HAS_UBOUND(flags)
Definition: rangetypes.h:50
signed short int16
Definition: c.h:345
#define RANGE_HAS_LBOUND(flags)
Definition: rangetypes.h:46
#define RANGE_EMPTY
Definition: rangetypes.h:36
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define VARSIZE(PTR)
Definition: postgres.h:303
Datum val
Definition: rangetypes.h:62
int16 typlen
Definition: typcache.h:37
#define RANGE_LB_INF
Definition: rangetypes.h:39
bool typbyval
Definition: typcache.h:38
char * Pointer
Definition: c.h:335
char typalign
Definition: pg_type.h:170
bool inclusive
Definition: rangetypes.h:64
#define RANGE_UB_INC
Definition: rangetypes.h:38
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:174
bool lower
Definition: rangetypes.h:65
struct TypeCacheEntry * rngelemtype
Definition: typcache.h:95
uintptr_t Datum
Definition: postgres.h:367
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
Definition: tupmacs.h:124
#define RANGE_LB_INC
Definition: rangetypes.h:37
#define Assert(condition)
Definition: c.h:732
bool infinite
Definition: rangetypes.h:63
#define RANGE_UB_INF
Definition: rangetypes.h:40
char typalign
Definition: typcache.h:39
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:73

◆ range_eq_internal()

bool range_eq_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 557 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_eq(), range_gist_consistent_leaf(), range_gist_same(), range_ne_internal(), and spg_range_quad_leaf_consistent().

558 {
559  RangeBound lower1,
560  lower2;
561  RangeBound upper1,
562  upper2;
563  bool empty1,
564  empty2;
565 
566  /* Different types should be prevented by ANYRANGE matching rules */
567  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
568  elog(ERROR, "range types do not match");
569 
570  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
571  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
572 
573  if (empty1 && empty2)
574  return true;
575  if (empty1 != empty2)
576  return false;
577 
578  if (range_cmp_bounds(typcache, &lower1, &lower2) != 0)
579  return false;
580 
581  if (range_cmp_bounds(typcache, &upper1, &upper2) != 0)
582  return false;
583 
584  return true;
585 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_get_flags()

char range_get_flags ( RangeType range)

Definition at line 1766 of file rangetypes.c.

References VARSIZE.

Referenced by get_gist_range_class(), hash_range(), hash_range_extended(), range_empty(), range_gist_same(), range_lower_inc(), range_lower_inf(), range_out(), range_send(), range_super_union(), range_upper_inc(), and range_upper_inf().

1767 {
1768  /* fetch the flag byte from datum's last byte */
1769  return *((char *) range + VARSIZE(range) - 1);
1770 }
#define VARSIZE(PTR)
Definition: postgres.h:303

◆ range_get_typcache()

TypeCacheEntry* range_get_typcache ( FunctionCallInfo  fcinfo,
Oid  rngtypid 
)

Definition at line 1546 of file rangetypes.c.

References elog, ERROR, FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_extra, lookup_type_cache(), TypeCacheEntry::rngelemtype, RangeIOData::typcache, TypeCacheEntry::type_id, and TYPECACHE_RANGE_INFO.

Referenced by daterange_canonical(), elem_contained_by_range(), hash_range(), hash_range_extended(), int4range_canonical(), int8range_canonical(), range_adjacent(), range_after(), range_before(), range_cmp(), range_constructor2(), range_constructor3(), range_contained_by(), range_contains(), range_contains_elem(), range_eq(), range_gist_consistent(), range_gist_penalty(), range_gist_picksplit(), range_gist_same(), range_gist_union(), range_intersect(), range_lower(), range_merge(), range_minus(), range_ne(), range_overlaps(), range_overleft(), range_overright(), range_typanalyze(), range_union(), range_upper(), rangesel(), spg_range_quad_choose(), spg_range_quad_inner_consistent(), spg_range_quad_leaf_consistent(), and spg_range_quad_picksplit().

1547 {
1548  TypeCacheEntry *typcache = (TypeCacheEntry *) fcinfo->flinfo->fn_extra;
1549 
1550  if (typcache == NULL ||
1551  typcache->type_id != rngtypid)
1552  {
1553  typcache = lookup_type_cache(rngtypid, TYPECACHE_RANGE_INFO);
1554  if (typcache->rngelemtype == NULL)
1555  elog(ERROR, "type %u is not a range type", rngtypid);
1556  fcinfo->flinfo->fn_extra = (void *) typcache;
1557  }
1558 
1559  return typcache;
1560 }
#define TYPECACHE_RANGE_INFO
Definition: typcache.h:139
#define ERROR
Definition: elog.h:43
struct TypeCacheEntry * rngelemtype
Definition: typcache.h:95
FmgrInfo * flinfo
Definition: fmgr.h:87
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:322
void * fn_extra
Definition: fmgr.h:64
#define elog(elevel,...)
Definition: elog.h:226

◆ range_ne_internal()

bool range_ne_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 602 of file rangetypes.c.

References range_eq_internal().

Referenced by range_ne().

603 {
604  return (!range_eq_internal(typcache, r1, r2));
605 }
bool range_eq_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
Definition: rangetypes.c:557

◆ range_overlaps_internal()

bool range_overlaps_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 825 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_gist_consistent_int(), range_gist_consistent_leaf(), range_overlaps(), range_union_internal(), and spg_range_quad_leaf_consistent().

826 {
827  RangeBound lower1,
828  lower2;
829  RangeBound upper1,
830  upper2;
831  bool empty1,
832  empty2;
833 
834  /* Different types should be prevented by ANYRANGE matching rules */
835  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
836  elog(ERROR, "range types do not match");
837 
838  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
839  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
840 
841  /* An empty range does not overlap any other range */
842  if (empty1 || empty2)
843  return false;
844 
845  if (range_cmp_bounds(typcache, &lower1, &lower2) >= 0 &&
846  range_cmp_bounds(typcache, &lower1, &upper2) <= 0)
847  return true;
848 
849  if (range_cmp_bounds(typcache, &lower2, &lower1) >= 0 &&
850  range_cmp_bounds(typcache, &lower2, &upper1) <= 0)
851  return true;
852 
853  return false;
854 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_overleft_internal()

bool range_overleft_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 871 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_gist_consistent_int(), range_gist_consistent_leaf(), range_overleft(), and spg_range_quad_leaf_consistent().

872 {
873  RangeBound lower1,
874  lower2;
875  RangeBound upper1,
876  upper2;
877  bool empty1,
878  empty2;
879 
880  /* Different types should be prevented by ANYRANGE matching rules */
881  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
882  elog(ERROR, "range types do not match");
883 
884  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
885  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
886 
887  /* An empty range is neither before nor after any other range */
888  if (empty1 || empty2)
889  return false;
890 
891  if (range_cmp_bounds(typcache, &upper1, &upper2) <= 0)
892  return true;
893 
894  return false;
895 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_overright_internal()

bool range_overright_internal ( TypeCacheEntry typcache,
RangeType r1,
RangeType r2 
)

Definition at line 912 of file rangetypes.c.

References elog, ERROR, range_cmp_bounds(), range_deserialize(), and RangeTypeGetOid.

Referenced by range_gist_consistent_int(), range_gist_consistent_leaf(), range_overright(), and spg_range_quad_leaf_consistent().

913 {
914  RangeBound lower1,
915  lower2;
916  RangeBound upper1,
917  upper2;
918  bool empty1,
919  empty2;
920 
921  /* Different types should be prevented by ANYRANGE matching rules */
922  if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
923  elog(ERROR, "range types do not match");
924 
925  range_deserialize(typcache, r1, &lower1, &upper1, &empty1);
926  range_deserialize(typcache, r2, &lower2, &upper2, &empty2);
927 
928  /* An empty range is neither before nor after any other range */
929  if (empty1 || empty2)
930  return false;
931 
932  if (range_cmp_bounds(typcache, &lower1, &lower2) >= 0)
933  return true;
934 
935  return false;
936 }
int range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1835
#define RangeTypeGetOid(r)
Definition: rangetypes.h:33
#define ERROR
Definition: elog.h:43
void range_deserialize(TypeCacheEntry *typcache, RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Definition: rangetypes.c:1699
#define elog(elevel,...)
Definition: elog.h:226

◆ range_serialize()

RangeType* range_serialize ( TypeCacheEntry typcache,
RangeBound lower,
RangeBound upper,
bool  empty 
)

Definition at line 1570 of file rangetypes.c.

References Assert, cmp(), datum_compute_size(), datum_write(), ereport, errcode(), errmsg(), ERROR, RangeBound::inclusive, RangeBound::infinite, RangeBound::lower, MAXALIGN, palloc0(), PG_DETOAST_DATUM_PACKED, PointerGetDatum, range(), range_cmp_bound_values(), RANGE_EMPTY, RANGE_HAS_LBOUND, RANGE_HAS_UBOUND, RANGE_LB_INC, RANGE_LB_INF, RANGE_UB_INC, RANGE_UB_INF, RangeType::rangetypid, TypeCacheEntry::rngelemtype, SET_VARSIZE, TypeCacheEntry::typalign, typalign, TypeCacheEntry::typbyval, TypeCacheEntry::type_id, TypeCacheEntry::typlen, TypeCacheEntry::typstorage, and RangeBound::val.

Referenced by compute_range_stats(), daterange_canonical(), int4range_canonical(), int8range_canonical(), make_range(), rangesel(), and spg_range_quad_picksplit().

1572 {
1573  RangeType *range;
1574  int cmp;
1575  Size msize;
1576  Pointer ptr;
1577  int16 typlen;
1578  bool typbyval;
1579  char typalign;
1580  char typstorage;
1581  char flags = 0;
1582 
1583  /*
1584  * Verify range is not invalid on its face, and construct flags value,
1585  * preventing any non-canonical combinations such as infinite+inclusive.
1586  */
1587  Assert(lower->lower);
1588  Assert(!upper->lower);
1589 
1590  if (empty)
1591  flags |= RANGE_EMPTY;
1592  else
1593  {
1594  cmp = range_cmp_bound_values(typcache, lower, upper);
1595 
1596  /* error check: if lower bound value is above upper, it's wrong */
1597  if (cmp > 0)
1598  ereport(ERROR,
1599  (errcode(ERRCODE_DATA_EXCEPTION),
1600  errmsg("range lower bound must be less than or equal to range upper bound")));
1601 
1602  /* if bounds are equal, and not both inclusive, range is empty */
1603  if (cmp == 0 && !(lower->inclusive && upper->inclusive))
1604  flags |= RANGE_EMPTY;
1605  else
1606  {
1607  /* infinite boundaries are never inclusive */
1608  if (lower->infinite)
1609  flags |= RANGE_LB_INF;
1610  else if (lower->inclusive)
1611  flags |= RANGE_LB_INC;
1612  if (upper->infinite)
1613  flags |= RANGE_UB_INF;
1614  else if (upper->inclusive)
1615  flags |= RANGE_UB_INC;
1616  }
1617  }
1618 
1619  /* Fetch information about range's element type */
1620  typlen = typcache->rngelemtype->typlen;
1621  typbyval = typcache->rngelemtype->typbyval;
1622  typalign = typcache->rngelemtype->typalign;
1623  typstorage = typcache->rngelemtype->typstorage;
1624 
1625  /* Count space for varlena header and range type's OID */
1626  msize = sizeof(RangeType);
1627  Assert(msize == MAXALIGN(msize));
1628 
1629  /* Count space for bounds */
1630  if (RANGE_HAS_LBOUND(flags))
1631  {
1632  /*
1633  * Make sure item to be inserted is not toasted. It is essential that
1634  * we not insert an out-of-line toast value pointer into a range
1635  * object, for the same reasons that arrays and records can't contain
1636  * them. It would work to store a compressed-in-line value, but we
1637  * prefer to decompress and then let compression be applied to the
1638  * whole range object if necessary. But, unlike arrays, we do allow
1639  * short-header varlena objects to stay as-is.
1640  */
1641  if (typlen == -1)
1642  lower->val = PointerGetDatum(PG_DETOAST_DATUM_PACKED(lower->val));
1643 
1644  msize = datum_compute_size(msize, lower->val, typbyval, typalign,
1645  typlen, typstorage);
1646  }
1647 
1648  if (RANGE_HAS_UBOUND(flags))
1649  {
1650  /* Make sure item to be inserted is not toasted */
1651  if (typlen == -1)
1652  upper->val = PointerGetDatum(PG_DETOAST_DATUM_PACKED(upper->val));
1653 
1654  msize = datum_compute_size(msize, upper->val, typbyval, typalign,
1655  typlen, typstorage);
1656  }
1657 
1658  /* Add space for flag byte */
1659  msize += sizeof(char);
1660 
1661  /* Note: zero-fill is required here, just as in heap tuples */
1662  range = (RangeType *) palloc0(msize);
1663  SET_VARSIZE(range, msize);
1664 
1665  /* Now fill in the datum */
1666  range->rangetypid = typcache->type_id;
1667 
1668  ptr = (char *) (range + 1);
1669 
1670  if (RANGE_HAS_LBOUND(flags))
1671  {
1672  Assert(lower->lower);
1673  ptr = datum_write(ptr, lower->val, typbyval, typalign, typlen,
1674  typstorage);
1675  }
1676 
1677  if (RANGE_HAS_UBOUND(flags))
1678  {
1679  Assert(!upper->lower);
1680  ptr = datum_write(ptr, upper->val, typbyval, typalign, typlen,
1681  typstorage);
1682  }
1683 
1684  *((char *) ptr) = flags;
1685 
1686  return range;
1687 }
#define RANGE_HAS_UBOUND(flags)
Definition: rangetypes.h:50
signed short int16
Definition: c.h:345
#define RANGE_HAS_LBOUND(flags)
Definition: rangetypes.h:46
#define RANGE_EMPTY
Definition: rangetypes.h:36
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum val
Definition: rangetypes.h:62
int errcode(int sqlerrcode)
Definition: elog.c:570
int16 typlen
Definition: typcache.h:37
#define RANGE_LB_INF
Definition: rangetypes.h:39
bool typbyval
Definition: typcache.h:38
Oid rangetypid
Definition: rangetypes.h:28
char * Pointer
Definition: c.h:335
char typalign
Definition: pg_type.h:170
bool inclusive
Definition: rangetypes.h:64
#define ERROR
Definition: elog.h:43
#define PG_DETOAST_DATUM_PACKED(datum)
Definition: fmgr.h:243
static Size datum_compute_size(Size sz, Datum datum, bool typbyval, char typalign, int16 typlen, char typstorage)
Definition: rangetypes.c:2399
char typstorage
Definition: typcache.h:40
#define RANGE_UB_INC
Definition: rangetypes.h:38
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
Definition: regc_locale.c:416
#define ereport(elevel, rest)
Definition: elog.h:141
bool lower
Definition: rangetypes.h:65
struct TypeCacheEntry * rngelemtype
Definition: typcache.h:95
void * palloc0(Size size)
Definition: mcxt.c:980
static Pointer datum_write(Pointer ptr, Datum datum, bool typbyval, char typalign, int16 typlen, char typstorage)
Definition: rangetypes.c:2425
#define RANGE_LB_INC
Definition: rangetypes.h:37
int range_cmp_bound_values(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
Definition: rangetypes.c:1909
#define Assert(condition)
Definition: c.h:732
size_t Size
Definition: c.h:466
bool infinite
Definition: rangetypes.h:63
#define MAXALIGN(LEN)
Definition: c.h:685
#define RANGE_UB_INF
Definition: rangetypes.h:40
char typalign
Definition: typcache.h:39
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ range_set_contain_empty()

void range_set_contain_empty ( RangeType range)

Definition at line 1780 of file rangetypes.c.

References RANGE_CONTAIN_EMPTY, and VARSIZE.

Referenced by range_super_union().

1781 {
1782  char *flagsp;
1783 
1784  /* flag byte is datum's last byte */
1785  flagsp = (char *) range + VARSIZE(range) - 1;
1786 
1787  *flagsp |= RANGE_CONTAIN_EMPTY;
1788 }
#define VARSIZE(PTR)
Definition: postgres.h:303
#define RANGE_CONTAIN_EMPTY
Definition: rangetypes.h:43