]> granicus.if.org Git - postgis/commitdiff
Only run KNN tests when building against PostgreSQL 9.1+
authorSandro Santilli <strk@keybit.net>
Tue, 24 Feb 2015 10:20:33 +0000 (10:20 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 24 Feb 2015 10:20:33 +0000 (10:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13281 b70326c6-7e19-0410-871a-916f4a2858ee

regress/Makefile.in
regress/knn.sql [new file with mode: 0644]
regress/knn_expected [new file with mode: 0644]
regress/regress_index.sql
regress/regress_index_expected

index c51065e45eacac8043eca18b9d1b563d9d2cb0a8..435f53343ddabe6bac5c2226ca92bdbc7ecb1554 100644 (file)
@@ -134,6 +134,11 @@ TESTS = \
        concave_hull\
        twkb
 
+ifeq ($(shell expr $(POSTGIS_PGSQL_VERSION) ">=" 91),1)
+  # Index supported KNN only available in PostgreSQL 9.1 and higher
+       TESTS += knn
+endif
+
 ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 32),1)
        # GEOS-3.3 adds:
        # ST_HausdorffDistance, ST_Buffer(params)
diff --git a/regress/knn.sql b/regress/knn.sql
new file mode 100644 (file)
index 0000000..1a52948
--- /dev/null
@@ -0,0 +1,43 @@
+CREATE OR REPLACE FUNCTION qnodes(q text) RETURNS text
+LANGUAGE 'plpgsql' AS
+$$
+DECLARE
+  exp TEXT;
+  mat TEXT[];
+  ret TEXT[];
+BEGIN
+  FOR exp IN EXECUTE 'EXPLAIN ' || q
+  LOOP
+    --RAISE NOTICE 'EXP: %', exp;
+    mat := regexp_matches(exp, ' *(?:-> *)?(.*Scan)');
+    --RAISE NOTICE 'MAT: %', mat;
+    IF mat IS NOT NULL THEN
+      ret := array_append(ret, mat[1]);
+    END IF;
+    --RAISE NOTICE 'RET: %', ret;
+  END LOOP;
+  RETURN array_to_string(ret,',');
+END;
+$$;
+
+\i regress_lots_of_points.sql
+CREATE INDEX on test using gist (the_geom);
+
+-- Index-supported KNN query
+
+SELECT '<-> idx', qnodes('select * from test order by the_geom <-> ST_MakePoint(0,0)');
+SELECT '<-> res1',num,
+  (the_geom <-> 'LINESTRING(0 0,5 5)'::geometry)::numeric(10,2),
+  ST_astext(the_geom) from test
+  order by the_geom <-> 'LINESTRING(0 0,5 5)'::geometry LIMIT 1;
+
+-- Full table extent: BOX(0.0439142361 0.0197799355,999.955261 999.993652)
+SELECT '<#> idx', qnodes('select * from test order by the_geom <#> ST_MakePoint(0,0)');
+SELECT '<#> res1',num,
+  (the_geom <#> 'LINESTRING(1000 0,1005 5)'::geometry)::numeric(10,2),
+  ST_astext(the_geom) from test
+  order by the_geom <#> 'LINESTRING(1000 0,1005 5)'::geometry LIMIT 1;
+
+DROP FUNCTION qnodes(text);
+
+DROP TABLE test;
diff --git a/regress/knn_expected b/regress/knn_expected
new file mode 100644 (file)
index 0000000..5a63f27
--- /dev/null
@@ -0,0 +1,4 @@
+<-> idx|Index Scan
+<-> res1|48589|0.17|POINT(2.33793712 2.44566727)
+<#> idx|Index Scan
+<#> res1|2057|0.83|POINT(999.173279 3.92185807)
index 2837d14dea4148ab93d741aa35d08cfc67e16bb7..aea23ae84500ff0a985e30b264e3e85588b5e47a 100644 (file)
@@ -43,21 +43,6 @@ set enable_seqscan = off;
 SELECT 'scan_seq', qnodes('select * from test where the_geom && ST_MakePoint(0,0)');
  select num,ST_astext(the_geom) from test where the_geom && 'BOX3D(125 125,135 135)'::box3d order by num;
 
--- Index-supported KNN query
-
-SELECT '<-> idx', qnodes('select * from test order by the_geom <-> ST_MakePoint(0,0)');
-SELECT '<-> res1',num,
-  (the_geom <-> 'LINESTRING(0 0,5 5)'::geometry)::numeric(10,2),
-  ST_astext(the_geom) from test
-  order by the_geom <-> 'LINESTRING(0 0,5 5)'::geometry LIMIT 1;
-
--- Full table extent: BOX(0.0439142361 0.0197799355,999.955261 999.993652)
-SELECT '<#> idx', qnodes('select * from test order by the_geom <#> ST_MakePoint(0,0)');
-SELECT '<#> res1',num,
-  (the_geom <#> 'LINESTRING(1000 0,1005 5)'::geometry)::numeric(10,2),
-  ST_astext(the_geom) from test
-  order by the_geom <#> 'LINESTRING(1000 0,1005 5)'::geometry LIMIT 1;
-
 CREATE FUNCTION estimate_error(qry text, tol int)
 RETURNS text
 LANGUAGE 'plpgsql' VOLATILE AS $$
index 52f5dd1ff731e9c1c4a8283f9d523a7490e4aa71..ae75d050d1ea94010f4dc83d2ff715da6f88c6f0 100644 (file)
@@ -6,10 +6,6 @@ scan_seq|Index Scan
 2594|POINT(130.504303 126.53112)
 3618|POINT(130.447205 131.655289)
 7245|POINT(128.10466 130.94133)
-<-> idx|Index Scan
-<-> res1|48589|0.17|POINT(2.33793712 2.44566727)
-<#> idx|Index Scan
-<#> res1|2057|0.83|POINT(999.173279 3.92185807)
 3+=5:true
 924+=60:true
 12621+=500:true