From fc75d076a2befef2239941edb29ecd2c18c17dce Mon Sep 17 00:00:00 2001 From: Ivan Panchenko Date: Sun, 14 May 2023 01:33:58 +0300 Subject: [PATCH 1/2] Uncommented tests for experimental spoint3 opclass. Added a small KNN test (for spoint3 opclass). --- Makefile | 12 ++++++------ expected/index_9.5.out | 12 ++++++------ expected/knn.out | 30 ++++++++++++++++++++++++++++++ sql/knn.sql | 10 ++++++++++ 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 expected/knn.out create mode 100644 sql/knn.sql diff --git a/Makefile b/Makefile index 8fc69c3..c556e86 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ REGRESS = init tables points euler circle line ellipse poly path box index \ contains_ops contains_ops_compat bounding_box_gist gnomo healpix \ moc -REGRESS_9_5 = index_9.5 # experimental for spoint3 +REGRESS_9_5 = index_9.5 knn # experimental for spoint3 TESTS = init_test tables points euler circle line ellipse poly path box index \ contains_ops contains_ops_compat bounding_box_gist gnomo healpix \ @@ -81,11 +81,11 @@ has_explain_summary = $(if $(filter-out 9.%,$(pg_version)),y,n) # ## the use of spoint 3 is too experimental and preliminary: -#ifeq ($(pg_version_9_5_plus),y) -# REGRESS += $(REGRESS_9_5) -# TESTS += $(REGRESS_9_5) -# PGS_SQL += $(PGS_SQL_9_5) -#endif +ifeq ($(pg_version_9_5_plus),y) + REGRESS += $(REGRESS_9_5) + TESTS += $(REGRESS_9_5) + PGS_SQL += $(PGS_SQL_9_5) +endif crushtest: REGRESS += $(CRUSH_TESTS) crushtest: installcheck diff --git a/expected/index_9.5.out b/expected/index_9.5.out index 99995f0..dfe9e02 100644 --- a/expected/index_9.5.out +++ b/expected/index_9.5.out @@ -3,10 +3,10 @@ SET enable_seqscan = OFF; SET enable_bitmapscan = OFF; SET enable_indexonlyscan = ON; EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>'; - QUERY PLAN --------------------------------------------------------- + QUERY PLAN +------------------------------------------------------- Aggregate - -> Index Only Scan using spoint3_idx on spheretmp1b + -> Index Scan using spoint3_idx on spheretmp1b Index Cond: (p <@ '<(1 , 1) , 0.3>'::scircle) (3 rows) @@ -17,10 +17,10 @@ EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1), (1 row) EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)'; - QUERY PLAN --------------------------------------------------------- + QUERY PLAN +--------------------------------------------------- Aggregate - -> Index Only Scan using spoint3_idx on spheretmp1b + -> Index Scan using spoint3_idx on spheretmp1b Index Cond: (p = '(3.09 , 1.25)'::spoint) (3 rows) diff --git a/expected/knn.out b/expected/knn.out new file mode 100644 index 0000000..f7d75ae --- /dev/null +++ b/expected/knn.out @@ -0,0 +1,30 @@ +CREATE TABLE points (id int, p spoint, pos int); +INSERT INTO points (id, p) SELECT x, spoint(random()*6.28, (2*random()-1)*1.57) FROM generate_series(1,314159) x; +CREATE INDEX i ON points USING gist (p spoint3); +SET enable_indexscan = true; +EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 10; + QUERY PLAN +------------------------------------------------- + Limit + -> Index Scan using i on points + Order By: (p <-> '(0.2 , 0.3)'::spoint) +(3 rows) + +UPDATE points SET pos = n FROM (SELECT id, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10) sel WHERE points.id = sel.id; +SET enable_indexscan = false; +SELECT pos, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10; + pos | n +-----+---- + 1 | 1 + 2 | 2 + 3 | 3 + 4 | 4 + 5 | 5 + 6 | 6 + 7 | 7 + 8 | 8 + 9 | 9 + 10 | 10 +(10 rows) + +DROP TABLE points; diff --git a/sql/knn.sql b/sql/knn.sql new file mode 100644 index 0000000..76c02c7 --- /dev/null +++ b/sql/knn.sql @@ -0,0 +1,10 @@ +CREATE TABLE points (id int, p spoint, pos int); +INSERT INTO points (id, p) SELECT x, spoint(random()*6.28, (2*random()-1)*1.57) FROM generate_series(1,314159) x; +CREATE INDEX i ON points USING gist (p spoint3); +SET enable_indexscan = true; +EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 10; +UPDATE points SET pos = n FROM (SELECT id, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10) sel WHERE points.id = sel.id; +SET enable_indexscan = false; +SELECT pos, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10; +DROP TABLE points; + From 7d8e47717e20d26ae4c68ac7d4f340ea9cdbbcdb Mon Sep 17 00:00:00 2001 From: Ivan Panchenko Date: Sun, 14 May 2023 09:25:11 +0300 Subject: [PATCH 2/2] Slightly improved tests --- expected/index_9.5.out | 12 ++++++------ expected/knn.out | 12 +++++++++++- sql/knn.sql | 2 ++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/expected/index_9.5.out b/expected/index_9.5.out index dfe9e02..99995f0 100644 --- a/expected/index_9.5.out +++ b/expected/index_9.5.out @@ -3,10 +3,10 @@ SET enable_seqscan = OFF; SET enable_bitmapscan = OFF; SET enable_indexonlyscan = ON; EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>'; - QUERY PLAN -------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------- Aggregate - -> Index Scan using spoint3_idx on spheretmp1b + -> Index Only Scan using spoint3_idx on spheretmp1b Index Cond: (p <@ '<(1 , 1) , 0.3>'::scircle) (3 rows) @@ -17,10 +17,10 @@ EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1), (1 row) EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)'; - QUERY PLAN ---------------------------------------------------- + QUERY PLAN +-------------------------------------------------------- Aggregate - -> Index Scan using spoint3_idx on spheretmp1b + -> Index Only Scan using spoint3_idx on spheretmp1b Index Cond: (p = '(3.09 , 1.25)'::spoint) (3 rows) diff --git a/expected/knn.out b/expected/knn.out index f7d75ae..3cb22af 100644 --- a/expected/knn.out +++ b/expected/knn.out @@ -6,12 +6,22 @@ EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT QUERY PLAN ------------------------------------------------- Limit - -> Index Scan using i on points + -> Index Only Scan using i on points Order By: (p <-> '(0.2 , 0.3)'::spoint) (3 rows) UPDATE points SET pos = n FROM (SELECT id, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10) sel WHERE points.id = sel.id; SET enable_indexscan = false; +SET enable_indexonlyscan = false; +EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 10; + QUERY PLAN +--------------------------------------------------- + Limit + -> Sort + Sort Key: ((p <-> '(0.2 , 0.3)'::spoint)) + -> Seq Scan on points +(4 rows) + SELECT pos, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10; pos | n -----+---- diff --git a/sql/knn.sql b/sql/knn.sql index 76c02c7..e49ddad 100644 --- a/sql/knn.sql +++ b/sql/knn.sql @@ -5,6 +5,8 @@ SET enable_indexscan = true; EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 10; UPDATE points SET pos = n FROM (SELECT id, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10) sel WHERE points.id = sel.id; SET enable_indexscan = false; +SET enable_indexonlyscan = false; +EXPLAIN (costs off) SELECT p <-> spoint (0.2, 0.3) FROM points ORDER BY 1 LIMIT 10; SELECT pos, row_number() OVER (ORDER BY p <-> spoint (0.2, 0.3)) n FROM points ORDER BY p <-> spoint (0.2, 0.3) LIMIT 10; DROP TABLE points;