Commit 4f4bf6b1 authored by Paul Ramsey's avatar Paul Ramsey

#3131, KNN geography still gives ERROR: index returned tuples in wrong order


git-svn-id: http://svn.osgeo.org/postgis/trunk@13582 b70326c6-7e19-0410-871a-916f4a2858ee
parent 64cd5ac7
......@@ -250,15 +250,15 @@ CREATE OPERATOR && (
#if POSTGIS_PGSQL_VERSION >= 95
-- Availability: 2.2.0
CREATE OR REPLACE FUNCTION geography_knn_distance(geography, geography)
CREATE OR REPLACE FUNCTION geography_distance_knn(geography, geography)
RETURNS float8
AS 'MODULE_PATHNAME','geography_distance_uncached'
AS 'MODULE_PATHNAME','geography_distance_knn'
LANGUAGE 'c' IMMUTABLE STRICT
COST 100;
-- Availability: 2.2.0
CREATE OPERATOR <-> (
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_knn_distance,
LEFTARG = geography, RIGHTARG = geography, PROCEDURE = geography_distance_knn,
COMMUTATOR = '<->'
);
......
......@@ -36,6 +36,7 @@
Datum geography_distance(PG_FUNCTION_ARGS);
Datum geography_distance_uncached(PG_FUNCTION_ARGS);
Datum geography_distance_knn(PG_FUNCTION_ARGS);
Datum geography_distance_tree(PG_FUNCTION_ARGS);
Datum geography_dwithin(PG_FUNCTION_ARGS);
Datum geography_dwithin_uncached(PG_FUNCTION_ARGS);
......@@ -50,6 +51,16 @@ Datum geography_project(PG_FUNCTION_ARGS);
Datum geography_azimuth(PG_FUNCTION_ARGS);
Datum geography_segmentize(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(geography_distance_knn);
Datum geography_distance_knn(PG_FUNCTION_ARGS)
{
return DirectFunctionCall3(geography_distance_uncached,
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1),
BoolGetDatum(false));
}
/*
** geography_distance_uncached(GSERIALIZED *g1, GSERIALIZED *g2, double tolerance, boolean use_spheroid)
** returns double distance in meters
......@@ -63,7 +74,7 @@ Datum geography_distance_uncached(PG_FUNCTION_ARGS)
GSERIALIZED *g2 = NULL;
double distance;
double tolerance = FP_TOLERANCE;
bool use_spheroid = true;
bool use_spheroid = false; /* XXX WARNING< CHANGE THIS DO NOT COMMIT */
SPHEROID s;
/* Get our geometry objects loaded into memory. */
......@@ -102,6 +113,8 @@ Datum geography_distance_uncached(PG_FUNCTION_ARGS)
distance = lwgeom_distance_spheroid(lwgeom1, lwgeom2, &s, tolerance);
POSTGIS_DEBUGF(2, "[GIST] '%s' got distance %g", __func__, distance);
/* Clean up */
lwgeom_free(lwgeom1);
lwgeom_free(lwgeom2);
......
......@@ -1062,7 +1062,7 @@ Datum gserialized_gist_geog_distance(PG_FUNCTION_ARGS)
GIDX *entry_box;
double distance;
POSTGIS_DEBUGF(4, "[GIST] '%s' function called", __func__);
POSTGIS_DEBUGF(3, "[GIST] '%s' function called", __func__);
/* We are using '13' as the gist geography distance <-> strategy number */
if ( strategy != 13 )
......@@ -1074,10 +1074,16 @@ Datum gserialized_gist_geog_distance(PG_FUNCTION_ARGS)
/* Null box should never make this far. */
if ( gserialized_datum_get_gidx_p(query_datum, query_box) == LW_FAILURE )
{
POSTGIS_DEBUG(4, "[GIST] null query_gbox_index!");
POSTGIS_DEBUG(2, "[GIST] null query_gbox_index!");
PG_RETURN_FLOAT8(FLT_MAX);
}
/* When we hit leaf nodes, it's time to turn on recheck */
if (GIST_LEAF(entry))
{
*recheck = true;
}
/* Get the entry box */
entry_box = (GIDX*)DatumGetPointer(entry->key);
......@@ -1087,13 +1093,8 @@ Datum gserialized_gist_geog_distance(PG_FUNCTION_ARGS)
/* compare reasonably with the over-the-spheroid distances that */
/* the recheck process will turn up */
distance = WGS84_RADIUS * gidx_distance(entry_box, query_box);
POSTGIS_DEBUGF(2, "[GIST] '%s' got distance %g", __func__, distance);
/* When we hit leaf nodes, it's time to turn on recheck */
if (GIST_LEAF(entry))
{
*recheck = true;
}
PG_RETURN_FLOAT8(distance);
}
#endif
......
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