| 1 |
/* |
| 2 |
* contrib/btree_gist/btree_utils_var.h |
| 3 |
*/ |
| 4 |
#ifndef __BTREE_UTILS_VAR_H__ |
| 5 |
#define __BTREE_UTILS_VAR_H__ |
| 6 |
|
| 7 |
#include "access/gist.h" |
| 8 |
#include "btree_gist.h" |
| 9 |
|
| 10 |
/* Variable length key */ |
| 11 |
typedef bytea GBT_VARKEY; |
| 12 |
|
| 13 |
/* Better readable key */ |
| 14 |
typedef struct |
| 15 |
{ |
| 16 |
bytea *lower, |
| 17 |
*upper; |
| 18 |
} GBT_VARKEY_R; |
| 19 |
|
| 20 |
/* |
| 21 |
* type description |
| 22 |
*/ |
| 23 |
typedef struct |
| 24 |
{ |
| 25 |
|
| 26 |
/* Attribs */ |
| 27 |
|
| 28 |
enum gbtree_type t; /* data type */ |
| 29 |
int32 eml; /* cached pg_database_encoding_max_length (0: |
| 30 |
* undefined) */ |
| 31 |
bool trnc; /* truncate (=compress) key */ |
| 32 |
|
| 33 |
/* Methods */ |
| 34 |
|
| 35 |
bool (*f_gt) (const void *, const void *, Oid, FmgrInfo *); /* greater than */ |
| 36 |
bool (*f_ge) (const void *, const void *, Oid, FmgrInfo *); /* greater equal */ |
| 37 |
bool (*f_eq) (const void *, const void *, Oid, FmgrInfo *); /* equal */ |
| 38 |
bool (*f_le) (const void *, const void *, Oid, FmgrInfo *); /* less equal */ |
| 39 |
bool (*f_lt) (const void *, const void *, Oid, FmgrInfo *); /* less than */ |
| 40 |
int32 (*f_cmp) (const void *, const void *, Oid, FmgrInfo *); /* compare */ |
| 41 |
GBT_VARKEY *(*f_l2n) (GBT_VARKEY *, FmgrInfo *flinfo); /* convert leaf to node */ |
| 42 |
} gbtree_vinfo; |
| 43 |
|
| 44 |
/* |
| 45 |
* Free ptr1 in case its a copy of ptr2. |
| 46 |
* |
| 47 |
* This is adapted from varlena's PG_FREE_IF_COPY, though doesn't require |
| 48 |
* fcinfo access. |
| 49 |
*/ |
| 50 |
#define GBT_FREE_IF_COPY(ptr1, ptr2) \ |
| 51 |
do { \ |
| 52 |
if ((Pointer) (ptr1) != DatumGetPointer(ptr2)) \ |
| 53 |
pfree(ptr1); \ |
| 54 |
} while (0) |
| 55 |
|
| 56 |
extern GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k); |
| 57 |
|
| 58 |
extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R *u); |
| 59 |
|
| 60 |
extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo); |
| 61 |
|
| 62 |
extern GBT_VARKEY *gbt_var_union(const GistEntryVector *entryvec, int32 *size, |
| 63 |
Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo); |
| 64 |
|
| 65 |
extern bool gbt_var_same(Datum d1, Datum d2, Oid collation, |
| 66 |
const gbtree_vinfo *tinfo, FmgrInfo *flinfo); |
| 67 |
|
| 68 |
extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, |
| 69 |
Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo); |
| 70 |
|
| 71 |
extern bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, |
| 72 |
StrategyNumber strategy, Oid collation, bool is_leaf, |
| 73 |
const gbtree_vinfo *tinfo, FmgrInfo *flinfo); |
| 74 |
|
| 75 |
extern GIST_SPLITVEC *gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, |
| 76 |
Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo); |
| 77 |
|
| 78 |
extern void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, |
| 79 |
const gbtree_vinfo *tinfo, FmgrInfo *flinfo); |
| 80 |
|
| 81 |
#endif |