PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_bit.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_var.h"
#include "utils/builtins.h"
#include "utils/bytea.h"
#include "utils/varbit.h"
Include dependency graph for btree_bit.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (gbt_bit_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_union)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_bit_same)
 
static bool gbt_bitgt (const void *a, const void *b, Oid collation)
 
static bool gbt_bitge (const void *a, const void *b, Oid collation)
 
static bool gbt_biteq (const void *a, const void *b, Oid collation)
 
static bool gbt_bitle (const void *a, const void *b, Oid collation)
 
static bool gbt_bitlt (const void *a, const void *b, Oid collation)
 
static int32 gbt_bitcmp (const void *a, const void *b, Oid collation)
 
static byteagbt_bit_xfrm (bytea *leaf)
 
static GBT_VARKEYgbt_bit_l2n (GBT_VARKEY *leaf)
 
Datum gbt_bit_compress (PG_FUNCTION_ARGS)
 
Datum gbt_bit_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_bit_union (PG_FUNCTION_ARGS)
 
Datum gbt_bit_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_bit_same (PG_FUNCTION_ARGS)
 
Datum gbt_bit_penalty (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_vinfo tinfo
 

Function Documentation

Datum gbt_bit_compress ( PG_FUNCTION_ARGS  )

Definition at line 130 of file btree_bit.c.

References gbt_var_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

131 {
132  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
133 
135 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
Datum gbt_bit_consistent ( PG_FUNCTION_ARGS  )

Definition at line 138 of file btree_bit.c.

References DatumGetByteaP, DatumGetPointer, FALSE, gbt_bit_xfrm(), gbt_var_consistent(), gbt_var_key_readable(), GIST_LEAF, GISTENTRY::key, PG_GET_COLLATION, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, and TRUE.

139 {
140  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
141  void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
143 
144  /* Oid subtype = PG_GETARG_OID(3); */
145  bool *recheck = (bool *) PG_GETARG_POINTER(4);
146  bool retval;
147  GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
149 
150  /* All cases served by this function are exact */
151  *recheck = false;
152 
153  if (GIST_LEAF(entry))
154  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
155  TRUE, &tinfo);
156  else
157  {
158  bytea *q = gbt_bit_xfrm((bytea *) query);
159 
160  retval = gbt_var_consistent(&r, q, strategy, PG_GET_COLLATION(),
161  FALSE, &tinfo);
162  }
163  PG_RETURN_BOOL(retval);
164 }
#define GIST_LEAF(entry)
Definition: gist.h:133
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:224
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
#define PG_GET_COLLATION()
Definition: fmgr.h:155
#define FALSE
Definition: c.h:218
#define DatumGetByteaP(X)
Definition: fmgr.h:246
Datum key
Definition: gist.h:123
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
static bytea * gbt_bit_xfrm(bytea *leaf)
Definition: btree_bit.c:76
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:228
#define DatumGetPointer(X)
Definition: postgres.h:557
Definition: c.h:435
#define TRUE
Definition: c.h:214
static GBT_VARKEY* gbt_bit_l2n ( GBT_VARKEY leaf)
static

Definition at line 95 of file btree_bit.c.

References gbt_bit_xfrm(), gbt_var_key_copy(), gbt_var_key_readable(), GBT_VARKEY_R::lower, pfree(), and GBT_VARKEY_R::upper.

96 {
97  GBT_VARKEY *out = leaf;
99  bytea *o;
100 
101  o = gbt_bit_xfrm(r.lower);
102  r.upper = r.lower = o;
103  out = gbt_var_key_copy(&r);
104  pfree(o);
105 
106  return out;
107 
108 }
void pfree(void *pointer)
Definition: mcxt.c:992
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
static bytea * gbt_bit_xfrm(bytea *leaf)
Definition: btree_bit.c:76
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
Definition: c.h:435
Datum gbt_bit_penalty ( PG_FUNCTION_ARGS  )

Definition at line 203 of file btree_bit.c.

References gbt_var_penalty(), PG_GET_COLLATION, PG_GETARG_POINTER, and PG_RETURN_POINTER.

204 {
207  float *result = (float *) PG_GETARG_POINTER(2);
208 
210  &tinfo));
211 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
#define PG_GET_COLLATION()
Definition: fmgr.h:155
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo)
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
Datum gbt_bit_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 180 of file btree_bit.c.

References gbt_var_picksplit(), PG_GET_COLLATION, PG_GETARG_POINTER, and PG_RETURN_POINTER.

181 {
184 
185  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
186  &tinfo);
188 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
#define PG_GET_COLLATION()
Definition: fmgr.h:155
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo)
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
Datum gbt_bit_same ( PG_FUNCTION_ARGS  )

Definition at line 191 of file btree_bit.c.

References gbt_var_same(), PG_GET_COLLATION, PG_GETARG_DATUM, PG_GETARG_POINTER, and PG_RETURN_POINTER.

192 {
193  Datum d1 = PG_GETARG_DATUM(0);
194  Datum d2 = PG_GETARG_DATUM(1);
195  bool *result = (bool *) PG_GETARG_POINTER(2);
196 
197  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo);
198  PG_RETURN_POINTER(result);
199 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:224
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
#define PG_GET_COLLATION()
Definition: fmgr.h:155
uintptr_t Datum
Definition: postgres.h:374
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
Datum gbt_bit_union ( PG_FUNCTION_ARGS  )

Definition at line 169 of file btree_bit.c.

References gbt_var_union(), PG_GET_COLLATION, PG_GETARG_POINTER, and PG_RETURN_POINTER.

170 {
172  int32 *size = (int *) PG_GETARG_POINTER(1);
173 
175  &tinfo));
176 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
#define PG_GET_COLLATION()
Definition: fmgr.h:155
signed int int32
Definition: c.h:253
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo)
static const gbtree_vinfo tinfo
Definition: btree_bit.c:110
static bytea* gbt_bit_xfrm ( bytea leaf)
static

Definition at line 76 of file btree_bit.c.

References INTALIGN, palloc(), SET_VARSIZE, VARBITBYTES, VARBITS, VARDATA, and VARHDRSZ.

Referenced by gbt_bit_consistent(), and gbt_bit_l2n().

77 {
78  bytea *out = leaf;
79  int sz = VARBITBYTES(leaf) + VARHDRSZ;
80  int padded_sz = INTALIGN(sz);
81 
82  out = (bytea *) palloc(padded_sz);
83  /* initialize the padding bytes to zero */
84  while (sz < padded_sz)
85  ((char *) out)[sz++] = 0;
86  SET_VARSIZE(out, padded_sz);
87  memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
88  return out;
89 }
#define VARBITS(PTR)
Definition: varbit.h:51
#define VARDATA(PTR)
Definition: postgres.h:305
#define VARBITBYTES(PTR)
Definition: varbit.h:53
#define VARHDRSZ
Definition: c.h:441
#define INTALIGN(LEN)
Definition: c.h:581
void * palloc(Size size)
Definition: mcxt.c:891
Definition: c.h:435
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
static int32 gbt_bitcmp ( const void *  a,
const void *  b,
Oid  collation 
)
static

Definition at line 67 of file btree_bit.c.

References byteacmp(), DatumGetInt32, DirectFunctionCall2, and PointerGetDatum.

68 {
70  PointerGetDatum(a),
71  PointerGetDatum(b)));
72 }
#define DatumGetInt32(X)
Definition: postgres.h:480
#define PointerGetDatum(X)
Definition: postgres.h:564
Datum byteacmp(PG_FUNCTION_ARGS)
Definition: varlena.c:3496
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
static bool gbt_biteq ( const void *  a,
const void *  b,
Oid  collation 
)
static

Definition at line 43 of file btree_bit.c.

References biteq(), DatumGetBool, DirectFunctionCall2, and PointerGetDatum.

44 {
46  PointerGetDatum(a),
47  PointerGetDatum(b)));
48 }
#define PointerGetDatum(X)
Definition: postgres.h:564
#define DatumGetBool(X)
Definition: postgres.h:401
Datum biteq(PG_FUNCTION_ARGS)
Definition: varbit.c:820
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
static bool gbt_bitge ( const void *  a,
const void *  b,
Oid  collation 
)
static

Definition at line 35 of file btree_bit.c.

References bitge(), DatumGetBool, DirectFunctionCall2, and PointerGetDatum.

36 {
38  PointerGetDatum(a),
39  PointerGetDatum(b)));
40 }
#define PointerGetDatum(X)
Definition: postgres.h:564
Datum bitge(PG_FUNCTION_ARGS)
Definition: varbit.c:913
#define DatumGetBool(X)
Definition: postgres.h:401
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
static bool gbt_bitgt ( const void *  a,
const void *  b,
Oid  collation 
)
static

Definition at line 27 of file btree_bit.c.

References bitgt(), DatumGetBool, DirectFunctionCall2, and PointerGetDatum.

28 {
30  PointerGetDatum(a),
31  PointerGetDatum(b)));
32 }
#define PointerGetDatum(X)
Definition: postgres.h:564
#define DatumGetBool(X)
Definition: postgres.h:401
Datum bitgt(PG_FUNCTION_ARGS)
Definition: varbit.c:898
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
static bool gbt_bitle ( const void *  a,
const void *  b,
Oid  collation 
)
static

Definition at line 51 of file btree_bit.c.

References bitle(), DatumGetBool, DirectFunctionCall2, and PointerGetDatum.

52 {
54  PointerGetDatum(a),
55  PointerGetDatum(b)));
56 }
Datum bitle(PG_FUNCTION_ARGS)
Definition: varbit.c:883
#define PointerGetDatum(X)
Definition: postgres.h:564
#define DatumGetBool(X)
Definition: postgres.h:401
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
static bool gbt_bitlt ( const void *  a,
const void *  b,
Oid  collation 
)
static

Definition at line 59 of file btree_bit.c.

References bitlt(), DatumGetBool, DirectFunctionCall2, and PointerGetDatum.

60 {
62  PointerGetDatum(a),
63  PointerGetDatum(b)));
64 }
#define PointerGetDatum(X)
Definition: postgres.h:564
Datum bitlt(PG_FUNCTION_ARGS)
Definition: varbit.c:868
#define DatumGetBool(X)
Definition: postgres.h:401
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
PG_FUNCTION_INFO_V1 ( gbt_bit_compress  )
PG_FUNCTION_INFO_V1 ( gbt_bit_union  )
PG_FUNCTION_INFO_V1 ( gbt_bit_picksplit  )
PG_FUNCTION_INFO_V1 ( gbt_bit_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_bit_penalty  )
PG_FUNCTION_INFO_V1 ( gbt_bit_same  )

Variable Documentation

const gbtree_vinfo tinfo
static
Initial value:
=
{
0,
}
static bool gbt_bitle(const void *a, const void *b, Oid collation)
Definition: btree_bit.c:51
static bool gbt_bitgt(const void *a, const void *b, Oid collation)
Definition: btree_bit.c:27
static bool gbt_biteq(const void *a, const void *b, Oid collation)
Definition: btree_bit.c:43
static int32 gbt_bitcmp(const void *a, const void *b, Oid collation)
Definition: btree_bit.c:67
static bool gbt_bitge(const void *a, const void *b, Oid collation)
Definition: btree_bit.c:35
static bool gbt_bitlt(const void *a, const void *b, Oid collation)
Definition: btree_bit.c:59
#define TRUE
Definition: c.h:214
static GBT_VARKEY * gbt_bit_l2n(GBT_VARKEY *leaf)
Definition: btree_bit.c:95

Definition at line 110 of file btree_bit.c.

Referenced by gbt_var_picksplit().