Commit 0cfa34c2 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Rename GinLogicValue to GinTernaryValue.

It's more descriptive. Also, get rid of the enum, and use #defines instead,
per Greg Stark's suggestion.
parent 7317d8d9
...@@ -225,7 +225,7 @@ ginarrayconsistent(PG_FUNCTION_ARGS) ...@@ -225,7 +225,7 @@ ginarrayconsistent(PG_FUNCTION_ARGS)
Datum Datum
ginarraytriconsistent(PG_FUNCTION_ARGS) ginarraytriconsistent(PG_FUNCTION_ARGS)
{ {
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0); GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1); StrategyNumber strategy = PG_GETARG_UINT16(1);
/* ArrayType *query = PG_GETARG_ARRAYTYPE_P(2); */ /* ArrayType *query = PG_GETARG_ARRAYTYPE_P(2); */
...@@ -234,7 +234,7 @@ ginarraytriconsistent(PG_FUNCTION_ARGS) ...@@ -234,7 +234,7 @@ ginarraytriconsistent(PG_FUNCTION_ARGS)
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
/* Datum *queryKeys = (Datum *) PG_GETARG_POINTER(5); */ /* Datum *queryKeys = (Datum *) PG_GETARG_POINTER(5); */
bool *nullFlags = (bool *) PG_GETARG_POINTER(6); bool *nullFlags = (bool *) PG_GETARG_POINTER(6);
GinLogicValue res; GinTernaryValue res;
int32 i; int32 i;
switch (strategy) switch (strategy)
...@@ -300,5 +300,5 @@ ginarraytriconsistent(PG_FUNCTION_ARGS) ...@@ -300,5 +300,5 @@ ginarraytriconsistent(PG_FUNCTION_ARGS)
res = false; res = false;
} }
PG_RETURN_GIN_LOGIC_VALUE(res); PG_RETURN_GIN_TERNARY_VALUE(res);
} }
...@@ -873,7 +873,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key, ...@@ -873,7 +873,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key,
uint32 i; uint32 i;
bool haveLossyEntry; bool haveLossyEntry;
GinScanEntry entry; GinScanEntry entry;
GinLogicValue res; GinTernaryValue res;
MemoryContext oldCtx; MemoryContext oldCtx;
bool allFinished; bool allFinished;
......
...@@ -58,7 +58,7 @@ trueConsistentFn(GinScanKey key) ...@@ -58,7 +58,7 @@ trueConsistentFn(GinScanKey key)
key->recheckCurItem = false; key->recheckCurItem = false;
return true; return true;
} }
static GinLogicValue static GinTernaryValue
trueTriConsistentFn(GinScanKey key) trueTriConsistentFn(GinScanKey key)
{ {
return GIN_TRUE; return GIN_TRUE;
...@@ -91,17 +91,18 @@ directBoolConsistentFn(GinScanKey key) ...@@ -91,17 +91,18 @@ directBoolConsistentFn(GinScanKey key)
/* /*
* A helper function for calling a native ternary logic consistent function. * A helper function for calling a native ternary logic consistent function.
*/ */
static GinLogicValue static GinTernaryValue
directTriConsistentFn(GinScanKey key) directTriConsistentFn(GinScanKey key)
{ {
return DatumGetGinLogicValue(FunctionCall7Coll(key->triConsistentFmgrInfo, return DatumGetGinTernaryValue(FunctionCall7Coll(
key->collation, key->triConsistentFmgrInfo,
PointerGetDatum(key->entryRes), key->collation,
UInt16GetDatum(key->strategy), PointerGetDatum(key->entryRes),
key->query, UInt16GetDatum(key->strategy),
UInt32GetDatum(key->nuserentries), key->query,
PointerGetDatum(key->extra_data), UInt32GetDatum(key->nuserentries),
PointerGetDatum(key->queryValues), PointerGetDatum(key->extra_data),
PointerGetDatum(key->queryValues),
PointerGetDatum(key->queryCategories))); PointerGetDatum(key->queryCategories)));
} }
...@@ -113,15 +114,16 @@ directTriConsistentFn(GinScanKey key) ...@@ -113,15 +114,16 @@ directTriConsistentFn(GinScanKey key)
static bool static bool
shimBoolConsistentFn(GinScanKey key) shimBoolConsistentFn(GinScanKey key)
{ {
GinLogicValue result; GinTernaryValue result;
result = DatumGetGinLogicValue(FunctionCall7Coll(key->triConsistentFmgrInfo, result = DatumGetGinTernaryValue(FunctionCall7Coll(
key->collation, key->triConsistentFmgrInfo,
PointerGetDatum(key->entryRes), key->collation,
UInt16GetDatum(key->strategy), PointerGetDatum(key->entryRes),
key->query, UInt16GetDatum(key->strategy),
UInt32GetDatum(key->nuserentries), key->query,
PointerGetDatum(key->extra_data), UInt32GetDatum(key->nuserentries),
PointerGetDatum(key->queryValues), PointerGetDatum(key->extra_data),
PointerGetDatum(key->queryValues),
PointerGetDatum(key->queryCategories))); PointerGetDatum(key->queryCategories)));
if (result == GIN_MAYBE) if (result == GIN_MAYBE)
{ {
...@@ -147,7 +149,7 @@ shimBoolConsistentFn(GinScanKey key) ...@@ -147,7 +149,7 @@ shimBoolConsistentFn(GinScanKey key)
* *
* NB: This function modifies the key->entryRes array! * NB: This function modifies the key->entryRes array!
*/ */
static GinLogicValue static GinTernaryValue
shimTriConsistentFn(GinScanKey key) shimTriConsistentFn(GinScanKey key)
{ {
int nmaybe; int nmaybe;
...@@ -155,7 +157,7 @@ shimTriConsistentFn(GinScanKey key) ...@@ -155,7 +157,7 @@ shimTriConsistentFn(GinScanKey key)
int i; int i;
bool boolResult; bool boolResult;
bool recheck = false; bool recheck = false;
GinLogicValue curResult; GinTernaryValue curResult;
/* /*
* Count how many MAYBE inputs there are, and store their indexes in * Count how many MAYBE inputs there are, and store their indexes in
......
...@@ -288,12 +288,12 @@ gin_consistent_jsonb(PG_FUNCTION_ARGS) ...@@ -288,12 +288,12 @@ gin_consistent_jsonb(PG_FUNCTION_ARGS)
Datum Datum
gin_triconsistent_jsonb(PG_FUNCTION_ARGS) gin_triconsistent_jsonb(PG_FUNCTION_ARGS)
{ {
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0); GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1); StrategyNumber strategy = PG_GETARG_UINT16(1);
/* Jsonb *query = PG_GETARG_JSONB(2); */ /* Jsonb *query = PG_GETARG_JSONB(2); */
int32 nkeys = PG_GETARG_INT32(3); int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
GinLogicValue res = GIN_TRUE; GinTernaryValue res = GIN_TRUE;
int32 i; int32 i;
...@@ -366,7 +366,7 @@ gin_triconsistent_jsonb(PG_FUNCTION_ARGS) ...@@ -366,7 +366,7 @@ gin_triconsistent_jsonb(PG_FUNCTION_ARGS)
else else
elog(ERROR, "unrecognized strategy number: %d", strategy); elog(ERROR, "unrecognized strategy number: %d", strategy);
PG_RETURN_GIN_LOGIC_VALUE(res); PG_RETURN_GIN_TERNARY_VALUE(res);
} }
/* /*
...@@ -414,12 +414,12 @@ gin_consistent_jsonb_hash(PG_FUNCTION_ARGS) ...@@ -414,12 +414,12 @@ gin_consistent_jsonb_hash(PG_FUNCTION_ARGS)
Datum Datum
gin_triconsistent_jsonb_hash(PG_FUNCTION_ARGS) gin_triconsistent_jsonb_hash(PG_FUNCTION_ARGS)
{ {
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0); GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1); StrategyNumber strategy = PG_GETARG_UINT16(1);
/* Jsonb *query = PG_GETARG_JSONB(2); */ /* Jsonb *query = PG_GETARG_JSONB(2); */
int32 nkeys = PG_GETARG_INT32(3); int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
GinLogicValue res = GIN_TRUE; GinTernaryValue res = GIN_TRUE;
int32 i; int32 i;
bool has_maybe = false; bool has_maybe = false;
...@@ -455,7 +455,7 @@ gin_triconsistent_jsonb_hash(PG_FUNCTION_ARGS) ...@@ -455,7 +455,7 @@ gin_triconsistent_jsonb_hash(PG_FUNCTION_ARGS)
if (!has_maybe && res == GIN_TRUE) if (!has_maybe && res == GIN_TRUE)
res = GIN_MAYBE; res = GIN_MAYBE;
PG_RETURN_GIN_LOGIC_VALUE(res); PG_RETURN_GIN_TERNARY_VALUE(res);
} }
Datum Datum
......
...@@ -173,12 +173,12 @@ gin_extract_tsquery(PG_FUNCTION_ARGS) ...@@ -173,12 +173,12 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
typedef struct typedef struct
{ {
QueryItem *first_item; QueryItem *first_item;
GinLogicValue *check; GinTernaryValue *check;
int *map_item_operand; int *map_item_operand;
bool *need_recheck; bool *need_recheck;
} GinChkVal; } GinChkVal;
static GinLogicValue static GinTernaryValue
checkcondition_gin(void *checkval, QueryOperand *val) checkcondition_gin(void *checkval, QueryOperand *val)
{ {
GinChkVal *gcv = (GinChkVal *) checkval; GinChkVal *gcv = (GinChkVal *) checkval;
...@@ -202,11 +202,11 @@ checkcondition_gin(void *checkval, QueryOperand *val) ...@@ -202,11 +202,11 @@ checkcondition_gin(void *checkval, QueryOperand *val)
* checkval can be used to pass information to the callback. TS_execute doesn't * checkval can be used to pass information to the callback. TS_execute doesn't
* do anything with it. * do anything with it.
*/ */
static GinLogicValue static GinTernaryValue
TS_execute_ternary(QueryItem *curitem, void *checkval, TS_execute_ternary(QueryItem *curitem, void *checkval,
GinLogicValue (*chkcond) (void *checkval, QueryOperand *val)) GinTernaryValue (*chkcond) (void *checkval, QueryOperand *val))
{ {
GinLogicValue val1, val2, result; GinTernaryValue val1, val2, result;
/* since this function recurses, it could be driven to stack overflow */ /* since this function recurses, it could be driven to stack overflow */
check_stack_depth(); check_stack_depth();
...@@ -297,14 +297,14 @@ gin_tsquery_consistent(PG_FUNCTION_ARGS) ...@@ -297,14 +297,14 @@ gin_tsquery_consistent(PG_FUNCTION_ARGS)
Datum Datum
gin_tsquery_triconsistent(PG_FUNCTION_ARGS) gin_tsquery_triconsistent(PG_FUNCTION_ARGS)
{ {
GinLogicValue *check = (GinLogicValue *) PG_GETARG_POINTER(0); GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */ /* StrategyNumber strategy = PG_GETARG_UINT16(1); */
TSQuery query = PG_GETARG_TSQUERY(2); TSQuery query = PG_GETARG_TSQUERY(2);
/* int32 nkeys = PG_GETARG_INT32(3); */ /* int32 nkeys = PG_GETARG_INT32(3); */
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
GinLogicValue res = GIN_FALSE; GinTernaryValue res = GIN_FALSE;
bool recheck; bool recheck;
/* The query requires recheck only if it involves weights */ /* The query requires recheck only if it involves weights */
...@@ -332,7 +332,7 @@ gin_tsquery_triconsistent(PG_FUNCTION_ARGS) ...@@ -332,7 +332,7 @@ gin_tsquery_triconsistent(PG_FUNCTION_ARGS)
res = GIN_MAYBE; res = GIN_MAYBE;
} }
PG_RETURN_GIN_LOGIC_VALUE(res); PG_RETURN_GIN_TERNARY_VALUE(res);
} }
/* /*
......
...@@ -47,20 +47,22 @@ typedef struct GinStatsData ...@@ -47,20 +47,22 @@ typedef struct GinStatsData
int32 ginVersion; int32 ginVersion;
} GinStatsData; } GinStatsData;
/* ginlogic.c */ /*
enum GinLogicValueEnum * A ternary value used by tri-consistent functions.
{ *
GIN_FALSE = 0, /* item is not present / does not match */ * For convenience, this is compatible with booleans. A boolean can be
GIN_TRUE = 1, /* item is present / matches */ * safely cast to a GinTernaryValue.
GIN_MAYBE = 2 /* don't know if item is present / don't know if */
* matches */ typedef char GinTernaryValue;
};
typedef char GinLogicValue; #define GIN_FALSE 0 /* item is not present / does not match */
#define GIN_TRUE 1 /* item is present / matches */
#define GIN_MAYBE 2 /* don't know if item is present / don't know if
* matches */
#define DatumGetGinLogicValue(X) ((GinLogicValue)(X)) #define DatumGetGinTernaryValue(X) ((GinTernaryValue)(X))
#define GinLogicValueGetDatum(X) ((Datum)(X)) #define GinTernaryValueGetDatum(X) ((Datum)(X))
#define PG_RETURN_GIN_LOGIC_VALUE(x) return GinLogicValueGetDatum(x) #define PG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x)
/* GUC parameter */ /* GUC parameter */
extern PGDLLIMPORT int GinFuzzySearchLimit; extern PGDLLIMPORT int GinFuzzySearchLimit;
......
...@@ -763,7 +763,7 @@ typedef struct GinScanKeyData ...@@ -763,7 +763,7 @@ typedef struct GinScanKeyData
/* array of check flags, reported to consistentFn */ /* array of check flags, reported to consistentFn */
bool *entryRes; bool *entryRes;
bool (*boolConsistentFn) (GinScanKey key); bool (*boolConsistentFn) (GinScanKey key);
GinLogicValue (*triConsistentFn) (GinScanKey key); GinTernaryValue (*triConsistentFn) (GinScanKey key);
FmgrInfo *consistentFmgrInfo; FmgrInfo *consistentFmgrInfo;
FmgrInfo *triConsistentFmgrInfo; FmgrInfo *triConsistentFmgrInfo;
Oid collation; Oid collation;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment