1
#include "btree_gist.h"
2
#include "btree_utils_num.h"
3
#include "utils/cash.h"
14
PG_FUNCTION_INFO_V1(gbt_cash_compress);
15
PG_FUNCTION_INFO_V1(gbt_cash_union);
16
PG_FUNCTION_INFO_V1(gbt_cash_picksplit);
17
PG_FUNCTION_INFO_V1(gbt_cash_consistent);
18
PG_FUNCTION_INFO_V1(gbt_cash_penalty);
19
PG_FUNCTION_INFO_V1(gbt_cash_same);
21
Datum gbt_cash_compress(PG_FUNCTION_ARGS);
22
Datum gbt_cash_union(PG_FUNCTION_ARGS);
23
Datum gbt_cash_picksplit(PG_FUNCTION_ARGS);
24
Datum gbt_cash_consistent(PG_FUNCTION_ARGS);
25
Datum gbt_cash_penalty(PG_FUNCTION_ARGS);
26
Datum gbt_cash_same(PG_FUNCTION_ARGS);
29
gbt_cashgt(const void *a, const void *b)
31
return (*((Cash *) a) > *((Cash *) b));
34
gbt_cashge(const void *a, const void *b)
36
return (*((Cash *) a) >= *((Cash *) b));
39
gbt_casheq(const void *a, const void *b)
41
return (*((Cash *) a) == *((Cash *) b));
44
gbt_cashle(const void *a, const void *b)
46
return (*((Cash *) a) <= *((Cash *) b));
49
gbt_cashlt(const void *a, const void *b)
51
return (*((Cash *) a) < *((Cash *) b));
55
gbt_cashkey_cmp(const void *a, const void *b)
58
if (*(Cash *) &(((Nsrt *) a)->t[0]) > *(Cash *) &(((Nsrt *) b)->t[0]))
60
else if (*(Cash *) &(((Nsrt *) a)->t[0]) < *(Cash *) &(((Nsrt *) b)->t[0]))
67
static const gbtree_ninfo tinfo =
80
/**************************************************
82
**************************************************/
86
gbt_cash_compress(PG_FUNCTION_ARGS)
88
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
89
GISTENTRY *retval = NULL;
91
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
96
gbt_cash_consistent(PG_FUNCTION_ARGS)
98
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
99
Cash query = (*((Cash *) PG_GETARG_POINTER(1)));
100
cashKEY *kkk = (cashKEY *) DatumGetPointer(entry->key);
102
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
104
key.lower = (GBT_NUMKEY *) & kkk->lower;
105
key.upper = (GBT_NUMKEY *) & kkk->upper;
108
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
114
gbt_cash_union(PG_FUNCTION_ARGS)
116
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
117
void *out = palloc(sizeof(cashKEY));
119
*(int *) PG_GETARG_POINTER(1) = sizeof(cashKEY);
120
PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
125
gbt_cash_penalty(PG_FUNCTION_ARGS)
127
cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
128
cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
129
float *result = (float *) PG_GETARG_POINTER(2);
135
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
140
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
141
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
144
PG_RETURN_POINTER(result);
149
gbt_cash_picksplit(PG_FUNCTION_ARGS)
151
PG_RETURN_POINTER(gbt_num_picksplit(
152
(GistEntryVector *) PG_GETARG_POINTER(0),
153
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
159
gbt_cash_same(PG_FUNCTION_ARGS)
161
cashKEY *b1 = (cashKEY *) PG_GETARG_POINTER(0);
162
cashKEY *b2 = (cashKEY *) PG_GETARG_POINTER(1);
163
bool *result = (bool *) PG_GETARG_POINTER(2);
165
*result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
166
PG_RETURN_POINTER(result);