@@ -203,6 +203,82 @@ select b from gist_tbl where b <@ box(point(5,5), point(6,6));
203203 (6,6),(6,6)
204204(21 rows)
205205
206+ -- Also test an index-only knn-search
207+ explain (costs off)
208+ select b from gist_tbl where b <@ box(point(5,5), point(6,6))
209+ order by b <-> point(5.2, 5.91);
210+ QUERY PLAN
211+ ------------------------------------------------------
212+ Index Only Scan using gist_tbl_box_index on gist_tbl
213+ Index Cond: (b <@ '(6,6),(5,5)'::box)
214+ Order By: (b <-> '(5.2,5.91)'::point)
215+ (3 rows)
216+
217+ select b from gist_tbl where b <@ box(point(5,5), point(6,6))
218+ order by b <-> point(5.2, 5.91);
219+ b
220+ -------------------------
221+ (5.55,5.55),(5.55,5.55)
222+ (5.6,5.6),(5.6,5.6)
223+ (5.5,5.5),(5.5,5.5)
224+ (5.65,5.65),(5.65,5.65)
225+ (5.45,5.45),(5.45,5.45)
226+ (5.7,5.7),(5.7,5.7)
227+ (5.4,5.4),(5.4,5.4)
228+ (5.75,5.75),(5.75,5.75)
229+ (5.35,5.35),(5.35,5.35)
230+ (5.8,5.8),(5.8,5.8)
231+ (5.3,5.3),(5.3,5.3)
232+ (5.85,5.85),(5.85,5.85)
233+ (5.25,5.25),(5.25,5.25)
234+ (5.9,5.9),(5.9,5.9)
235+ (5.2,5.2),(5.2,5.2)
236+ (5.95,5.95),(5.95,5.95)
237+ (5.15,5.15),(5.15,5.15)
238+ (6,6),(6,6)
239+ (5.1,5.1),(5.1,5.1)
240+ (5.05,5.05),(5.05,5.05)
241+ (5,5),(5,5)
242+ (21 rows)
243+
244+ -- Check commuted case as well
245+ explain (costs off)
246+ select b from gist_tbl where b <@ box(point(5,5), point(6,6))
247+ order by point(5.2, 5.91) <-> b;
248+ QUERY PLAN
249+ ------------------------------------------------------
250+ Index Only Scan using gist_tbl_box_index on gist_tbl
251+ Index Cond: (b <@ '(6,6),(5,5)'::box)
252+ Order By: (b <-> '(5.2,5.91)'::point)
253+ (3 rows)
254+
255+ select b from gist_tbl where b <@ box(point(5,5), point(6,6))
256+ order by point(5.2, 5.91) <-> b;
257+ b
258+ -------------------------
259+ (5.55,5.55),(5.55,5.55)
260+ (5.6,5.6),(5.6,5.6)
261+ (5.5,5.5),(5.5,5.5)
262+ (5.65,5.65),(5.65,5.65)
263+ (5.45,5.45),(5.45,5.45)
264+ (5.7,5.7),(5.7,5.7)
265+ (5.4,5.4),(5.4,5.4)
266+ (5.75,5.75),(5.75,5.75)
267+ (5.35,5.35),(5.35,5.35)
268+ (5.8,5.8),(5.8,5.8)
269+ (5.3,5.3),(5.3,5.3)
270+ (5.85,5.85),(5.85,5.85)
271+ (5.25,5.25),(5.25,5.25)
272+ (5.9,5.9),(5.9,5.9)
273+ (5.2,5.2),(5.2,5.2)
274+ (5.95,5.95),(5.95,5.95)
275+ (5.15,5.15),(5.15,5.15)
276+ (6,6),(6,6)
277+ (5.1,5.1),(5.1,5.1)
278+ (5.05,5.05),(5.05,5.05)
279+ (5,5),(5,5)
280+ (21 rows)
281+
206282drop index gist_tbl_box_index;
207283-- Test that an index-only scan is not chosen, when the query involves the
208284-- circle column (the circle opclass does not support index-only scans).
0 commit comments