summaryrefslogtreecommitdiffstats
path: root/src/test/regress/expected/polygon.out
blob: 7a9778e70fd1f2a524ed394cbeb66e11455bd6a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
--
-- POLYGON
--
-- polygon logic
--
CREATE TABLE POLYGON_TBL(f1 polygon);
INSERT INTO POLYGON_TBL(f1) VALUES ('(2.0,0.0),(2.0,4.0),(0.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(3.0,1.0),(3.0,3.0),(1.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(1,2),(3,4),(5,6),(7,8)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(7,8),(5,6),(3,4),(1,2)'); -- Reverse
INSERT INTO POLYGON_TBL(f1) VALUES ('(1,2),(7,8),(5,6),(3,-4)');
-- degenerate polygons
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,0.0)');
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,1.0),(0.0,1.0)');
-- bad polygon input strings
INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
ERROR:  invalid input syntax for type polygon: "0.0"
LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
                                            ^
INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
ERROR:  invalid input syntax for type polygon: "(0.0 0.0"
LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
                                            ^
INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
ERROR:  invalid input syntax for type polygon: "(0,1,2)"
LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
                                            ^
INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
ERROR:  invalid input syntax for type polygon: "(0,1,2,3"
LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
                                            ^
INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
ERROR:  invalid input syntax for type polygon: "asdf"
LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
                                            ^
SELECT * FROM POLYGON_TBL;
             f1             
----------------------------
 ((2,0),(2,4),(0,0))
 ((3,1),(3,3),(1,0))
 ((1,2),(3,4),(5,6),(7,8))
 ((7,8),(5,6),(3,4),(1,2))
 ((1,2),(7,8),(5,6),(3,-4))
 ((0,0))
 ((0,1),(0,1))
(7 rows)

--
-- Test the SP-GiST index
--
CREATE TABLE quad_poly_tbl (id int, p polygon);
INSERT INTO quad_poly_tbl
	SELECT (x - 1) * 100 + y, polygon(circle(point(x * 10, y * 10), 1 + (x + y) % 10))
	FROM generate_series(1, 100) x,
		 generate_series(1, 100) y;
INSERT INTO quad_poly_tbl
	SELECT i, polygon '((200, 300),(210, 310),(230, 290))'
	FROM generate_series(10001, 11000) AS i;
INSERT INTO quad_poly_tbl
	VALUES
		(11001, NULL),
		(11002, NULL),
		(11003, NULL);
CREATE INDEX quad_poly_tbl_idx ON quad_poly_tbl USING spgist(p);
-- get reference results for ORDER BY distance from seq scan
SET enable_seqscan = ON;
SET enable_indexscan = OFF;
SET enable_bitmapscan = OFF;
CREATE TEMP TABLE quad_poly_tbl_ord_seq2 AS
SELECT rank() OVER (ORDER BY p <-> point '123,456') n, p <-> point '123,456' dist, id
FROM quad_poly_tbl WHERE p <@ polygon '((300,300),(400,600),(600,500),(700,200))';
-- check results from index scan
SET enable_seqscan = OFF;
SET enable_indexscan = OFF;
SET enable_bitmapscan = ON;
EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p << polygon '((300,300),(400,600),(600,500),(700,200))';
                                      QUERY PLAN                                       
---------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p << '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p << '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p << polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  3890
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p &< polygon '((300,300),(400,600),(600,500),(700,200))';
                                      QUERY PLAN                                       
---------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p &< '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p &< '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p &< polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  7900
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p && polygon '((300,300),(400,600),(600,500),(700,200))';
                                      QUERY PLAN                                       
---------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p && '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p && '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p && polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
   977
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p &> polygon '((300,300),(400,600),(600,500),(700,200))';
                                      QUERY PLAN                                       
---------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p &> '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p &> '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p &> polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  7000
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p >> polygon '((300,300),(400,600),(600,500),(700,200))';
                                      QUERY PLAN                                       
---------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p >> '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p >> '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p >> polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  2990
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p <<| polygon '((300,300),(400,600),(600,500),(700,200))';
                                       QUERY PLAN                                       
----------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p <<| '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p <<| '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p <<| polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  1890
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p &<| polygon '((300,300),(400,600),(600,500),(700,200))';
                                       QUERY PLAN                                       
----------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p &<| '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p &<| '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p &<| polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  6900
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p |&> polygon '((300,300),(400,600),(600,500),(700,200))';
                                       QUERY PLAN                                       
----------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p |&> '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p |&> '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p |&> polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  9000
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p |>> polygon '((300,300),(400,600),(600,500),(700,200))';
                                       QUERY PLAN                                       
----------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p |>> '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p |>> '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p |>> polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
  3990
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p <@ polygon '((300,300),(400,600),(600,500),(700,200))';
                                      QUERY PLAN                                       
---------------------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p <@ '((300,300),(400,600),(600,500),(700,200))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p <@ '((300,300),(400,600),(600,500),(700,200))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p <@ polygon '((300,300),(400,600),(600,500),(700,200))';
 count 
-------
   831
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p @> polygon '((340,550),(343,552),(341,553))';
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p @> '((340,550),(343,552),(341,553))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p @> '((340,550),(343,552),(341,553))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p @> polygon '((340,550),(343,552),(341,553))';
 count 
-------
     1
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM quad_poly_tbl WHERE p ~= polygon '((200, 300),(210, 310),(230, 290))';
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Aggregate
   ->  Bitmap Heap Scan on quad_poly_tbl
         Recheck Cond: (p ~= '((200,300),(210,310),(230,290))'::polygon)
         ->  Bitmap Index Scan on quad_poly_tbl_idx
               Index Cond: (p ~= '((200,300),(210,310),(230,290))'::polygon)
(5 rows)

SELECT count(*) FROM quad_poly_tbl WHERE p ~= polygon '((200, 300),(210, 310),(230, 290))';
 count 
-------
  1000
(1 row)

-- test ORDER BY distance
SET enable_indexscan = ON;
SET enable_bitmapscan = OFF;
EXPLAIN (COSTS OFF)
SELECT rank() OVER (ORDER BY p <-> point '123,456') n, p <-> point '123,456' dist, id
FROM quad_poly_tbl WHERE p <@ polygon '((300,300),(400,600),(600,500),(700,200))';
                                   QUERY PLAN                                    
---------------------------------------------------------------------------------
 WindowAgg
   ->  Index Scan using quad_poly_tbl_idx on quad_poly_tbl
         Index Cond: (p <@ '((300,300),(400,600),(600,500),(700,200))'::polygon)
         Order By: (p <-> '(123,456)'::point)
(4 rows)

CREATE TEMP TABLE quad_poly_tbl_ord_idx2 AS
SELECT rank() OVER (ORDER BY p <-> point '123,456') n, p <-> point '123,456' dist, id
FROM quad_poly_tbl WHERE p <@ polygon '((300,300),(400,600),(600,500),(700,200))';
SELECT *
FROM quad_poly_tbl_ord_seq2 seq FULL JOIN quad_poly_tbl_ord_idx2 idx
	ON seq.n = idx.n AND seq.id = idx.id AND
		(seq.dist = idx.dist OR seq.dist IS NULL AND idx.dist IS NULL)
WHERE seq.id IS NULL OR idx.id IS NULL;
 n | dist | id | n | dist | id 
---+------+----+---+------+----
(0 rows)

RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
-- test non-error-throwing API for some core types
SELECT pg_input_is_valid('(2.0,0.8,0.1)', 'polygon');
 pg_input_is_valid 
-------------------
 f
(1 row)

SELECT * FROM pg_input_error_info('(2.0,0.8,0.1)', 'polygon');
                        message                         | detail | hint | sql_error_code 
--------------------------------------------------------+--------+------+----------------
 invalid input syntax for type polygon: "(2.0,0.8,0.1)" |        |      | 22P02
(1 row)

SELECT pg_input_is_valid('(2.0,xyz)', 'polygon');
 pg_input_is_valid 
-------------------
 f
(1 row)

SELECT * FROM pg_input_error_info('(2.0,xyz)', 'polygon');
                      message                       | detail | hint | sql_error_code 
----------------------------------------------------+--------+------+----------------
 invalid input syntax for type polygon: "(2.0,xyz)" |        |      | 22P02
(1 row)