PostgreSQL Source Code git master
Loading...
Searching...
No Matches
btree_utils_var.h
Go to the documentation of this file.
1/*
2 * contrib/btree_gist/btree_utils_var.h
3 *
4 * Declarations for btree_gist code working with varlena indexed data types.
5 */
6#ifndef __BTREE_UTILS_VAR_H__
7#define __BTREE_UTILS_VAR_H__
8
9#include "access/gist.h"
10#include "btree_gist.h"
11
12/*
13 * An internal index key (also called a node in some places) includes a
14 * lower and an upper bound, both of which are varlena datums, packed into
15 * a wrapper varlena datum. We also work with leaf keys, which contain a
16 * single varlena datum wrapped in another varlena; this case can be
17 * distinguished by noting that the wrapper isn't long enough to hold a
18 * second datum. For simplicity we consider the wrapper to be a bytea.
19 */
21
22/*
23 * To actually work on a key, we use this more readable struct containing
24 * pointers directly to the lower and upper values. gbt_var_key_readable()
25 * and gbt_var_key_copy() convert between these two representations.
26 */
27typedef struct
28{
32
33/*
34 * type description
35 *
36 * For types that set the "trnc" flag, the representation of keys on internal
37 * pages may be different from that of keys on leaf pages (which match the
38 * data type's normal representation). The methods f_gt, f_ge, f_eq, f_le,
39 * f_lt expect to work on the normal representation, and therefore can be used
40 * only with leaf-page index entries. The f_cmp method expects to work on the
41 * representation used on internal pages, so it must not be used with leaf
42 * entries. The f_l2n method converts the leaf-page representation to the
43 * internal-page representation; if that pointer is NULL, they're the same.
44 *
45 * Currently, btree_utils_var.c effectively assumes that internal-page keys
46 * of "trnc" types are equivalent to bytea in representation and semantics.
47 * The truncation process shortens the lower+upper bounds of a downlink node
48 * to be of length equal to their common prefix's length plus one byte.
49 * This would not work for types with comparison semantics more complex than
50 * bytewise comparison. Even then, we need a hack to deal with the fact that
51 * shortening the upper bound would normally lead to its being considered less
52 * than the original maximum leaf-page entry. We handle that by considering
53 * any search key that matches the bound for the bound's full length to be a
54 * potential match, even if it's longer (see gbt_var_node_pf_match and its
55 * callers).
56 */
57typedef struct
58{
59
60 /* Attribs */
61
62 enum gbtree_type t; /* data type */
63 bool trnc; /* truncate (=compress) key */
64
65 /* Methods */
66
67 bool (*f_gt) (const void *, const void *, Oid, FmgrInfo *); /* greater than */
68 bool (*f_ge) (const void *, const void *, Oid, FmgrInfo *); /* greater equal */
69 bool (*f_eq) (const void *, const void *, Oid, FmgrInfo *); /* equal */
70 bool (*f_le) (const void *, const void *, Oid, FmgrInfo *); /* less equal */
71 bool (*f_lt) (const void *, const void *, Oid, FmgrInfo *); /* less than */
72 int32 (*f_cmp) (const void *, const void *, Oid, FmgrInfo *); /* compare */
73 GBT_VARKEY *(*f_l2n) (GBT_VARKEY *, FmgrInfo *flinfo); /* convert leaf to node */
75
76/*
77 * Free ptr1 in case it's a copy of ptr2.
78 *
79 * This is adapted from varlena's PG_FREE_IF_COPY, though doesn't require
80 * fcinfo access.
81 */
82#define GBT_FREE_IF_COPY(ptr1, ptr2) \
83 do { \
84 if ((ptr1) != DatumGetPointer(ptr2)) \
85 pfree(ptr1); \
86 } while (0)
87
89
91
93
95 Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
96
97extern bool gbt_var_same(Datum d1, Datum d2, Oid collation,
98 const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
99
100extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
101 Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
102
103extern bool gbt_var_consistent(const GBT_VARKEY_R *key, const void *query,
104 StrategyNumber strategy, Oid collation, bool is_leaf,
105 const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
106
108 Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
109
110extern void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
111 const gbtree_vinfo *tinfo, FmgrInfo *flinfo);
112
113#endif
static const gbtree_vinfo tinfo
Definition btree_bit.c:136
gbtree_type
Definition btree_gist.h:15
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
bool gbt_var_consistent(const GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
void gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
bytea GBT_VARKEY
int32_t int32
Definition c.h:679
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
e
static int fb(int x)
uint16 StrategyNumber
Definition stratnum.h:22
enum gbtree_type t
Definition c.h:835