2000-01-05 07:07:58 +01:00
|
|
|
--
|
|
|
|
-- POINT
|
|
|
|
--
|
1997-04-05 13:26:55 +02:00
|
|
|
|
|
|
|
CREATE TABLE POINT_TBL(f1 point);
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(0.0,0.0)');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(-10.0,0.0)');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(-3.0,4.0)');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(5.1, 34.5)');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(-5.0,-12.0)');
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- bad format points
|
1997-04-05 13:26:55 +02:00
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('asdfasdf');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('10.0,10.0');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(10.0 10.0)');
|
|
|
|
|
|
|
|
INSERT INTO POINT_TBL(f1) VALUES ('(10.0,10.0');
|
|
|
|
|
|
|
|
|
2005-04-07 03:51:41 +02:00
|
|
|
SELECT '' AS six, * FROM POINT_TBL;
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- left of
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS three, p.* FROM POINT_TBL p WHERE p.f1 << '(0.0, 0.0)';
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- right of
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS three, p.* FROM POINT_TBL p WHERE '(0.0,0.0)' >> p.f1;
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- above
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS one, p.* FROM POINT_TBL p WHERE '(0.0,0.0)' >^ p.f1;
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- below
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS one, p.* FROM POINT_TBL p WHERE p.f1 <^ '(0.0, 0.0)';
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- equal
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS one, p.* FROM POINT_TBL p WHERE p.f1 ~= '(5.1, 34.5)';
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
-- point in box
|
1997-04-27 04:58:38 +02:00
|
|
|
SELECT '' AS three, p.* FROM POINT_TBL p
|
2006-09-10 02:29:35 +02:00
|
|
|
WHERE p.f1 <@ box '(0,0,100,100)';
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-01-14 17:31:09 +01:00
|
|
|
SELECT '' AS three, p.* FROM POINT_TBL p
|
|
|
|
WHERE box '(0,0,100,100)' @> p.f1;
|
|
|
|
|
1997-04-05 13:26:55 +02:00
|
|
|
SELECT '' AS three, p.* FROM POINT_TBL p
|
2006-09-10 02:29:35 +02:00
|
|
|
WHERE not p.f1 <@ box '(0,0,100,100)';
|
1997-04-05 13:26:55 +02:00
|
|
|
|
|
|
|
SELECT '' AS two, p.* FROM POINT_TBL p
|
2006-09-10 02:29:35 +02:00
|
|
|
WHERE p.f1 <@ path '[(0,0),(-10,0),(-10,10)]';
|
1997-04-05 13:26:55 +02:00
|
|
|
|
2010-01-14 17:31:09 +01:00
|
|
|
SELECT '' AS three, p.* FROM POINT_TBL p
|
|
|
|
WHERE not box '(0,0,100,100)' @> p.f1;
|
|
|
|
|
2000-01-05 07:07:58 +01:00
|
|
|
SELECT '' AS six, p.f1, p.f1 <-> point '(0,0)' AS dist
|
1997-05-11 17:42:09 +02:00
|
|
|
FROM POINT_TBL p
|
|
|
|
ORDER BY dist;
|
1997-04-05 13:26:55 +02:00
|
|
|
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS thirtysix, p1.f1 AS point1, p2.f1 AS point2, p1.f1 <-> p2.f1 AS dist
|
1997-05-11 17:42:09 +02:00
|
|
|
FROM POINT_TBL p1, POINT_TBL p2
|
2007-01-09 03:14:16 +01:00
|
|
|
ORDER BY dist, p1.f1[0], p2.f1[0];
|
1997-05-11 17:42:09 +02:00
|
|
|
|
|
|
|
SELECT '' AS thirty, p1.f1 AS point1, p2.f1 AS point2
|
1997-04-05 13:26:55 +02:00
|
|
|
FROM POINT_TBL p1, POINT_TBL p2
|
1997-07-29 18:22:48 +02:00
|
|
|
WHERE (p1.f1 <-> p2.f1) > 3;
|
1997-04-05 13:26:55 +02:00
|
|
|
|
1997-05-11 17:42:09 +02:00
|
|
|
-- put distance result into output to allow sorting with GEQ optimizer - tgl 97/05/10
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS fifteen, p1.f1 AS point1, p2.f1 AS point2, (p1.f1 <-> p2.f1) AS distance
|
1997-04-05 13:26:55 +02:00
|
|
|
FROM POINT_TBL p1, POINT_TBL p2
|
1997-07-29 18:22:48 +02:00
|
|
|
WHERE (p1.f1 <-> p2.f1) > 3 and p1.f1 << p2.f1
|
2007-01-09 03:14:16 +01:00
|
|
|
ORDER BY distance, p1.f1[0], p2.f1[0];
|
1997-04-05 13:26:55 +02:00
|
|
|
|
1997-05-11 17:42:09 +02:00
|
|
|
-- put distance result into output to allow sorting with GEQ optimizer - tgl 97/05/10
|
1997-07-29 18:22:48 +02:00
|
|
|
SELECT '' AS three, p1.f1 AS point1, p2.f1 AS point2, (p1.f1 <-> p2.f1) AS distance
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM POINT_TBL p1, POINT_TBL p2
|
1997-07-29 18:22:48 +02:00
|
|
|
WHERE (p1.f1 <-> p2.f1) > 3 and p1.f1 << p2.f1 and p1.f1 >^ p2.f1
|
1997-05-11 17:42:09 +02:00
|
|
|
ORDER BY distance;
|
Fix gist_box_same and gist_point_consistent to handle fuzziness correctly.
While there's considerable doubt that we want fuzzy behavior in the
geometric operators at all (let alone as currently implemented), nobody is
stepping forward to redesign that stuff. In the meantime it behooves us
to make sure that index searches agree with the behavior of the underlying
operators. This patch fixes two problems in this area.
First, gist_box_same was using fuzzy equality, but it really needs to use
exact equality to prevent not-quite-identical upper index keys from being
treated as identical, which for example would prevent an existing upper
key from being extended by an amount less than epsilon. This would result
in inconsistent indexes. (The next release notes will need to recommend
that users reindex GiST indexes on boxes, polygons, circles, and points,
since all four opclasses use gist_box_same.)
Second, gist_point_consistent used exact comparisons for upper-page
comparisons in ~= searches, when it needs to use fuzzy comparisons to
ensure it finds all matches; and it used fuzzy comparisons for point <@ box
searches, when it needs to use exact comparisons because that's what the
<@ operator (rather inconsistently) does.
The added regression test cases illustrate all three misbehaviors.
Back-patch to all active branches. (8.4 did not have GiST point_ops,
but it still seems prudent to apply the gist_box_same patch to it.)
Alexander Korotkov, reviewed by Noah Misch
2013-02-09 00:03:17 +01:00
|
|
|
|
|
|
|
-- Test that GiST indexes provide same behavior as sequential scan
|
|
|
|
CREATE TEMP TABLE point_gist_tbl(f1 point);
|
|
|
|
INSERT INTO point_gist_tbl SELECT '(0,0)' FROM generate_series(0,1000);
|
|
|
|
CREATE INDEX point_gist_tbl_index ON point_gist_tbl USING gist (f1);
|
|
|
|
INSERT INTO point_gist_tbl VALUES ('(0.0000009,0.0000009)');
|
|
|
|
SET enable_seqscan TO true;
|
|
|
|
SET enable_indexscan TO false;
|
|
|
|
SET enable_bitmapscan TO false;
|
|
|
|
SELECT COUNT(*) FROM point_gist_tbl WHERE f1 ~= '(0.0000009,0.0000009)'::point;
|
|
|
|
SELECT COUNT(*) FROM point_gist_tbl WHERE f1 <@ '(0.0000009,0.0000009),(0.0000009,0.0000009)'::box;
|
|
|
|
SELECT COUNT(*) FROM point_gist_tbl WHERE f1 ~= '(0.0000018,0.0000018)'::point;
|
|
|
|
SET enable_seqscan TO false;
|
|
|
|
SET enable_indexscan TO true;
|
|
|
|
SET enable_bitmapscan TO true;
|
|
|
|
SELECT COUNT(*) FROM point_gist_tbl WHERE f1 ~= '(0.0000009,0.0000009)'::point;
|
|
|
|
SELECT COUNT(*) FROM point_gist_tbl WHERE f1 <@ '(0.0000009,0.0000009),(0.0000009,0.0000009)'::box;
|
|
|
|
SELECT COUNT(*) FROM point_gist_tbl WHERE f1 ~= '(0.0000018,0.0000018)'::point;
|
|
|
|
RESET enable_seqscan;
|
|
|
|
RESET enable_indexscan;
|
|
|
|
RESET enable_bitmapscan;
|