Commit f7ce316d authored by Regina Obe's avatar Regina Obe

#2703 knn_recheck regress tests -- will currently fail -- exercises issue...

#2703 knn_recheck regress tests -- will currently fail -- exercises issue nicklas brought up in -devel

git-svn-id: http://svn.osgeo.org/postgis/[email protected] b70326c6-7e19-0410-871a-916f4a2858ee
parent f2047f3f
......@@ -141,6 +141,11 @@ ifeq ($(shell expr $(POSTGIS_PGSQL_VERSION) ">=" 91),1)
TESTS += knn
endif
ifeq ($(shell expr $(POSTGIS_PGSQL_VERSION) ">=" 95),1)
# Index supported KNN recheck only available in PostgreSQL 9.5 and higher
TESTS += knn_recheck
endif
ifeq ($(shell expr $(POSTGIS_GEOS_VERSION) ">=" 32),1)
# GEOS-3.3 adds:
# ST_HausdorffDistance, ST_Buffer(params)
......
-- create table
CREATE TABLE knn_recheck_geom(gid serial primary key, geom geometry);
INSERT INTO knn_recheck_geom(gid,geom)
SELECT ROW_NUMBER() OVER(ORDER BY x,y) AS gid, ST_Point(x*0.777,y*0.777) As geom
FROM generate_series(-100,100, 1) AS x CROSS JOIN generate_series(-300,10000,10) As y;
INSERT INTO knn_recheck_geom(gid, geom)
SELECT 500000, 'LINESTRING(100 300, -10 700, 400 123, -300 10000)'::geometry;
INSERT INTO knn_recheck_geom(gid, geom)
SELECT 500001, 'POLYGON((100 3000, -10 700, 400 123, 405 124, 100 3000))'::geometry;
INSERT INTO knn_recheck_geom(gid,geom)
SELECT 600000 + ROW_NUMBER() OVER(ORDER BY gid) AS gid, ST_Buffer(geom,1000,2) As geom
FROM knn_recheck_geom
WHERE gid IN(1000, 10000, 2000, 40000);
-- without index order should match st_distance order --
-- point check
SELECT gid, RANK() OVER(ORDER BY ST_Distance( 'POINT(200 1000)'::geometry, geom) )
FROM knn_recheck_geom
ORDER BY 'POINT(200 1000)'::geometry <-> geom LIMIT 5;
-- linestring check
SELECT gid, RANK() OVER(ORDER BY ST_Distance( 'LINESTRING(200 100, -10 600)'::geometry, geom) )
FROM knn_recheck_geom
ORDER BY 'LINESTRING(200 100, -10 600)'::geometry <-> geom LIMIT 5;
-- lateral check before index
SELECT a.gid, b.gid As match, RANK() OVER(PARTITION BY a.gid ORDER BY ST_Distance(a.geom, b.geom) ) As true_rn, b.rn As knn_rn
FROM knn_recheck_geom As a
LEFT JOIN
LATERAL ( SELECT gid, geom, RANK() OVER(ORDER BY a.geom <-> g.geom) As rn
FROM knn_recheck_geom As g WHERE a.gid <> g.gid ORDER BY a.geom <-> g.geom LIMIT 5) As b ON true
WHERE a.gid IN(50000,50001,70000,61000)
ORDER BY a.gid, b.rn;
-- create index and repeat
CREATE INDEX idx_knn_recheck_geom_gist ON knn_recheck_geom USING gist(geom);
-- point check after index
SELECT gid, RANK() OVER(ORDER BY ST_Distance( 'POINT(200 1000)'::geometry, geom) )
FROM knn_recheck_geom
ORDER BY 'POINT(200 1000)'::geometry <-> geom LIMIT 5;
-- lateral check after index - currently is wrong
SELECT a.gid, b.gid As match, RANK() OVER(PARTITION BY a.gid ORDER BY ST_Distance(a.geom, b.geom) ) As true_rn, b.rn As knn_rn
FROM knn_recheck_geom As a
LEFT JOIN
LATERAL ( SELECT gid, geom, RANK() OVER(ORDER BY a.geom <-> g.geom) As rn
FROM knn_recheck_geom As g WHERE a.gid <> g.gid ORDER BY a.geom <-> g.geom LIMIT 5) As b ON true
WHERE a.gid IN(50000,50001,70000,61000)
ORDER BY a.gid, b.rn;
DROP TABLE knn_recheck_geom;
\ No newline at end of file
500001|1
206360|2
206359|3
206361|4
206358|5
500000|1
134128|2
199066|3
155774|4
112482|5
50000|48969|1|1
50000|51031|2|2
50000|47938|3|3
50000|52062|4|4
50000|46907|5|5
50001|48970|1|1
50001|51032|2|2
50001|47939|3|3
50001|52063|4|4
50001|46908|5|5
61000|62031|1|1
61000|59969|1|1
61000|63062|3|3
61000|58938|4|4
61000|64093|5|5
70000|600001|1|1
70000|600002|1|1
70000|600004|1|1
70000|71031|4|4
70000|68969|5|5
500001|1
206360|2
206359|3
206361|4
206358|5
50000|48969|1|1
50000|51031|2|2
50000|47938|3|3
50000|52062|4|4
50000|46907|5|5
50001|53093|5|1
50001|48970|1|2
50001|51032|2|3
50001|47939|3|4
50001|52063|4|5
61000|62031|1|1
61000|59969|1|1
61000|63062|3|3
61000|58938|4|4
61000|46908|5|5
70000|600001|1|1
70000|600002|1|1
70000|600004|1|1
70000|71031|4|4
70000|68969|5|5
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