PostgreSQL Source Code  git master
btree_bit.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_var.h"
#include "utils/fmgrprotos.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, FmgrInfo *flinfo)
 
static bool gbt_bitge (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_biteq (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_bitle (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static bool gbt_bitlt (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static int32 gbt_bitcmp (const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
 
static byteagbt_bit_xfrm (bytea *leaf)
 
static GBT_VARKEYgbt_bit_l2n (GBT_VARKEY *leaf, FmgrInfo *flinfo)
 
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

◆ gbt_bit_compress()

Datum gbt_bit_compress ( PG_FUNCTION_ARGS  )

Definition at line 128 of file btree_bit.c.

129 {
130  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
131 
133 }
static const gbtree_vinfo tinfo
Definition: btree_bit.c:108
GISTENTRY * gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361

References gbt_var_compress(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_bit_consistent()

Datum gbt_bit_consistent ( PG_FUNCTION_ARGS  )

Definition at line 136 of file btree_bit.c.

137 {
138  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139  void *query = DatumGetByteaP(PG_GETARG_DATUM(1));
141 
142  /* Oid subtype = PG_GETARG_OID(3); */
143  bool *recheck = (bool *) PG_GETARG_POINTER(4);
144  bool retval;
147 
148  /* All cases served by this function are exact */
149  *recheck = false;
150 
151  if (GIST_LEAF(entry))
152  retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
153  true, &tinfo, fcinfo->flinfo);
154  else
155  {
156  bytea *q = gbt_bit_xfrm((bytea *) query);
157 
158  retval = gbt_var_consistent(&r, q, strategy, PG_GET_COLLATION(),
159  false, &tinfo, fcinfo->flinfo);
160  }
161  PG_RETURN_BOOL(retval);
162 }
static bytea * gbt_bit_xfrm(bytea *leaf)
Definition: btree_bit.c:75
bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query, StrategyNumber strategy, Oid collation, bool is_leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k)
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_GET_COLLATION()
Definition: fmgr.h:198
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define DatumGetByteaP(X)
Definition: fmgr.h:331
#define GIST_LEAF(entry)
Definition: gist.h:170
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:160
Definition: c.h:641

References DatumGetByteaP, DatumGetPointer(), gbt_bit_xfrm(), gbt_var_consistent(), gbt_var_key_readable(), GIST_LEAF, GISTENTRY::key, sort-test::key, PG_GET_COLLATION, PG_GETARG_DATUM, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, and tinfo.

◆ gbt_bit_l2n()

static GBT_VARKEY* gbt_bit_l2n ( GBT_VARKEY leaf,
FmgrInfo flinfo 
)
static

Definition at line 94 of file btree_bit.c.

95 {
96  GBT_VARKEY *out = leaf;
98  bytea *o;
99 
100  o = gbt_bit_xfrm(r.lower);
101  r.upper = r.lower = o;
102  out = gbt_var_key_copy(&r);
103  pfree(o);
104 
105  return out;
106 }
GBT_VARKEY * gbt_var_key_copy(const GBT_VARKEY_R *u)
void pfree(void *pointer)
Definition: mcxt.c:1521

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

◆ gbt_bit_penalty()

Datum gbt_bit_penalty ( PG_FUNCTION_ARGS  )

Definition at line 201 of file btree_bit.c.

202 {
205  float *result = (float *) PG_GETARG_POINTER(2);
206 
208  &tinfo, fcinfo->flinfo));
209 }
float * gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_bit_picksplit()

Datum gbt_bit_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 178 of file btree_bit.c.

179 {
182 
183  gbt_var_picksplit(entryvec, v, PG_GET_COLLATION(),
184  &tinfo, fcinfo->flinfo);
186 }
GIST_SPLITVEC * gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_bit_same()

Datum gbt_bit_same ( PG_FUNCTION_ARGS  )

Definition at line 189 of file btree_bit.c.

190 {
191  Datum d1 = PG_GETARG_DATUM(0);
192  Datum d2 = PG_GETARG_DATUM(1);
193  bool *result = (bool *) PG_GETARG_POINTER(2);
194 
195  *result = gbt_var_same(d1, d2, PG_GET_COLLATION(), &tinfo, fcinfo->flinfo);
196  PG_RETURN_POINTER(result);
197 }
bool gbt_var_same(Datum d1, Datum d2, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
uintptr_t Datum
Definition: postgres.h:64

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

◆ gbt_bit_union()

Datum gbt_bit_union ( PG_FUNCTION_ARGS  )

Definition at line 167 of file btree_bit.c.

168 {
170  int32 *size = (int *) PG_GETARG_POINTER(1);
171 
173  &tinfo, fcinfo->flinfo));
174 }
GBT_VARKEY * gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
int32_t int32
Definition: c.h:481
static pg_noinline void Size size
Definition: slab.c:607

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

◆ gbt_bit_xfrm()

static bytea* gbt_bit_xfrm ( bytea leaf)
static

Definition at line 75 of file btree_bit.c.

76 {
77  bytea *out = leaf;
78  int sz = VARBITBYTES(leaf) + VARHDRSZ;
79  int padded_sz = INTALIGN(sz);
80 
81  out = (bytea *) palloc(padded_sz);
82  /* initialize the padding bytes to zero */
83  while (sz < padded_sz)
84  ((char *) out)[sz++] = 0;
85  SET_VARSIZE(out, padded_sz);
86  memcpy(VARDATA(out), VARBITS(leaf), VARBITBYTES(leaf));
87  return out;
88 }
#define INTALIGN(LEN)
Definition: c.h:762
#define VARHDRSZ
Definition: c.h:646
void * palloc(Size size)
Definition: mcxt.c:1317
#define VARDATA(PTR)
Definition: varatt.h:278
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARBITBYTES(PTR)
Definition: varbit.h:73
#define VARBITS(PTR)
Definition: varbit.h:71

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

Referenced by gbt_bit_consistent(), and gbt_bit_l2n().

◆ gbt_bitcmp()

static int32 gbt_bitcmp ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 66 of file btree_bit.c.

67 {
70  PointerGetDatum(b)));
71 }
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
int b
Definition: isn.c:69
int a
Definition: isn.c:68
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
Datum byteacmp(PG_FUNCTION_ARGS)
Definition: varlena.c:3913

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

◆ gbt_biteq()

static bool gbt_biteq ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 42 of file btree_bit.c.

43 {
46  PointerGetDatum(b)));
47 }
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
Datum biteq(PG_FUNCTION_ARGS)
Definition: varbit.c:841

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

◆ gbt_bitge()

static bool gbt_bitge ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 34 of file btree_bit.c.

35 {
38  PointerGetDatum(b)));
39 }
Datum bitge(PG_FUNCTION_ARGS)
Definition: varbit.c:934

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

◆ gbt_bitgt()

static bool gbt_bitgt ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 26 of file btree_bit.c.

27 {
30  PointerGetDatum(b)));
31 }
Datum bitgt(PG_FUNCTION_ARGS)
Definition: varbit.c:919

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

◆ gbt_bitle()

static bool gbt_bitle ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 50 of file btree_bit.c.

51 {
54  PointerGetDatum(b)));
55 }
Datum bitle(PG_FUNCTION_ARGS)
Definition: varbit.c:904

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

◆ gbt_bitlt()

static bool gbt_bitlt ( const void *  a,
const void *  b,
Oid  collation,
FmgrInfo flinfo 
)
static

Definition at line 58 of file btree_bit.c.

59 {
62  PointerGetDatum(b)));
63 }
Datum bitlt(PG_FUNCTION_ARGS)
Definition: varbit.c:889

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

◆ PG_FUNCTION_INFO_V1() [1/6]

PG_FUNCTION_INFO_V1 ( gbt_bit_compress  )

◆ PG_FUNCTION_INFO_V1() [2/6]

PG_FUNCTION_INFO_V1 ( gbt_bit_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/6]

PG_FUNCTION_INFO_V1 ( gbt_bit_penalty  )

◆ PG_FUNCTION_INFO_V1() [4/6]

PG_FUNCTION_INFO_V1 ( gbt_bit_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/6]

PG_FUNCTION_INFO_V1 ( gbt_bit_same  )

◆ PG_FUNCTION_INFO_V1() [6/6]

PG_FUNCTION_INFO_V1 ( gbt_bit_union  )

Variable Documentation

◆ tinfo

const gbtree_vinfo tinfo
static
Initial value:
=
{
0,
true,
}
static bool gbt_bitge(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:34
static bool gbt_bitgt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:26
static int32 gbt_bitcmp(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:66
static bool gbt_bitle(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:50
static GBT_VARKEY * gbt_bit_l2n(GBT_VARKEY *leaf, FmgrInfo *flinfo)
Definition: btree_bit.c:94
static bool gbt_biteq(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:42
static bool gbt_bitlt(const void *a, const void *b, Oid collation, FmgrInfo *flinfo)
Definition: btree_bit.c:58
@ gbt_t_bit
Definition: btree_gist.h:34

Definition at line 108 of file btree_bit.c.

Referenced by binary_upgrade_set_type_oids_by_type_oid(), gbt_bit_compress(), gbt_bit_consistent(), gbt_bit_penalty(), gbt_bit_picksplit(), gbt_bit_same(), gbt_bit_union(), gbt_num_bin_union(), gbt_num_compress(), gbt_num_consistent(), gbt_num_distance(), gbt_num_fetch(), gbt_num_picksplit(), gbt_num_same(), gbt_num_union(), gbt_var_bin_union(), gbt_var_consistent(), gbt_var_leaf2node(), gbt_var_node_cp_len(), gbt_var_node_pf_match(), gbt_var_penalty(), gbt_var_picksplit(), gbt_var_same(), gbt_var_union(), and getConstraints().