2008-05-17 03:28:26 +02:00
|
|
|
/*
|
2010-09-20 22:08:53 +02:00
|
|
|
* contrib/btree_gist/btree_utils_num.h
|
2008-05-17 03:28:26 +02:00
|
|
|
*/
|
2006-07-10 23:03:58 +02:00
|
|
|
#ifndef __BTREE_UTILS_NUM_H__
|
|
|
|
#define __BTREE_UTILS_NUM_H__
|
|
|
|
|
2006-07-14 07:28:29 +02:00
|
|
|
#include "btree_gist.h"
|
2011-09-01 16:03:22 +02:00
|
|
|
#include "access/gist.h"
|
2008-06-19 02:46:06 +02:00
|
|
|
#include "utils/rel.h"
|
2006-07-14 07:28:29 +02:00
|
|
|
|
2006-07-13 18:57:31 +02:00
|
|
|
#include <math.h>
|
2006-07-14 06:44:46 +02:00
|
|
|
#include <float.h>
|
2006-07-13 18:57:31 +02:00
|
|
|
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
typedef char GBT_NUMKEY;
|
|
|
|
|
|
|
|
/* Better readable key */
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
const GBT_NUMKEY *lower,
|
|
|
|
*upper;
|
2009-06-11 16:49:15 +02:00
|
|
|
} GBT_NUMKEY_R;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* for sorting */
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
int i;
|
|
|
|
GBT_NUMKEY *t;
|
2009-06-11 16:49:15 +02:00
|
|
|
} Nsrt;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* type description */
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
/* Attribs */
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
enum gbtree_type t; /* data type */
|
2014-05-16 21:11:51 +02:00
|
|
|
int32 size; /* size of type, 0 means variable */
|
|
|
|
int32 indexsize; /* size of datums stored in index */
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
/* Methods */
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
bool (*f_gt) (const void *, const void *, FmgrInfo *); /* greater than */
|
|
|
|
bool (*f_ge) (const void *, const void *, FmgrInfo *); /* greater or equal */
|
|
|
|
bool (*f_eq) (const void *, const void *, FmgrInfo *); /* equal */
|
|
|
|
bool (*f_le) (const void *, const void *, FmgrInfo *); /* less or equal */
|
|
|
|
bool (*f_lt) (const void *, const void *, FmgrInfo *); /* less than */
|
|
|
|
int (*f_cmp) (const void *, const void *, FmgrInfo *); /* key compare function */
|
|
|
|
float8 (*f_dist) (const void *, const void *, FmgrInfo *); /* key distance function */
|
2009-06-11 16:49:15 +02:00
|
|
|
} gbtree_ninfo;
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-08-29 07:07:03 +02:00
|
|
|
* Numeric btree functions
|
2011-03-02 20:43:24 +01:00
|
|
|
*/
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2004-06-03 14:26:10 +02:00
|
|
|
|
2005-07-01 15:44:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: The factor 0.49 in following macro avoids floating point overflows
|
2011-03-02 20:43:24 +01:00
|
|
|
*/
|
2005-07-01 15:44:56 +02:00
|
|
|
#define penalty_num(result,olower,oupper,nlower,nupper) do { \
|
2005-10-15 04:49:52 +02:00
|
|
|
double tmp = 0.0F; \
|
|
|
|
(*(result)) = 0.0F; \
|
2004-06-03 14:26:10 +02:00
|
|
|
if ( (nupper) > (oupper) ) \
|
2005-07-01 15:44:56 +02:00
|
|
|
tmp += ( ((double)nupper)*0.49F - ((double)oupper)*0.49F ); \
|
2004-08-29 07:07:03 +02:00
|
|
|
if ( (olower) > (nlower) ) \
|
2005-07-01 15:44:56 +02:00
|
|
|
tmp += ( ((double)olower)*0.49F - ((double)nlower)*0.49F ); \
|
|
|
|
if (tmp > 0.0F) \
|
|
|
|
{ \
|
2005-10-15 04:49:52 +02:00
|
|
|
(*(result)) += FLT_MIN; \
|
|
|
|
(*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
|
|
|
|
(*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
|
2005-07-01 15:44:56 +02:00
|
|
|
} \
|
Get rid of trailing semicolons in C macro definitions.
Writing a trailing semicolon in a macro is almost never the right thing,
because you almost always want to write a semicolon after each macro
call instead. (Even if there was some reason to prefer not to, pgindent
would probably make a hash of code formatted that way; so within PG the
rule should basically be "don't do it".) Thus, if we have a semi inside
the macro, the compiler sees "something;;". Much of the time the extra
empty statement is harmless, but it could lead to mysterious syntax
errors at call sites. In perhaps an overabundance of neatnik-ism, let's
run around and get rid of the excess semicolons whereever possible.
The only thing worse than a mysterious syntax error is a mysterious
syntax error that only happens in the back branches; therefore,
backpatch these changes where relevant, which is most of them because
most of these mistakes are old. (The lack of reported problems shows
that this is largely a hypothetical issue, but still, it could bite
us in some future patch.)
John Naylor and Tom Lane
Discussion: https://postgr.es/m/CACPNZCs0qWTqJ2QUSGJ07B7uvAvzMb-KbG2q+oo+J3tsWN5cqw@mail.gmail.com
2020-05-01 23:28:01 +02:00
|
|
|
} while (0)
|
2004-06-03 14:26:10 +02:00
|
|
|
|
|
|
|
|
2005-07-21 06:15:04 +02:00
|
|
|
/*
|
|
|
|
* Convert an Interval to an approximate equivalent number of seconds
|
|
|
|
* (as a double). Here because we need it for time/timetz as well as
|
|
|
|
* interval. See interval_cmp_internal for comparison.
|
|
|
|
*/
|
|
|
|
#define INTERVAL_TO_SEC(ivp) \
|
|
|
|
(((double) (ivp)->time) / ((double) USECS_PER_SEC) + \
|
|
|
|
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
|
|
|
|
(ivp)->month * (30.0 * SECS_PER_DAY))
|
|
|
|
|
2011-03-02 20:43:24 +01:00
|
|
|
#define GET_FLOAT_DISTANCE(t, arg1, arg2) Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check to see if a float4/8 val has underflowed or overflowed
|
|
|
|
* borrowed from src/backend/utils/adt/float.c
|
|
|
|
*/
|
|
|
|
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid) \
|
|
|
|
do { \
|
|
|
|
if (isinf(val) && !(inf_is_valid)) \
|
|
|
|
ereport(ERROR, \
|
|
|
|
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), \
|
|
|
|
errmsg("value out of range: overflow"))); \
|
|
|
|
\
|
|
|
|
if ((val) == 0.0 && !(zero_is_valid)) \
|
|
|
|
ereport(ERROR, \
|
|
|
|
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), \
|
|
|
|
errmsg("value out of range: underflow"))); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
extern Interval *abs_interval(Interval *a);
|
2005-07-21 06:15:04 +02:00
|
|
|
|
2009-06-11 16:49:15 +02:00
|
|
|
extern bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query,
|
2004-08-29 07:07:03 +02:00
|
|
|
const StrategyNumber *strategy, bool is_leaf,
|
2017-03-21 14:12:46 +01:00
|
|
|
const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2011-03-02 20:43:24 +01:00
|
|
|
extern float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query,
|
2017-03-21 14:12:46 +01:00
|
|
|
bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
|
2011-03-02 20:43:24 +01:00
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
|
2017-03-21 14:12:46 +01:00
|
|
|
const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2015-03-26 22:10:10 +01:00
|
|
|
extern GISTENTRY *gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2015-03-27 22:35:16 +01:00
|
|
|
extern GISTENTRY *gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2009-06-11 16:49:15 +02:00
|
|
|
extern void *gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec,
|
2017-03-21 14:12:46 +01:00
|
|
|
const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2009-06-11 16:49:15 +02:00
|
|
|
extern bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b,
|
2017-03-21 14:12:46 +01:00
|
|
|
const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
|
New version. Add support for int2, int8, float4, float8, timestamp with/without time zone, time with/without time zone, date, interval, oid, money and macaddr, char, varchar/text, bytea, numeric, bit, varbit, inet/cidr types for GiST
2004-05-28 12:43:32 +02:00
|
|
|
|
2009-06-11 16:49:15 +02:00
|
|
|
extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY *e,
|
2017-03-21 14:12:46 +01:00
|
|
|
const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
|
2006-07-10 23:03:58 +02:00
|
|
|
|
|
|
|
#endif
|