PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_bytea.c
Go to the documentation of this file.
1 /*
2  * contrib/btree_gist/btree_bytea.c
3  */
4 #include "postgres.h"
5 
6 #include "btree_gist.h"
7 #include "btree_utils_var.h"
8 #include "utils/builtins.h"
9 #include "utils/bytea.h"
10 
11 
12 /*
13 ** Bytea ops
14 */
21 
22 
23 /* define for comparison */
24 
25 static bool
26 gbt_byteagt(const void *a, const void *b, Oid collation)
27 {
29  PointerGetDatum(a),
30  PointerGetDatum(b)));
31 }
32 
33 static bool
34 gbt_byteage(const void *a, const void *b, Oid collation)
35 {
37  PointerGetDatum(a),
38  PointerGetDatum(b)));
39 }
40 
41 static bool
42 gbt_byteaeq(const void *a, const void *b, Oid collation)
43 {
45  PointerGetDatum(a),
46  PointerGetDatum(b)));
47 }
48 
49 static bool
50 gbt_byteale(const void *a, const void *b, Oid collation)
51 {
53  PointerGetDatum(a),
54  PointerGetDatum(b)));
55 }
56 
57 static bool
58 gbt_bytealt(const void *a, const void *b, Oid collation)
59 {
61  PointerGetDatum(a),
62  PointerGetDatum(b)));
63 }
64 
65 static int32
66 gbt_byteacmp(const void *a, const void *b, Oid collation)
67 {
69  PointerGetDatum(a),
70  PointerGetDatum(b)));
71 }
72 
73 
74 static const gbtree_vinfo tinfo =
75 {
77  0,
78  TRUE,
85  NULL
86 };
87 
88 
89 /**************************************************
90  * Text ops
91  **************************************************/
92 
93 
94 Datum
96 {
97  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
98 
99  PG_RETURN_POINTER(gbt_var_compress(entry, &tinfo));
100 }
101 
102 
103 
104 Datum
106 {
107  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
108  void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
110 
111  /* Oid subtype = PG_GETARG_OID(3); */
112  bool *recheck = (bool *) PG_GETARG_POINTER(4);
113  bool retval;
114  GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
116 
117  /* All cases served by this function are exact */
118  *recheck = false;
119 
120  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
121  GIST_LEAF(entry), &tinfo);
122  PG_RETURN_BOOL(retval);
123 }
124 
125 
126 
127 Datum
129 {
131  int32 *size = (int *) PG_GETARG_POINTER(1);
132 
134  &tinfo));
135 }
136 
137 
138 Datum
140 {
143 
144  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
145  &tinfo);
147 }
148 
149 Datum
151 {
152  Datum d1 = PG_GETARG_DATUM(0);
153  Datum d2 = PG_GETARG_DATUM(1);
154  bool *result = (bool *) PG_GETARG_POINTER(2);
155 
156  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
157  PG_RETURN_POINTER(result);
158 }
159 
160 
161 Datum
163 {
166  float *result = (float *) PG_GETARG_POINTER(2);
167 
169  &tinfo));
170 }
#define GIST_LEAF(entry)
Definition: gist.h:133
static int32 gbt_byteacmp(const void *a, const void *b, Oid collation)
Definition: btree_bytea.c:66
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
static const gbtree_vinfo tinfo
Definition: btree_bytea.c:74
Datum gbt_bytea_penalty(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:162
#define DatumGetInt32(X)
Definition: postgres.h:480
Datum byteagt(PG_FUNCTION_ARGS)
Definition: varlena.c:3456
#define PointerGetDatum(X)
Definition: postgres.h:564
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:224
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo)
uint16 StrategyNumber
Definition: stratnum.h:22
bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
unsigned int Oid
Definition: postgres_ext.h:31
Datum byteaeq(PG_FUNCTION_ARGS)
Definition: varlena.c:3352
#define PG_GET_COLLATION()
Definition: fmgr.h:155
static bool gbt_bytealt(const void *a, const void *b, Oid collation)
Definition: btree_bytea.c:58
signed int int32
Definition: c.h:253
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo)
Datum bytealt(PG_FUNCTION_ARGS)
Definition: varlena.c:3416
PG_FUNCTION_INFO_V1(gbt_bytea_compress)
static bool gbt_byteale(const void *a, const void *b, Oid collation)
Definition: btree_bytea.c:50
Datum byteage(PG_FUNCTION_ARGS)
Definition: varlena.c:3476
#define DatumGetByteaP(X)
Definition: fmgr.h:246
Datum key
Definition: gist.h:123
#define DatumGetBool(X)
Definition: postgres.h:401
Datum gbt_bytea_union(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:128
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo)
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
uintptr_t Datum
Definition: postgres.h:374
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
Datum gbt_bytea_same(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:150
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo)
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
Datum byteacmp(PG_FUNCTION_ARGS)
Definition: varlena.c:3496
Datum gbt_bytea_consistent(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:105
#define NULL
Definition: c.h:226
Datum gbt_bytea_picksplit(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:139
Datum gbt_bytea_compress(PG_FUNCTION_ARGS)
Definition: btree_bytea.c:95
static bool gbt_byteaeq(const void *a, const void *b, Oid collation)
Definition: btree_bytea.c:42
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:228
#define DatumGetPointer(X)
Definition: postgres.h:557
Definition: c.h:435
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
static bool gbt_byteage(const void *a, const void *b, Oid collation)
Definition: btree_bytea.c:34
#define TRUE
Definition: c.h:214
Datum byteale(PG_FUNCTION_ARGS)
Definition: varlena.c:3436
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
static bool gbt_byteagt(const void *a, const void *b, Oid collation)
Definition: btree_bytea.c:26