From 35fcb1b3d038a501f3f4c87c05630095abaaadab Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 15 May 2015 14:26:51 +0300 Subject: Allow GiST distance function to return merely a lower-bound. The distance function can now set *recheck = false, like index quals. The executor will then re-check the ORDER BY expressions, and use a queue to reorder the results on the fly. This makes it possible to do kNN-searches on polygons and circles, which don't store the exact value in the index, but just a bounding box. Alexander Korotkov and me --- doc/src/sgml/gist.sgml | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'doc/src/sgml/gist.sgml') diff --git a/doc/src/sgml/gist.sgml b/doc/src/sgml/gist.sgml index e7d1ff9d83f..1291f8dd0c8 100644 --- a/doc/src/sgml/gist.sgml +++ b/doc/src/sgml/gist.sgml @@ -105,6 +105,7 @@ ~= + <-> @@ -163,6 +164,7 @@ ~= + <-> @@ -206,6 +208,12 @@ + + Currently, ordering by the distance operator <-> + is supported only with point by the operator classes + of the geometric types. + + For historical reasons, the inet_ops operator class is not the default class for types inet and cidr. @@ -780,6 +788,7 @@ my_distance(PG_FUNCTION_ARGS) data_type *query = PG_GETARG_DATA_TYPE_P(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); /* Oid subtype = PG_GETARG_OID(3); */ + /* bool *recheck = (bool *) PG_GETARG_POINTER(4); */ data_type *key = DatumGetDataType(entry->key); double retval; @@ -792,14 +801,24 @@ my_distance(PG_FUNCTION_ARGS) The arguments to the distance function are identical to - the arguments of the consistent function, except that no - recheck flag is used. The distance to a leaf index entry must always - be determined exactly, since there is no way to re-order the tuples - once they are returned. Some approximation is allowed when determining - the distance to an internal tree node, so long as the result is never - greater than any child's actual distance. Thus, for example, distance - to a bounding box is usually sufficient in geometric applications. The - result value can be any finite float8 value. (Infinity and + the arguments of the consistent function. + + + + Some approximation is allowed when determining the distance, as long as + the result is never greater than the entry's actual distance. Thus, for + example, distance to a bounding box is usually sufficient in geometric + applications. For an internal tree node, the distance returned must not + be greater than the distance to any of the child nodes. If the returned + distance is not accurate, the function must set *recheck to false. (This + is not necessary for internal tree nodes; for them, the calculation is + always assumed to be inaccurate). The executor will calculate the + accurate distance after fetching the tuple from the heap, and reorder + the tuples if necessary. + + + + The result value can be any finite float8 value. (Infinity and minus infinity are used internally to handle cases such as nulls, so it is not recommended that distance functions return these values.) -- cgit v1.2.3