Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0cfa34c

Browse files
committed
Rename GinLogicValue to GinTernaryValue.
It's more descriptive. Also, get rid of the enum, and use #defines instead, per Greg Stark's suggestion.
1 parent 7317d8d commit 0cfa34c

File tree

7 files changed

+56
-52
lines changed

7 files changed

+56
-52
lines changed

src/backend/access/gin/ginarrayproc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ ginarrayconsistent(PG_FUNCTION_ARGS)
225225
Datum
226226
ginarraytriconsistent(PG_FUNCTION_ARGS)
227227
{
228-
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0);
228+
GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
229229
StrategyNumber strategy = PG_GETARG_UINT16(1);
230230

231231
/* ArrayType *query = PG_GETARG_ARRAYTYPE_P(2); */
@@ -234,7 +234,7 @@ ginarraytriconsistent(PG_FUNCTION_ARGS)
234234
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
235235
/* Datum *queryKeys = (Datum *) PG_GETARG_POINTER(5); */
236236
bool *nullFlags = (bool *) PG_GETARG_POINTER(6);
237-
GinLogicValue res;
237+
GinTernaryValue res;
238238
int32 i;
239239

240240
switch (strategy)
@@ -300,5 +300,5 @@ ginarraytriconsistent(PG_FUNCTION_ARGS)
300300
res = false;
301301
}
302302

303-
PG_RETURN_GIN_LOGIC_VALUE(res);
303+
PG_RETURN_GIN_TERNARY_VALUE(res);
304304
}

src/backend/access/gin/ginget.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key,
873873
uint32 i;
874874
bool haveLossyEntry;
875875
GinScanEntry entry;
876-
GinLogicValue res;
876+
GinTernaryValue res;
877877
MemoryContext oldCtx;
878878
bool allFinished;
879879

src/backend/access/gin/ginlogic.c

+23-21
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ trueConsistentFn(GinScanKey key)
5858
key->recheckCurItem = false;
5959
return true;
6060
}
61-
static GinLogicValue
61+
static GinTernaryValue
6262
trueTriConsistentFn(GinScanKey key)
6363
{
6464
return GIN_TRUE;
@@ -91,17 +91,18 @@ directBoolConsistentFn(GinScanKey key)
9191
/*
9292
* A helper function for calling a native ternary logic consistent function.
9393
*/
94-
static GinLogicValue
94+
static GinTernaryValue
9595
directTriConsistentFn(GinScanKey key)
9696
{
97-
return DatumGetGinLogicValue(FunctionCall7Coll(key->triConsistentFmgrInfo,
98-
key->collation,
99-
PointerGetDatum(key->entryRes),
100-
UInt16GetDatum(key->strategy),
101-
key->query,
102-
UInt32GetDatum(key->nuserentries),
103-
PointerGetDatum(key->extra_data),
104-
PointerGetDatum(key->queryValues),
97+
return DatumGetGinTernaryValue(FunctionCall7Coll(
98+
key->triConsistentFmgrInfo,
99+
key->collation,
100+
PointerGetDatum(key->entryRes),
101+
UInt16GetDatum(key->strategy),
102+
key->query,
103+
UInt32GetDatum(key->nuserentries),
104+
PointerGetDatum(key->extra_data),
105+
PointerGetDatum(key->queryValues),
105106
PointerGetDatum(key->queryCategories)));
106107
}
107108

@@ -113,15 +114,16 @@ directTriConsistentFn(GinScanKey key)
113114
static bool
114115
shimBoolConsistentFn(GinScanKey key)
115116
{
116-
GinLogicValue result;
117-
result = DatumGetGinLogicValue(FunctionCall7Coll(key->triConsistentFmgrInfo,
118-
key->collation,
119-
PointerGetDatum(key->entryRes),
120-
UInt16GetDatum(key->strategy),
121-
key->query,
122-
UInt32GetDatum(key->nuserentries),
123-
PointerGetDatum(key->extra_data),
124-
PointerGetDatum(key->queryValues),
117+
GinTernaryValue result;
118+
result = DatumGetGinTernaryValue(FunctionCall7Coll(
119+
key->triConsistentFmgrInfo,
120+
key->collation,
121+
PointerGetDatum(key->entryRes),
122+
UInt16GetDatum(key->strategy),
123+
key->query,
124+
UInt32GetDatum(key->nuserentries),
125+
PointerGetDatum(key->extra_data),
126+
PointerGetDatum(key->queryValues),
125127
PointerGetDatum(key->queryCategories)));
126128
if (result == GIN_MAYBE)
127129
{
@@ -147,15 +149,15 @@ shimBoolConsistentFn(GinScanKey key)
147149
*
148150
* NB: This function modifies the key->entryRes array!
149151
*/
150-
static GinLogicValue
152+
static GinTernaryValue
151153
shimTriConsistentFn(GinScanKey key)
152154
{
153155
int nmaybe;
154156
int maybeEntries[MAX_MAYBE_ENTRIES];
155157
int i;
156158
bool boolResult;
157159
bool recheck = false;
158-
GinLogicValue curResult;
160+
GinTernaryValue curResult;
159161

160162
/*
161163
* Count how many MAYBE inputs there are, and store their indexes in

src/backend/utils/adt/jsonb_gin.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ gin_consistent_jsonb(PG_FUNCTION_ARGS)
288288
Datum
289289
gin_triconsistent_jsonb(PG_FUNCTION_ARGS)
290290
{
291-
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0);
291+
GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
292292
StrategyNumber strategy = PG_GETARG_UINT16(1);
293293
/* Jsonb *query = PG_GETARG_JSONB(2); */
294294
int32 nkeys = PG_GETARG_INT32(3);
295295
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
296-
GinLogicValue res = GIN_TRUE;
296+
GinTernaryValue res = GIN_TRUE;
297297

298298
int32 i;
299299

@@ -366,7 +366,7 @@ gin_triconsistent_jsonb(PG_FUNCTION_ARGS)
366366
else
367367
elog(ERROR, "unrecognized strategy number: %d", strategy);
368368

369-
PG_RETURN_GIN_LOGIC_VALUE(res);
369+
PG_RETURN_GIN_TERNARY_VALUE(res);
370370
}
371371

372372
/*
@@ -414,12 +414,12 @@ gin_consistent_jsonb_hash(PG_FUNCTION_ARGS)
414414
Datum
415415
gin_triconsistent_jsonb_hash(PG_FUNCTION_ARGS)
416416
{
417-
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0);
417+
GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
418418
StrategyNumber strategy = PG_GETARG_UINT16(1);
419419
/* Jsonb *query = PG_GETARG_JSONB(2); */
420420
int32 nkeys = PG_GETARG_INT32(3);
421421
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
422-
GinLogicValue res = GIN_TRUE;
422+
GinTernaryValue res = GIN_TRUE;
423423
int32 i;
424424
bool has_maybe = false;
425425

@@ -455,7 +455,7 @@ gin_triconsistent_jsonb_hash(PG_FUNCTION_ARGS)
455455
if (!has_maybe && res == GIN_TRUE)
456456
res = GIN_MAYBE;
457457

458-
PG_RETURN_GIN_LOGIC_VALUE(res);
458+
PG_RETURN_GIN_TERNARY_VALUE(res);
459459
}
460460

461461
Datum

src/backend/utils/adt/tsginidx.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
173173
typedef struct
174174
{
175175
QueryItem *first_item;
176-
GinLogicValue *check;
176+
GinTernaryValue *check;
177177
int *map_item_operand;
178178
bool *need_recheck;
179179
} GinChkVal;
180180

181-
static GinLogicValue
181+
static GinTernaryValue
182182
checkcondition_gin(void *checkval, QueryOperand *val)
183183
{
184184
GinChkVal *gcv = (GinChkVal *) checkval;
@@ -202,11 +202,11 @@ checkcondition_gin(void *checkval, QueryOperand *val)
202202
* checkval can be used to pass information to the callback. TS_execute doesn't
203203
* do anything with it.
204204
*/
205-
static GinLogicValue
205+
static GinTernaryValue
206206
TS_execute_ternary(QueryItem *curitem, void *checkval,
207-
GinLogicValue (*chkcond) (void *checkval, QueryOperand *val))
207+
GinTernaryValue (*chkcond) (void *checkval, QueryOperand *val))
208208
{
209-
GinLogicValue val1, val2, result;
209+
GinTernaryValue val1, val2, result;
210210
/* since this function recurses, it could be driven to stack overflow */
211211
check_stack_depth();
212212

@@ -297,14 +297,14 @@ gin_tsquery_consistent(PG_FUNCTION_ARGS)
297297
Datum
298298
gin_tsquery_triconsistent(PG_FUNCTION_ARGS)
299299
{
300-
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0);
300+
GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
301301

302302
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
303303
TSQuery query = PG_GETARG_TSQUERY(2);
304304

305305
/* int32 nkeys = PG_GETARG_INT32(3); */
306306
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
307-
GinLogicValue res = GIN_FALSE;
307+
GinTernaryValue res = GIN_FALSE;
308308
bool recheck;
309309

310310
/* The query requires recheck only if it involves weights */
@@ -332,7 +332,7 @@ gin_tsquery_triconsistent(PG_FUNCTION_ARGS)
332332
res = GIN_MAYBE;
333333
}
334334

335-
PG_RETURN_GIN_LOGIC_VALUE(res);
335+
PG_RETURN_GIN_TERNARY_VALUE(res);
336336
}
337337

338338
/*

src/include/access/gin.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,22 @@ typedef struct GinStatsData
4747
int32 ginVersion;
4848
} GinStatsData;
4949

50-
/* ginlogic.c */
51-
enum GinLogicValueEnum
52-
{
53-
GIN_FALSE = 0, /* item is not present / does not match */
54-
GIN_TRUE = 1, /* item is present / matches */
55-
GIN_MAYBE = 2 /* don't know if item is present / don't know if
56-
* matches */
57-
};
50+
/*
51+
* A ternary value used by tri-consistent functions.
52+
*
53+
* For convenience, this is compatible with booleans. A boolean can be
54+
* safely cast to a GinTernaryValue.
55+
*/
56+
typedef char GinTernaryValue;
5857

59-
typedef char GinLogicValue;
58+
#define GIN_FALSE 0 /* item is not present / does not match */
59+
#define GIN_TRUE 1 /* item is present / matches */
60+
#define GIN_MAYBE 2 /* don't know if item is present / don't know if
61+
* matches */
6062

61-
#define DatumGetGinLogicValue(X) ((GinLogicValue)(X))
62-
#define GinLogicValueGetDatum(X) ((Datum)(X))
63-
#define PG_RETURN_GIN_LOGIC_VALUE(x) return GinLogicValueGetDatum(x)
63+
#define DatumGetGinTernaryValue(X) ((GinTernaryValue)(X))
64+
#define GinTernaryValueGetDatum(X) ((Datum)(X))
65+
#define PG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x)
6466

6567
/* GUC parameter */
6668
extern PGDLLIMPORT int GinFuzzySearchLimit;

src/include/access/gin_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ typedef struct GinScanKeyData
763763
/* array of check flags, reported to consistentFn */
764764
bool *entryRes;
765765
bool (*boolConsistentFn) (GinScanKey key);
766-
GinLogicValue (*triConsistentFn) (GinScanKey key);
766+
GinTernaryValue (*triConsistentFn) (GinScanKey key);
767767
FmgrInfo *consistentFmgrInfo;
768768
FmgrInfo *triConsistentFmgrInfo;
769769
Oid collation;

0 commit comments

Comments
 (0)