From: Paul Ramsey Date: Fri, 29 May 2015 21:18:23 +0000 (+0000) Subject: #3131, KNN geography still gives ERROR: index returned tuples in wrong order X-Git-Tag: 2.2.0rc1~433 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f4bf6b157043e43f9cd65bb0e9f247129447928;p=postgis #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 --- diff --git a/postgis/geography.sql.in b/postgis/geography.sql.in index 9e524c248..092de843a 100644 --- a/postgis/geography.sql.in +++ b/postgis/geography.sql.in @@ -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 = '<->' ); diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c index caf8bf2cd..3a0451dc9 100644 --- a/postgis/geography_measurement.c +++ b/postgis/geography_measurement.c @@ -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); diff --git a/postgis/gserialized_gist_nd.c b/postgis/gserialized_gist_nd.c index 84d26db33..c2d7c0575 100644 --- a/postgis/gserialized_gist_nd.c +++ b/postgis/gserialized_gist_nd.c @@ -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