PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
btree_enum.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
#include "fmgr.h"
#include "utils/fmgrprotos.h"
#include "utils/fmgroids.h"
#include "utils/sortsupport.h"
Include dependency graph for btree_enum.c:

Go to the source code of this file.

Data Structures

struct  oidKEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_enum_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_union)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_same)
 
 PG_FUNCTION_INFO_V1 (gbt_enum_sortsupport)
 
static bool gbt_enumgt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_enumge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_enumeq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_enumle (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_enumlt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_enumkey_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
Datum gbt_enum_compress (PG_FUNCTION_ARGS)
 
Datum gbt_enum_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_enum_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_enum_union (PG_FUNCTION_ARGS)
 
Datum gbt_enum_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_enum_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_enum_same (PG_FUNCTION_ARGS)
 
static int gbt_enum_ssup_cmp (Datum x, Datum y, SortSupport ssup)
 
Datum gbt_enum_sortsupport (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Function Documentation

◆ gbt_enum_compress()

Datum gbt_enum_compress ( PG_FUNCTION_ARGS  )

Definition at line 107 of file btree_enum.c.

108{
109 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
110
112}
static const gbtree_ninfo tinfo
Definition: btree_enum.c:87
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361

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

◆ gbt_enum_consistent()

Datum gbt_enum_consistent ( PG_FUNCTION_ARGS  )

Definition at line 123 of file btree_enum.c.

124{
125 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
126 Oid query = PG_GETARG_OID(1);
128
129 /* Oid subtype = PG_GETARG_OID(3); */
130 bool *recheck = (bool *) PG_GETARG_POINTER(4);
131 oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
133
134 /* All cases served by this function are exact */
135 *recheck = false;
136
137 key.lower = (GBT_NUMKEY *) &kkk->lower;
138 key.upper = (GBT_NUMKEY *) &kkk->upper;
139
140 PG_RETURN_BOOL(gbt_num_consistent(&key, &query, &strategy,
141 GIST_LEAF(entry), &tinfo,
142 fcinfo->flinfo));
143}
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
char GBT_NUMKEY
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:272
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define GIST_LEAF(entry)
Definition: gist.h:171
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
unsigned int Oid
Definition: postgres_ext.h:30
uint16 StrategyNumber
Definition: stratnum.h:22
Datum key
Definition: gist.h:161
Oid upper
Definition: btree_enum.c:18
Oid lower
Definition: btree_enum.c:17

References DatumGetPointer(), gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, sort-test::key, oidKEY::lower, PG_GETARG_OID, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, tinfo, and oidKEY::upper.

◆ gbt_enum_fetch()

Datum gbt_enum_fetch ( PG_FUNCTION_ARGS  )

Definition at line 115 of file btree_enum.c.

116{
117 GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
118
120}
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)

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

◆ gbt_enum_penalty()

Datum gbt_enum_penalty ( PG_FUNCTION_ARGS  )

Definition at line 156 of file btree_enum.c.

157{
158 oidKEY *origentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
159 oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
160 float *result = (float *) PG_GETARG_POINTER(2);
161
162 penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
163
164 PG_RETURN_POINTER(result);
165}
#define penalty_num(result, olower, oupper, nlower, nupper)

References DatumGetPointer(), sort-test::key, oidKEY::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and oidKEY::upper.

◆ gbt_enum_picksplit()

Datum gbt_enum_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 168 of file btree_enum.c.

169{
172 &tinfo, fcinfo->flinfo));
173}
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_enum_same()

Datum gbt_enum_same ( PG_FUNCTION_ARGS  )

Definition at line 176 of file btree_enum.c.

177{
178 oidKEY *b1 = (oidKEY *) PG_GETARG_POINTER(0);
179 oidKEY *b2 = (oidKEY *) PG_GETARG_POINTER(1);
180 bool *result = (bool *) PG_GETARG_POINTER(2);
181
182 *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
183 PG_RETURN_POINTER(result);
184}
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

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

◆ gbt_enum_sortsupport()

Datum gbt_enum_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 201 of file btree_enum.c.

202{
204 FmgrInfo *flinfo;
205
207
208 /*
209 * Since gbt_enum_ssup_cmp() uses enum_cmp() like the rest of the
210 * comparison functions, it also needs to pass flinfo when calling it. The
211 * caller to a SortSupport comparison function doesn't provide an FmgrInfo
212 * struct, so look it up now, save it in ssup_extra and use it in
213 * gbt_enum_ssup_cmp() later.
214 */
215 flinfo = MemoryContextAlloc(ssup->ssup_cxt, sizeof(FmgrInfo));
216 fmgr_info_cxt(F_ENUM_CMP, flinfo, ssup->ssup_cxt);
217 ssup->ssup_extra = flinfo;
218
220}
static int gbt_enum_ssup_cmp(Datum x, Datum y, SortSupport ssup)
Definition: btree_enum.c:187
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition: fmgr.c:137
#define PG_RETURN_VOID()
Definition: fmgr.h:349
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1185
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
Definition: fmgr.h:57
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
void * ssup_extra
Definition: sortsupport.h:87
MemoryContext ssup_cxt
Definition: sortsupport.h:66

References SortSupportData::comparator, fmgr_info_cxt(), gbt_enum_ssup_cmp(), MemoryContextAlloc(), PG_GETARG_POINTER, PG_RETURN_VOID, SortSupportData::ssup_cxt, and SortSupportData::ssup_extra.

◆ gbt_enum_ssup_cmp()

static int gbt_enum_ssup_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 187 of file btree_enum.c.

188{
189 oidKEY *arg1 = (oidKEY *) DatumGetPointer(x);
190 oidKEY *arg2 = (oidKEY *) DatumGetPointer(y);
191
192 /* for leaf items we expect lower == upper, so only compare lower */
194 ssup->ssup_extra,
196 arg1->lower,
197 arg2->lower));
198}
Datum enum_cmp(PG_FUNCTION_ARGS)
Definition: enum.c:378
Datum CallerFInfoFunctionCall2(PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1085
int y
Definition: isn.c:76
int x
Definition: isn.c:75
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:207
#define InvalidOid
Definition: postgres_ext.h:35

References CallerFInfoFunctionCall2(), DatumGetInt32(), DatumGetPointer(), enum_cmp(), InvalidOid, oidKEY::lower, SortSupportData::ssup_extra, x, and y.

Referenced by gbt_enum_sortsupport().

◆ gbt_enum_union()

Datum gbt_enum_union ( PG_FUNCTION_ARGS  )

Definition at line 146 of file btree_enum.c.

147{
149 void *out = palloc(sizeof(oidKEY));
150
151 *(int *) PG_GETARG_POINTER(1) = sizeof(oidKEY);
152 PG_RETURN_POINTER(gbt_num_union(out, entryvec, &tinfo, fcinfo->flinfo));
153}
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
void * palloc(Size size)
Definition: mcxt.c:1321

References gbt_num_union(), palloc(), PG_GETARG_POINTER, PG_RETURN_POINTER, and tinfo.

◆ gbt_enumeq()

static bool gbt_enumeq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 47 of file btree_enum.c.

48{
49 return (*((const Oid *) a) == *((const Oid *) b));
50}
int b
Definition: isn.c:74
int a
Definition: isn.c:73

References a, and b.

◆ gbt_enumge()

static bool gbt_enumge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 40 of file btree_enum.c.

41{
43 ObjectIdGetDatum(*((const Oid *) a)),
44 ObjectIdGetDatum(*((const Oid *) b))));
45}
Datum enum_ge(PG_FUNCTION_ARGS)
Definition: enum.c:342
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257

References a, b, CallerFInfoFunctionCall2(), DatumGetBool(), enum_ge(), InvalidOid, and ObjectIdGetDatum().

◆ gbt_enumgt()

static bool gbt_enumgt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 33 of file btree_enum.c.

34{
36 ObjectIdGetDatum(*((const Oid *) a)),
37 ObjectIdGetDatum(*((const Oid *) b))));
38}
Datum enum_gt(PG_FUNCTION_ARGS)
Definition: enum.c:351

References a, b, CallerFInfoFunctionCall2(), DatumGetBool(), enum_gt(), InvalidOid, and ObjectIdGetDatum().

◆ gbt_enumkey_cmp()

static int gbt_enumkey_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 67 of file btree_enum.c.

68{
69 oidKEY *ia = (oidKEY *) (((const Nsrt *) a)->t);
70 oidKEY *ib = (oidKEY *) (((const Nsrt *) b)->t);
71
72 if (ia->lower == ib->lower)
73 {
74 if (ia->upper == ib->upper)
75 return 0;
76
80 }
81
85}

References a, b, CallerFInfoFunctionCall2(), DatumGetInt32(), enum_cmp(), InvalidOid, oidKEY::lower, ObjectIdGetDatum(), and oidKEY::upper.

◆ gbt_enumle()

static bool gbt_enumle ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 52 of file btree_enum.c.

53{
55 ObjectIdGetDatum(*((const Oid *) a)),
56 ObjectIdGetDatum(*((const Oid *) b))));
57}
Datum enum_le(PG_FUNCTION_ARGS)
Definition: enum.c:315

References a, b, CallerFInfoFunctionCall2(), DatumGetBool(), enum_le(), InvalidOid, and ObjectIdGetDatum().

◆ gbt_enumlt()

static bool gbt_enumlt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 59 of file btree_enum.c.

60{
62 ObjectIdGetDatum(*((const Oid *) a)),
63 ObjectIdGetDatum(*((const Oid *) b))));
64}
Datum enum_lt(PG_FUNCTION_ARGS)
Definition: enum.c:306

References a, b, CallerFInfoFunctionCall2(), DatumGetBool(), enum_lt(), InvalidOid, and ObjectIdGetDatum().

◆ PG_FUNCTION_INFO_V1() [1/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_compress  )

◆ PG_FUNCTION_INFO_V1() [2/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_consistent  )

◆ PG_FUNCTION_INFO_V1() [3/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_fetch  )

◆ PG_FUNCTION_INFO_V1() [4/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_penalty  )

◆ PG_FUNCTION_INFO_V1() [5/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_picksplit  )

◆ PG_FUNCTION_INFO_V1() [6/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_same  )

◆ PG_FUNCTION_INFO_V1() [7/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_sortsupport  )

◆ PG_FUNCTION_INFO_V1() [8/8]

PG_FUNCTION_INFO_V1 ( gbt_enum_union  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(Oid),
8,
NULL
}
static bool gbt_enumeq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:47
static bool gbt_enumge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:40
static bool gbt_enumlt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:59
static int gbt_enumkey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:67
static bool gbt_enumgt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:33
static bool gbt_enumle(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_enum.c:52
@ gbt_t_enum
Definition: btree_gist.h:38

Definition at line 87 of file btree_enum.c.

Referenced by gbt_enum_compress(), gbt_enum_consistent(), gbt_enum_fetch(), gbt_enum_picksplit(), gbt_enum_same(), and gbt_enum_union().