mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Add KNNGIST support to contrib/btree_gist.
This extends GiST's support for nearest-neighbor searches to many of the standard data types. Teodor Sigaev
This commit is contained in:
@ -17,6 +17,7 @@ PG_FUNCTION_INFO_V1(gbt_float8_compress);
|
||||
PG_FUNCTION_INFO_V1(gbt_float8_union);
|
||||
PG_FUNCTION_INFO_V1(gbt_float8_picksplit);
|
||||
PG_FUNCTION_INFO_V1(gbt_float8_consistent);
|
||||
PG_FUNCTION_INFO_V1(gbt_float8_distance);
|
||||
PG_FUNCTION_INFO_V1(gbt_float8_penalty);
|
||||
PG_FUNCTION_INFO_V1(gbt_float8_same);
|
||||
|
||||
@ -24,6 +25,7 @@ Datum gbt_float8_compress(PG_FUNCTION_ARGS);
|
||||
Datum gbt_float8_union(PG_FUNCTION_ARGS);
|
||||
Datum gbt_float8_picksplit(PG_FUNCTION_ARGS);
|
||||
Datum gbt_float8_consistent(PG_FUNCTION_ARGS);
|
||||
Datum gbt_float8_distance(PG_FUNCTION_ARGS);
|
||||
Datum gbt_float8_penalty(PG_FUNCTION_ARGS);
|
||||
Datum gbt_float8_same(PG_FUNCTION_ARGS);
|
||||
|
||||
@ -71,6 +73,19 @@ gbt_float8key_cmp(const void *a, const void *b)
|
||||
return (ia->lower > ib->lower) ? 1 : -1;
|
||||
}
|
||||
|
||||
static float8
|
||||
gbt_float8_dist(const void *a, const void *b)
|
||||
{
|
||||
float8 arg1 = *(const float8 *)a;
|
||||
float8 arg2 = *(const float8 *)b;
|
||||
float8 r;
|
||||
|
||||
r = arg1 - arg2;
|
||||
CHECKFLOATVAL(r, isinf(arg1) || isinf(arg2), true);
|
||||
|
||||
return Abs(r);
|
||||
}
|
||||
|
||||
|
||||
static const gbtree_ninfo tinfo =
|
||||
{
|
||||
@ -81,10 +96,26 @@ static const gbtree_ninfo tinfo =
|
||||
gbt_float8eq,
|
||||
gbt_float8le,
|
||||
gbt_float8lt,
|
||||
gbt_float8key_cmp
|
||||
gbt_float8key_cmp,
|
||||
gbt_float8_dist
|
||||
};
|
||||
|
||||
|
||||
PG_FUNCTION_INFO_V1(float8_dist);
|
||||
Datum float8_dist(PG_FUNCTION_ARGS);
|
||||
Datum
|
||||
float8_dist(PG_FUNCTION_ARGS)
|
||||
{
|
||||
float8 a = PG_GETARG_FLOAT8(0);
|
||||
float8 b = PG_GETARG_FLOAT8(1);
|
||||
float8 r;
|
||||
|
||||
r = a - b;
|
||||
CHECKFLOATVAL(r, isinf(a) || isinf(b), true);
|
||||
|
||||
PG_RETURN_FLOAT8( Abs(r) );
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
* float8 ops
|
||||
**************************************************/
|
||||
@ -124,6 +155,25 @@ gbt_float8_consistent(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
gbt_float8_distance(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
float8 query = PG_GETARG_FLOAT8(1);
|
||||
|
||||
/* Oid subtype = PG_GETARG_OID(3); */
|
||||
float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
|
||||
GBT_NUMKEY_R key;
|
||||
|
||||
key.lower = (GBT_NUMKEY *) &kkk->lower;
|
||||
key.upper = (GBT_NUMKEY *) &kkk->upper;
|
||||
|
||||
PG_RETURN_FLOAT8(
|
||||
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
gbt_float8_union(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
Reference in New Issue
Block a user