2009-03-26 07:20:01 +08:00
|
|
|
/*
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/btree_gin/btree_gin.c
|
2009-03-26 07:20:01 +08:00
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "fmgr.h"
|
|
|
|
#include "access/skey.h"
|
2011-02-09 05:04:18 +08:00
|
|
|
#include "catalog/pg_collation.h"
|
2009-03-26 07:20:01 +08:00
|
|
|
#include "utils/builtins.h"
|
2009-08-05 02:49:50 +08:00
|
|
|
#include "utils/bytea.h"
|
2009-03-26 07:20:01 +08:00
|
|
|
#include "utils/cash.h"
|
|
|
|
#include "utils/date.h"
|
|
|
|
#include "utils/inet.h"
|
|
|
|
#include "utils/numeric.h"
|
|
|
|
#include "utils/timestamp.h"
|
|
|
|
#include "utils/varbit.h"
|
|
|
|
|
|
|
|
PG_MODULE_MAGIC;
|
|
|
|
|
|
|
|
typedef struct TypeInfo
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
bool is_varlena;
|
|
|
|
Datum (*leftmostvalue) (void);
|
|
|
|
Datum (*typecmp) (FunctionCallInfo);
|
2009-03-26 07:20:01 +08:00
|
|
|
} TypeInfo;
|
|
|
|
|
|
|
|
typedef struct QueryInfo
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
StrategyNumber strategy;
|
|
|
|
Datum datum;
|
2009-03-26 07:20:01 +08:00
|
|
|
} QueryInfo;
|
|
|
|
|
|
|
|
#define GIN_EXTRACT_VALUE(type) \
|
|
|
|
PG_FUNCTION_INFO_V1(gin_extract_value_##type); \
|
2009-06-11 22:49:15 +08:00
|
|
|
Datum gin_extract_value_##type(PG_FUNCTION_ARGS); \
|
2009-03-26 07:20:01 +08:00
|
|
|
Datum \
|
|
|
|
gin_extract_value_##type(PG_FUNCTION_ARGS) \
|
|
|
|
{ \
|
|
|
|
Datum datum = PG_GETARG_DATUM(0); \
|
|
|
|
int32 *nentries = (int32 *) PG_GETARG_POINTER(1); \
|
|
|
|
Datum *entries = (Datum *) palloc(sizeof(Datum)); \
|
|
|
|
\
|
|
|
|
if ( TypeInfo_##type.is_varlena ) \
|
|
|
|
datum = PointerGetDatum(PG_DETOAST_DATUM(datum)); \
|
|
|
|
entries[0] = datum; \
|
|
|
|
*nentries = 1; \
|
|
|
|
\
|
|
|
|
PG_RETURN_POINTER(entries); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, and
|
|
|
|
* BTEqualStrategyNumber we want to start the index scan at the
|
|
|
|
* supplied query datum, and work forward. For BTLessStrategyNumber
|
|
|
|
* and BTLessEqualStrategyNumber, we need to start at the leftmost
|
|
|
|
* key, and work forward until the supplied query datum (which must be
|
|
|
|
* sent along inside the QueryInfo structure).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define GIN_EXTRACT_QUERY(type) \
|
|
|
|
PG_FUNCTION_INFO_V1(gin_extract_query_##type); \
|
2009-06-11 22:49:15 +08:00
|
|
|
Datum gin_extract_query_##type(PG_FUNCTION_ARGS); \
|
2009-03-26 07:20:01 +08:00
|
|
|
Datum \
|
|
|
|
gin_extract_query_##type(PG_FUNCTION_ARGS) \
|
|
|
|
{ \
|
|
|
|
Datum datum = PG_GETARG_DATUM(0); \
|
|
|
|
int32 *nentries = (int32 *) PG_GETARG_POINTER(1); \
|
|
|
|
StrategyNumber strategy = PG_GETARG_UINT16(2); \
|
|
|
|
bool **partialmatch = (bool **) PG_GETARG_POINTER(3); \
|
2009-06-11 22:49:15 +08:00
|
|
|
Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4); \
|
2009-03-26 07:20:01 +08:00
|
|
|
Datum *entries = (Datum *) palloc(sizeof(Datum)); \
|
|
|
|
QueryInfo *data = (QueryInfo *) palloc(sizeof(QueryInfo)); \
|
|
|
|
bool *ptr_partialmatch; \
|
|
|
|
\
|
|
|
|
*nentries = 1; \
|
|
|
|
ptr_partialmatch = *partialmatch = (bool *) palloc(sizeof(bool)); \
|
|
|
|
*ptr_partialmatch = false; \
|
|
|
|
if ( TypeInfo_##type.is_varlena ) \
|
|
|
|
datum = PointerGetDatum(PG_DETOAST_DATUM(datum)); \
|
|
|
|
data->strategy = strategy; \
|
|
|
|
data->datum = datum; \
|
|
|
|
*extra_data = (Pointer *) palloc(sizeof(Pointer)); \
|
|
|
|
**extra_data = (Pointer) data; \
|
|
|
|
\
|
|
|
|
switch (strategy) \
|
|
|
|
{ \
|
|
|
|
case BTLessStrategyNumber: \
|
|
|
|
case BTLessEqualStrategyNumber: \
|
|
|
|
entries[0] = TypeInfo_##type.leftmostvalue(); \
|
|
|
|
*ptr_partialmatch = true; \
|
|
|
|
break; \
|
|
|
|
case BTGreaterEqualStrategyNumber: \
|
|
|
|
case BTGreaterStrategyNumber: \
|
|
|
|
*ptr_partialmatch = true; \
|
|
|
|
case BTEqualStrategyNumber: \
|
|
|
|
entries[0] = datum; \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
elog(ERROR, "unrecognized strategy number: %d", strategy); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
PG_RETURN_POINTER(entries); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Datum a is a value from extract_query method and for BTLess*
|
|
|
|
* strategy it is a left-most value. So, use original datum from QueryInfo
|
|
|
|
* to decide to stop scanning or not. Datum b is always from index.
|
|
|
|
*/
|
|
|
|
#define GIN_COMPARE_PREFIX(type) \
|
|
|
|
PG_FUNCTION_INFO_V1(gin_compare_prefix_##type); \
|
2009-06-11 22:49:15 +08:00
|
|
|
Datum gin_compare_prefix_##type(PG_FUNCTION_ARGS); \
|
2009-03-26 07:20:01 +08:00
|
|
|
Datum \
|
|
|
|
gin_compare_prefix_##type(PG_FUNCTION_ARGS) \
|
|
|
|
{ \
|
|
|
|
Datum a = PG_GETARG_DATUM(0); \
|
|
|
|
Datum b = PG_GETARG_DATUM(1); \
|
|
|
|
QueryInfo *data = (QueryInfo *) PG_GETARG_POINTER(3); \
|
|
|
|
int32 res, \
|
|
|
|
cmp; \
|
|
|
|
\
|
2011-02-09 05:04:18 +08:00
|
|
|
cmp = DatumGetInt32(DirectFunctionCall2WithCollation( \
|
2009-06-11 22:49:15 +08:00
|
|
|
TypeInfo_##type.typecmp, \
|
2011-02-09 05:04:18 +08:00
|
|
|
DEFAULT_COLLATION_OID, \
|
2009-06-11 22:49:15 +08:00
|
|
|
(data->strategy == BTLessStrategyNumber || \
|
2009-03-26 07:20:01 +08:00
|
|
|
data->strategy == BTLessEqualStrategyNumber) \
|
2009-06-11 22:49:15 +08:00
|
|
|
? data->datum : a, \
|
2009-03-26 07:20:01 +08:00
|
|
|
b)); \
|
|
|
|
\
|
|
|
|
switch (data->strategy) \
|
|
|
|
{ \
|
|
|
|
case BTLessStrategyNumber: \
|
|
|
|
/* If original datum > indexed one then return match */ \
|
|
|
|
if (cmp > 0) \
|
|
|
|
res = 0; \
|
|
|
|
else \
|
|
|
|
res = 1; \
|
|
|
|
break; \
|
|
|
|
case BTLessEqualStrategyNumber: \
|
|
|
|
/* The same except equality */ \
|
|
|
|
if (cmp >= 0) \
|
|
|
|
res = 0; \
|
|
|
|
else \
|
|
|
|
res = 1; \
|
|
|
|
break; \
|
|
|
|
case BTEqualStrategyNumber: \
|
|
|
|
if (cmp != 0) \
|
|
|
|
res = 1; \
|
|
|
|
else \
|
|
|
|
res = 0; \
|
|
|
|
break; \
|
|
|
|
case BTGreaterEqualStrategyNumber: \
|
|
|
|
/* If original datum <= indexed one then return match */ \
|
|
|
|
if (cmp <= 0) \
|
|
|
|
res = 0; \
|
|
|
|
else \
|
|
|
|
res = 1; \
|
|
|
|
break; \
|
|
|
|
case BTGreaterStrategyNumber: \
|
|
|
|
/* If original datum <= indexed one then return match */ \
|
|
|
|
/* If original datum == indexed one then continue scan */ \
|
|
|
|
if (cmp < 0) \
|
|
|
|
res = 0; \
|
|
|
|
else if (cmp == 0) \
|
|
|
|
res = -1; \
|
|
|
|
else \
|
|
|
|
res = 1; \
|
|
|
|
break; \
|
|
|
|
default: \
|
2009-06-11 22:49:15 +08:00
|
|
|
elog(ERROR, "unrecognized strategy number: %d", \
|
2009-03-26 07:20:01 +08:00
|
|
|
data->strategy); \
|
|
|
|
res = 0; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
PG_RETURN_INT32(res); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GIN_SUPPORT(type) \
|
|
|
|
GIN_EXTRACT_VALUE(type) \
|
|
|
|
GIN_EXTRACT_QUERY(type) \
|
|
|
|
GIN_COMPARE_PREFIX(type)
|
|
|
|
|
|
|
|
|
|
|
|
PG_FUNCTION_INFO_V1(gin_btree_consistent);
|
2009-06-11 22:49:15 +08:00
|
|
|
Datum gin_btree_consistent(PG_FUNCTION_ARGS);
|
2009-03-26 07:20:01 +08:00
|
|
|
Datum
|
|
|
|
gin_btree_consistent(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
bool *recheck = (bool *) PG_GETARG_POINTER(5);
|
2009-03-26 07:20:01 +08:00
|
|
|
|
|
|
|
*recheck = false;
|
|
|
|
PG_RETURN_BOOL(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_int2(void)
|
|
|
|
{
|
|
|
|
return Int16GetDatum(SHRT_MIN);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_int2 = {false, leftmostvalue_int2, btint2cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(int2)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_int4(void)
|
|
|
|
{
|
|
|
|
return Int32GetDatum(INT_MIN);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_int4 = {false, leftmostvalue_int4, btint4cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(int4)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_int8(void)
|
|
|
|
{
|
|
|
|
/*
|
2010-01-07 12:53:35 +08:00
|
|
|
* Use sequence's definition to keep compatibility.
|
2009-03-26 07:20:01 +08:00
|
|
|
*/
|
|
|
|
return Int64GetDatum(SEQ_MINVALUE);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_int8 = {false, leftmostvalue_int8, btint8cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(int8)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_float4(void)
|
|
|
|
{
|
|
|
|
return Float4GetDatum(-get_float4_infinity());
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_float4 = {false, leftmostvalue_float4, btfloat4cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(float4)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_float8(void)
|
|
|
|
{
|
|
|
|
return Float8GetDatum(-get_float8_infinity());
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_float8 = {false, leftmostvalue_float8, btfloat8cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(float8)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_money(void)
|
|
|
|
{
|
|
|
|
/*
|
2010-01-07 12:53:35 +08:00
|
|
|
* Use sequence's definition to keep compatibility.
|
2009-03-26 07:20:01 +08:00
|
|
|
*/
|
|
|
|
return Int64GetDatum(SEQ_MINVALUE);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_money = {false, leftmostvalue_money, cash_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(money)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_oid(void)
|
|
|
|
{
|
|
|
|
return ObjectIdGetDatum(0);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_oid = {false, leftmostvalue_oid, btoidcmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(oid)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_timestamp(void)
|
|
|
|
{
|
|
|
|
return TimestampGetDatum(DT_NOBEGIN);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_timestamp = {false, leftmostvalue_timestamp, timestamp_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(timestamp)
|
|
|
|
|
|
|
|
static TypeInfo TypeInfo_timestamptz = {false, leftmostvalue_timestamp, timestamp_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(timestamptz)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_time(void)
|
|
|
|
{
|
|
|
|
return TimeADTGetDatum(0);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_time = {false, leftmostvalue_time, time_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(time)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_timetz(void)
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
TimeTzADT *v = palloc(sizeof(TimeTzADT));
|
2009-03-26 07:20:01 +08:00
|
|
|
|
|
|
|
v->time = 0;
|
2009-06-11 22:49:15 +08:00
|
|
|
v->zone = -24 * 3600; /* XXX is that true? */
|
2009-03-26 07:20:01 +08:00
|
|
|
|
|
|
|
return TimeTzADTPGetDatum(v);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_timetz = {false, leftmostvalue_timetz, timetz_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(timetz)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_date(void)
|
|
|
|
{
|
|
|
|
return DateADTGetDatum(DATEVAL_NOBEGIN);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_date = {false, leftmostvalue_date, date_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(date)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_interval(void)
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
Interval *v = palloc(sizeof(Interval));
|
2009-03-26 07:20:01 +08:00
|
|
|
|
|
|
|
v->time = DT_NOBEGIN;
|
|
|
|
v->day = 0;
|
|
|
|
v->month = 0;
|
|
|
|
return IntervalPGetDatum(v);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_interval = {false, leftmostvalue_interval, interval_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(interval)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_macaddr(void)
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
macaddr *v = palloc0(sizeof(macaddr));
|
2009-03-26 07:20:01 +08:00
|
|
|
|
|
|
|
return MacaddrPGetDatum(v);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_macaddr = {false, leftmostvalue_macaddr, macaddr_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(macaddr)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_inet(void)
|
|
|
|
{
|
|
|
|
return DirectFunctionCall3(inet_in,
|
|
|
|
CStringGetDatum("0.0.0.0/0"),
|
|
|
|
ObjectIdGetDatum(0),
|
|
|
|
Int32GetDatum(-1));
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_inet = {true, leftmostvalue_inet, network_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(inet)
|
|
|
|
|
|
|
|
static TypeInfo TypeInfo_cidr = {true, leftmostvalue_inet, network_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(cidr)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_text(void)
|
|
|
|
{
|
|
|
|
return PointerGetDatum(cstring_to_text_with_len("", 0));
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_text = {true, leftmostvalue_text, bttextcmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(text)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_char(void)
|
|
|
|
{
|
|
|
|
return CharGetDatum(SCHAR_MIN);
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_char = {false, leftmostvalue_char, btcharcmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(char)
|
|
|
|
|
|
|
|
static TypeInfo TypeInfo_bytea = {true, leftmostvalue_text, byteacmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(bytea)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_bit(void)
|
|
|
|
{
|
|
|
|
return DirectFunctionCall3(bit_in,
|
|
|
|
CStringGetDatum(""),
|
|
|
|
ObjectIdGetDatum(0),
|
|
|
|
Int32GetDatum(-1));
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_bit = {true, leftmostvalue_bit, bitcmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(bit)
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_varbit(void)
|
|
|
|
{
|
|
|
|
return DirectFunctionCall3(varbit_in,
|
|
|
|
CStringGetDatum(""),
|
|
|
|
ObjectIdGetDatum(0),
|
|
|
|
Int32GetDatum(-1));
|
|
|
|
}
|
|
|
|
static TypeInfo TypeInfo_varbit = {true, leftmostvalue_varbit, bitcmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(varbit)
|
|
|
|
|
|
|
|
/*
|
2011-01-10 04:24:22 +08:00
|
|
|
* Numeric type hasn't a real left-most value, so we use PointerGetDatum(NULL)
|
|
|
|
* (*not* a SQL NULL) to represent that. We can get away with that because
|
|
|
|
* the value returned by our leftmostvalue function will never be stored in
|
|
|
|
* the index nor passed to anything except our compare and prefix-comparison
|
|
|
|
* functions. The same trick could be used for other pass-by-reference types.
|
2009-03-26 07:20:01 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NUMERIC_IS_LEFTMOST(x) ((x) == NULL)
|
|
|
|
|
|
|
|
PG_FUNCTION_INFO_V1(gin_numeric_cmp);
|
2009-06-11 22:49:15 +08:00
|
|
|
Datum gin_numeric_cmp(PG_FUNCTION_ARGS);
|
2009-03-26 07:20:01 +08:00
|
|
|
|
|
|
|
Datum
|
|
|
|
gin_numeric_cmp(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
Numeric a = (Numeric) PG_GETARG_POINTER(0);
|
|
|
|
Numeric b = (Numeric) PG_GETARG_POINTER(1);
|
|
|
|
int res = 0;
|
2009-03-26 07:20:01 +08:00
|
|
|
|
2009-06-11 22:49:15 +08:00
|
|
|
if (NUMERIC_IS_LEFTMOST(a))
|
2009-03-26 07:20:01 +08:00
|
|
|
{
|
2009-06-11 22:49:15 +08:00
|
|
|
res = (NUMERIC_IS_LEFTMOST(b)) ? 0 : -1;
|
2009-03-26 07:20:01 +08:00
|
|
|
}
|
2009-06-11 22:49:15 +08:00
|
|
|
else if (NUMERIC_IS_LEFTMOST(b))
|
2009-03-26 07:20:01 +08:00
|
|
|
{
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = DatumGetInt32(DirectFunctionCall2(numeric_cmp,
|
|
|
|
NumericGetDatum(a),
|
|
|
|
NumericGetDatum(b)));
|
|
|
|
}
|
|
|
|
|
|
|
|
PG_RETURN_INT32(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Datum
|
|
|
|
leftmostvalue_numeric(void)
|
|
|
|
{
|
|
|
|
return PointerGetDatum(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TypeInfo TypeInfo_numeric = {true, leftmostvalue_numeric, gin_numeric_cmp};
|
2009-06-11 22:49:15 +08:00
|
|
|
|
2009-03-26 07:20:01 +08:00
|
|
|
GIN_SUPPORT(numeric)
|