PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree_utils_num.h
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_utils_num.h
3 */
4#ifndef __BTREE_UTILS_NUM_H__
5#define __BTREE_UTILS_NUM_H__
6
7#include <math.h>
8#include <float.h>
9
10#include "access/gist.h"
11#include "btree_gist.h"
12
13typedef char GBT_NUMKEY;
14
15/* Better readable key */
16typedef struct
17{
21
22
23/* for sorting */
24typedef struct
25{
26 int i;
28} Nsrt;
29
30
31/* type description */
32
33typedef struct
34{
35
36 /* Attribs */
37
38 enum gbtree_type t; /* data type */
39 int32 size; /* size of type, 0 means variable */
40 int32 indexsize; /* size of datums stored in index */
41
42 /* Methods */
43
44 bool (*f_gt) (const void *, const void *, FmgrInfo *); /* greater than */
45 bool (*f_ge) (const void *, const void *, FmgrInfo *); /* greater or equal */
46 bool (*f_eq) (const void *, const void *, FmgrInfo *); /* equal */
47 bool (*f_le) (const void *, const void *, FmgrInfo *); /* less or equal */
48 bool (*f_lt) (const void *, const void *, FmgrInfo *); /* less than */
49 int (*f_cmp) (const void *, const void *, FmgrInfo *); /* key compare function */
50 float8 (*f_dist) (const void *, const void *, FmgrInfo *); /* key distance function */
52
53
54/*
55 * Numeric btree functions
56 */
57
58
59
60/*
61 * Note: The factor 0.49 in following macro avoids floating point overflows
62 */
63#define penalty_num(result,olower,oupper,nlower,nupper) do { \
64 double tmp = 0.0F; \
65 (*(result)) = 0.0F; \
66 if ( (nupper) > (oupper) ) \
67 tmp += ( ((double)nupper)*0.49F - ((double)oupper)*0.49F ); \
68 if ( (olower) > (nlower) ) \
69 tmp += ( ((double)olower)*0.49F - ((double)nlower)*0.49F ); \
70 if (tmp > 0.0F) \
71 { \
72 (*(result)) += FLT_MIN; \
73 (*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
74 (*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
75 } \
76} while (0)
77
78
79/*
80 * Convert an Interval to an approximate equivalent number of seconds
81 * (as a double). Here because we need it for time/timetz as well as
82 * interval. See interval_cmp_internal for comparison.
83 */
84#define INTERVAL_TO_SEC(ivp) \
85 (((double) (ivp)->time) / ((double) USECS_PER_SEC) + \
86 (ivp)->day * (24.0 * SECS_PER_HOUR) + \
87 (ivp)->month * (30.0 * SECS_PER_DAY))
88
89#define GET_FLOAT_DISTANCE(t, arg1, arg2) fabs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
90
91
93
94extern bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query,
95 const StrategyNumber *strategy, bool is_leaf,
96 const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
97
98extern float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query,
99 bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
100
102 const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
103
105
106extern GISTENTRY *gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo);
107
108extern void *gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec,
109 const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
110
111extern bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b,
112 const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
113
114extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY *e,
115 const gbtree_ninfo *tinfo, FmgrInfo *flinfo);
116
117#endif
static const gbtree_vinfo tinfo
Definition: btree_bit.c:108
gbtree_type
Definition: btree_gist.h:15
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
void gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Interval * abs_interval(Interval *a)
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
char GBT_NUMKEY
double float8
Definition: c.h:584
int32_t int32
Definition: c.h:481
int b
Definition: isn.c:69
int a
Definition: isn.c:68
uintptr_t Datum
Definition: postgres.h:64
e
Definition: preproc-init.c:82
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: fmgr.h:57
const GBT_NUMKEY * upper
const GBT_NUMKEY * lower
GBT_NUMKEY * t
enum gbtree_type t