]> granicus.if.org Git - postgis/commitdiff
#3131, KNN geography still gives ERROR: index returned tuples in wrong order
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 29 May 2015 21:18:23 +0000 (21:18 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 29 May 2015 21:18:23 +0000 (21:18 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13582 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geography.sql.in
postgis/geography_measurement.c
postgis/gserialized_gist_nd.c

index 9e524c24893063374e491a3db2a4c9024efb7069..092de843a5e369f2c0bcbf3811910660e93f18a0 100644 (file)
@@ -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 = '<->'
 );
 
index caf8bf2cdeb30836362e6eb85ae722cc53d1d52c..3a0451dc947ab93fd22bac5b17e0ebaf381f1689 100644 (file)
@@ -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);
index 84d26db330d466c47b7e06f0e33c8cf9b6891a19..c2d7c0575ef64c8d62d5b0438dbb6179cf9d5b42 100644 (file)
@@ -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