Commit f1585362 authored by Tom Lane's avatar Tom Lane

Fix copyright notices, other minor editing in new range-types code.

No functional changes in this commit (except I could not resist the
temptation to re-word a couple of error messages).  This is just manual
cleanup after pgindent to make the code look reasonably like other PG
code, in preparation for more detailed code review to come.
parent 1a2586c1
......@@ -3,7 +3,8 @@
* pg_range.c
* routines to support manipulation of the pg_range relation
*
* Copyright (c) 2006-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
......@@ -22,10 +23,10 @@
#include "catalog/pg_proc.h"
#include "catalog/pg_range.h"
#include "catalog/pg_type.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/tqual.h"
#include "utils/rel.h"
#include "utils/tqual.h"
/*
* RangeCreate
......@@ -45,7 +46,7 @@ RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
pg_range = heap_open(RangeRelationId, RowExclusiveLock);
memset(nulls, 0, Natts_pg_range * sizeof(bool));
memset(nulls, 0, sizeof(nulls));
values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
......@@ -55,11 +56,12 @@ RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
values[Anum_pg_range_rngsubdiff - 1] = ObjectIdGetDatum(rangeSubDiff);
tup = heap_form_tuple(RelationGetDescr(pg_range), values, nulls);
simple_heap_insert(pg_range, tup);
CatalogUpdateIndexes(pg_range, tup);
heap_freetuple(tup);
/* record dependencies */
/* record type's dependencies on range-related items */
myself.classId = TypeRelationId;
myself.objectId = rangeTypeOid;
......@@ -105,7 +107,7 @@ RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
/*
* RangeDelete
* Remove the pg_range entry.
* Remove the pg_range entry for the specified type.
*/
void
RangeDelete(Oid rangeTypeOid)
......
This diff is collapsed.
......@@ -3,7 +3,8 @@
* rangetypes_gist.c
* GiST support for range types.
*
* Copyright (c) 2006-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
......@@ -20,6 +21,8 @@
#include "utils/lsyscache.h"
#include "utils/rangetypes.h"
/* Operator strategy numbers used in the GiST range opclass */
#define RANGESTRAT_EQ 1
#define RANGESTRAT_NE 2
#define RANGESTRAT_OVERLAPS 3
......@@ -33,16 +36,6 @@
#define RANGESTRAT_OVERRIGHT 11
#define RANGESTRAT_ADJACENT 12
static RangeType *range_super_union(FunctionCallInfo fcinfo, RangeType * r1,
RangeType * r2);
static bool range_gist_consistent_int(FunctionCallInfo fcinfo,
StrategyNumber strategy, RangeType * key,
RangeType * query);
static bool range_gist_consistent_leaf(FunctionCallInfo fcinfo,
StrategyNumber strategy, RangeType * key,
RangeType * query);
static int sort_item_cmp(const void *a, const void *b);
/*
* Auxiliary structure for picksplit method.
*/
......@@ -53,6 +46,16 @@ typedef struct
FunctionCallInfo fcinfo;
} PickSplitSortItem;
static RangeType *range_super_union(FunctionCallInfo fcinfo, RangeType * r1,
RangeType * r2);
static bool range_gist_consistent_int(FunctionCallInfo fcinfo,
StrategyNumber strategy, RangeType * key,
RangeType * query);
static bool range_gist_consistent_leaf(FunctionCallInfo fcinfo,
StrategyNumber strategy, RangeType * key,
RangeType * query);
static int sort_item_cmp(const void *a, const void *b);
Datum
range_gist_consistent(PG_FUNCTION_ARGS)
......@@ -60,12 +63,10 @@ range_gist_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Datum dquery = PG_GETARG_DATUM(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
RangeType *key = DatumGetRangeType(entry->key);
RangeType *query;
RangeBound lower;
RangeBound upper;
bool empty;
......@@ -77,9 +78,6 @@ range_gist_consistent(PG_FUNCTION_ARGS)
switch (strategy)
{
RangeBound lower;
RangeBound upper;
/*
* For contains and contained by operators, the other operand is a
* "point" of the subtype. Construct a singleton range containing
......@@ -97,8 +95,8 @@ range_gist_consistent(PG_FUNCTION_ARGS)
upper.val = dquery;
upper.lower = false;
upper.infinite = false;
query = DatumGetRangeType(
make_range(fcinfo, &lower, &upper, false));
query = DatumGetRangeType(make_range(fcinfo,
&lower, &upper, false));
break;
default:
......@@ -107,11 +105,11 @@ range_gist_consistent(PG_FUNCTION_ARGS)
}
if (GIST_LEAF(entry))
PG_RETURN_BOOL(range_gist_consistent_leaf(
fcinfo, strategy, key, query));
PG_RETURN_BOOL(range_gist_consistent_leaf(fcinfo, strategy,
key, query));
else
PG_RETURN_BOOL(range_gist_consistent_int(
fcinfo, strategy, key, query));
PG_RETURN_BOOL(range_gist_consistent_int(fcinfo, strategy,
key, query));
}
Datum
......@@ -157,22 +155,20 @@ range_gist_penalty(PG_FUNCTION_ARGS)
float *penalty = (float *) PG_GETARG_POINTER(2);
RangeType *orig = DatumGetRangeType(origentry->key);
RangeType *new = DatumGetRangeType(newentry->key);
RangeType *s_union = range_super_union(fcinfo, orig, new);
RangeType *s_union;
FmgrInfo *subtype_diff;
RangeBound lower1,
lower2;
RangeBound upper1,
upper2;
bool empty1,
empty2;
float lower_diff,
upper_diff;
RangeTypeInfo rngtypinfo;
s_union = range_super_union(fcinfo, orig, new);
range_deserialize(fcinfo, orig, &lower1, &upper1, &empty1);
range_deserialize(fcinfo, s_union, &lower2, &upper2, &empty2);
......@@ -371,23 +367,21 @@ range_super_union(FunctionCallInfo fcinfo, RangeType * r1, RangeType * r2)
if (result_lower == &lower2 && result_upper == &upper2)
return r2;
return DatumGetRangeType(
make_range(fcinfo, result_lower, result_upper, false));
return DatumGetRangeType(make_range(fcinfo, result_lower, result_upper,
false));
}
static bool
range_gist_consistent_int(FunctionCallInfo fcinfo, StrategyNumber strategy,
RangeType * key, RangeType * query)
{
Oid proc = InvalidOid;
Oid proc;
RangeBound lower1,
lower2;
RangeBound upper1,
upper2;
bool empty1,
empty2;
bool retval;
bool negate = false;
......@@ -440,13 +434,16 @@ range_gist_consistent_int(FunctionCallInfo fcinfo, StrategyNumber strategy,
case RANGESTRAT_ADJACENT:
if (empty1 || empty2)
return false;
if (DatumGetBool(
OidFunctionCall2(F_RANGE_ADJACENT,
if (DatumGetBool(OidFunctionCall2(F_RANGE_ADJACENT,
RangeTypeGetDatum(key),
RangeTypeGetDatum(query))))
return true;
proc = F_RANGE_OVERLAPS;
break;
default:
elog(ERROR, "unrecognized range strategy: %d", strategy);
proc = InvalidOid;
break;
}
retval = DatumGetBool(OidFunctionCall2(proc, RangeTypeGetDatum(key),
......@@ -462,8 +459,7 @@ static bool
range_gist_consistent_leaf(FunctionCallInfo fcinfo, StrategyNumber strategy,
RangeType * key, RangeType * query)
{
Oid proc = InvalidOid;
Oid proc;
RangeBound lower1,
lower2;
RangeBound upper1,
......@@ -518,6 +514,10 @@ range_gist_consistent_leaf(FunctionCallInfo fcinfo, StrategyNumber strategy,
return false;
proc = F_RANGE_ADJACENT;
break;
default:
elog(ERROR, "unrecognized range strategy: %d", strategy);
proc = InvalidOid;
break;
}
return DatumGetBool(OidFunctionCall2(proc, RangeTypeGetDatum(key),
......@@ -545,16 +545,13 @@ sort_item_cmp(const void *a, const void *b)
PickSplitSortItem *i2 = (PickSplitSortItem *) b;
RangeType *r1 = i1->data;
RangeType *r2 = i2->data;
RangeBound lower1,
lower2;
RangeBound upper1,
upper2;
bool empty1,
empty2;
FunctionCallInfo fcinfo = i1->fcinfo;
int cmp;
range_deserialize(fcinfo, r1, &lower1, &upper1, &empty1);
......
......@@ -5,7 +5,8 @@
* along with the relation's initial contents.
*
*
* Copyright (c) 2006-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/catalog/pg_range.h
*
......@@ -59,16 +60,6 @@ typedef FormData_pg_range *Form_pg_range;
#define Anum_pg_range_rngcanonical 5
#define Anum_pg_range_rngsubdiff 6
#define RANGE_DEFAULT_FLAGS "[)"
/*
* prototypes for functions in pg_range.c
*/
extern void RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
Oid rangeSubOpclass, RegProcedure rangeCanonical,
RegProcedure rangeSubDiff);
extern void RangeDelete(Oid rangeTypeOid);
/* ----------------
* initial contents of pg_range
......@@ -81,4 +72,14 @@ DATA(insert ( 3910 1184 0 10047 - tstzrange_subdiff));
DATA(insert ( 3912 1082 0 10019 daterange_canonical daterange_subdiff));
DATA(insert ( 3926 20 0 10029 int8range_canonical int8range_subdiff));
/*
* prototypes for functions in pg_range.c
*/
extern void RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
Oid rangeSubOpclass, RegProcedure rangeCanonical,
RegProcedure rangeSubDiff);
extern void RangeDelete(Oid rangeTypeOid);
#endif /* PG_RANGE_H */
......@@ -3,36 +3,46 @@
* rangetypes.h
* Declarations for Postgres range types.
*
*
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/utils/rangetypes.h
*
*-------------------------------------------------------------------------
*/
#ifndef RANGETYPES_H
#define RANGETYPES_H
#include "fmgr.h"
/* All ranges are represented as varlena objects */
typedef struct varlena RangeType;
/* Internal representation of either bound of a range (not what's on disk) */
typedef struct
{
Datum val;
Oid rngtypid;
bool infinite;
bool lower;
bool inclusive;
Datum val; /* the bound value, if any */
Oid rngtypid; /* OID of the range type itself */
bool infinite; /* bound is +/- infinity */
bool lower; /* this is the lower (vs upper) bound */
bool inclusive; /* bound is inclusive (vs exclusive) */
} RangeBound;
/* Standard runtime-cached data for a range type */
typedef struct
{
FmgrInfo canonicalFn;
FmgrInfo cmpFn;
FmgrInfo subdiffFn;
Oid rngtypid;
Oid subtype;
Oid collation;
int16 subtyplen;
char subtypalign;
char subtypstorage;
bool subtypbyval;
FmgrInfo canonicalFn; /* canonicalization function, if any */
FmgrInfo cmpFn; /* element type's btree comparison function */
FmgrInfo subdiffFn; /* element type difference function, if any */
Oid rngtypid; /* OID of the range type itself */
Oid subtype; /* OID of the element type */
Oid collation; /* collation for comparisons, if any */
int16 subtyplen; /* typlen of element type */
char subtypalign; /* typalign of element type */
char subtypstorage; /* typstorage of element type */
bool subtypbyval; /* typbyval of element type */
} RangeTypeInfo;
/*
......@@ -62,16 +72,6 @@ extern Datum range_constructor0(PG_FUNCTION_ARGS);
extern Datum range_constructor1(PG_FUNCTION_ARGS);
extern Datum range_constructor2(PG_FUNCTION_ARGS);
extern Datum range_constructor3(PG_FUNCTION_ARGS);
extern Datum range_make1(PG_FUNCTION_ARGS);
extern Datum range_linf_(PG_FUNCTION_ARGS);
extern Datum range_uinf_(PG_FUNCTION_ARGS);
extern Datum range_linfi(PG_FUNCTION_ARGS);
extern Datum range_uinfi(PG_FUNCTION_ARGS);
extern Datum range(PG_FUNCTION_ARGS);
extern Datum range__(PG_FUNCTION_ARGS);
extern Datum range_i(PG_FUNCTION_ARGS);
extern Datum rangei_(PG_FUNCTION_ARGS);
extern Datum rangeii(PG_FUNCTION_ARGS);
/* range -> subtype */
extern Datum range_lower(PG_FUNCTION_ARGS);
......@@ -84,7 +84,7 @@ extern Datum range_upper_inc(PG_FUNCTION_ARGS);
extern Datum range_lower_inf(PG_FUNCTION_ARGS);
extern Datum range_upper_inf(PG_FUNCTION_ARGS);
/* range, point -> bool */
/* range, element -> bool */
extern Datum range_contains_elem(PG_FUNCTION_ARGS);
extern Datum elem_contained_by_range(PG_FUNCTION_ARGS);
......@@ -115,45 +115,40 @@ extern Datum range_gt(PG_FUNCTION_ARGS);
/* Hash support */
extern Datum hash_range(PG_FUNCTION_ARGS);
/* GiST support (rangetypes_gist.c) */
extern Datum range_gist_consistent(PG_FUNCTION_ARGS);
extern Datum range_gist_compress(PG_FUNCTION_ARGS);
extern Datum range_gist_decompress(PG_FUNCTION_ARGS);
extern Datum range_gist_union(PG_FUNCTION_ARGS);
extern Datum range_gist_penalty(PG_FUNCTION_ARGS);
extern Datum range_gist_picksplit(PG_FUNCTION_ARGS);
extern Datum range_gist_same(PG_FUNCTION_ARGS);
/* Canonical functions */
Datum int4range_canonical(PG_FUNCTION_ARGS);
Datum int8range_canonical(PG_FUNCTION_ARGS);
Datum daterange_canonical(PG_FUNCTION_ARGS);
extern Datum int4range_canonical(PG_FUNCTION_ARGS);
extern Datum int8range_canonical(PG_FUNCTION_ARGS);
extern Datum daterange_canonical(PG_FUNCTION_ARGS);
/* Subtype Difference functions */
Datum int4range_subdiff(PG_FUNCTION_ARGS);
Datum int8range_subdiff(PG_FUNCTION_ARGS);
Datum numrange_subdiff(PG_FUNCTION_ARGS);
Datum daterange_subdiff(PG_FUNCTION_ARGS);
Datum tsrange_subdiff(PG_FUNCTION_ARGS);
Datum tstzrange_subdiff(PG_FUNCTION_ARGS);
/* for defining more generic functions */
extern Datum make_range(FunctionCallInfo fcinfo, RangeBound *lower,
extern Datum int4range_subdiff(PG_FUNCTION_ARGS);
extern Datum int8range_subdiff(PG_FUNCTION_ARGS);
extern Datum numrange_subdiff(PG_FUNCTION_ARGS);
extern Datum daterange_subdiff(PG_FUNCTION_ARGS);
extern Datum tsrange_subdiff(PG_FUNCTION_ARGS);
extern Datum tstzrange_subdiff(PG_FUNCTION_ARGS);
/* assorted support functions */
extern Datum range_serialize(FunctionCallInfo fcinfo, RangeBound *lower,
RangeBound *upper, bool empty);
extern void range_deserialize(FunctionCallInfo fcinfo, RangeType *range,
RangeBound *lower, RangeBound *upper,
bool *empty);
extern Datum make_range(FunctionCallInfo fcinfo, RangeBound *lower,
RangeBound *upper, bool empty);
extern int range_cmp_bounds(FunctionCallInfo fcinfo, RangeBound *b1,
RangeBound *b2);
extern RangeType *make_empty_range(FunctionCallInfo fcinfo, Oid rngtypid);
extern void range_gettypinfo(FunctionCallInfo fcinfo, Oid rngtypid,
RangeTypeInfo *rngtypinfo);
/* for defining a range "canonicalize" function */
extern Datum range_serialize(FunctionCallInfo fcinfo, RangeBound *lower,
RangeBound *upper, bool empty);
/* for use in DefineRange */
extern char range_parse_flags(char *flags_str);
/* GiST support (in rangetypes_gist.c) */
extern Datum range_gist_consistent(PG_FUNCTION_ARGS);
extern Datum range_gist_compress(PG_FUNCTION_ARGS);
extern Datum range_gist_decompress(PG_FUNCTION_ARGS);
extern Datum range_gist_union(PG_FUNCTION_ARGS);
extern Datum range_gist_penalty(PG_FUNCTION_ARGS);
extern Datum range_gist_picksplit(PG_FUNCTION_ARGS);
extern Datum range_gist_same(PG_FUNCTION_ARGS);
#endif /* RANGETYPES_H */
......@@ -345,7 +345,7 @@ select numrange(1.0, 2.0) + numrange(1.5, 3.0);
(1 row)
select numrange(1.0, 2.0) + numrange(2.5, 3.0);
ERROR: result range is not contiguous
ERROR: result of range union would not be contiguous
select numrange(1.0, 2.0) * numrange(2.0, 3.0);
?column?
----------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment