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
|
\set ECHO none
set_sphere_output_precision
-----------------------------
SET 8
(1 row)
-- without idx
SELECT count(*) FROM spheretmp1 WHERE p @ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
SELECT count(*) FROM spheretmp1 WHERE p = spoint '(3.09 , 1.25)' ;
count
-------
4
(1 row)
SELECT count(*) FROM spheretmp2 WHERE c @ scircle '<(1,1),0.3>';
count
-------
12
(1 row)
SELECT count(*) FROM spheretmp2 WHERE c && scircle '<(1,1),0.3>';
count
-------
48
(1 row)
SELECT count(*) FROM spheretmp3 WHERE b && scircle '<(1,1),0.3>';
count
-------
28
(1 row)
SELECT count(*) FROM spheretmp3 WHERE spoint '(3.09 , 1.25)' @ b ;
count
-------
1
(1 row)
SELECT count(*) FROM spheretmp4 WHERE l @ scircle '<(1,1),0.3>';
count
-------
8
(1 row)
SELECT count(*) FROM spheretmp4 WHERE l && scircle '<(1,1),0.3>';
count
-------
40
(1 row)
-- create idx
CREATE TABLE spheretmp1b AS TABLE spheretmp1;
ANALYZE spheretmp1;
CREATE INDEX aaaidx ON spheretmp1 USING gist ( p );
CREATE INDEX spoint3_idx ON spheretmp1b USING gist (p spoint3);
CREATE INDEX bbbidx ON spheretmp2 USING gist ( c );
CREATE INDEX cccidx ON spheretmp3 USING gist ( b );
CREATE INDEX dddidx ON spheretmp4 USING gist ( l );
--with idx
SET enable_seqscan = OFF ;
SELECT count(*) FROM spheretmp1 WHERE p @ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
SELECT count(*) FROM spheretmp1b WHERE p @ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
SELECT count(*) FROM spheretmp1 WHERE p <@ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
SELECT count(*) FROM spheretmp1 WHERE p = spoint '(3.09 , 1.25)' ;
count
-------
4
(1 row)
SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)' ;
count
-------
4
(1 row)
SELECT count(*) FROM spheretmp2 WHERE c @ scircle '<(1,1),0.3>' ;
count
-------
12
(1 row)
SELECT count(*) FROM spheretmp2 WHERE c && scircle '<(1,1),0.3>' ;
count
-------
48
(1 row)
SELECT count(*) FROM spheretmp3 WHERE b && scircle '<(1,1),0.3>';
count
-------
28
(1 row)
SELECT count(*) FROM spheretmp3 WHERE spoint '(3.09 , 1.25)' @ b ;
count
-------
1
(1 row)
SELECT count(*) FROM spheretmp4 WHERE l @ scircle '<(1,1),0.3>' ;
count
-------
8
(1 row)
SELECT count(*) FROM spheretmp4 WHERE l && scircle '<(1,1),0.3>' ;
count
-------
40
(1 row)
-- test spoint3 operator class with and without index-only scan
SET enable_bitmapscan = OFF;
SET enable_indexonlyscan = ON;
EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>';
QUERY PLAN
--------------------------------------------------------
Aggregate
-> Index Only Scan using spoint3_idx on spheretmp1b
Index Cond: (p <@ '<(1 , 1) , 0.3>'::scircle)
(3 rows)
SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)';
QUERY PLAN
--------------------------------------------------------
Aggregate
-> Index Only Scan using spoint3_idx on spheretmp1b
Index Cond: (p = '(3.09 , 1.25)'::spoint)
(3 rows)
SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)';
count
-------
4
(1 row)
SET enable_indexonlyscan = OFF;
EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>';
QUERY PLAN
-------------------------------------------------------
Aggregate
-> Index Scan using spoint3_idx on spheretmp1b
Index Cond: (p <@ '<(1 , 1) , 0.3>'::scircle)
(3 rows)
SELECT count(*) FROM spheretmp1b WHERE p <@ scircle '<(1,1),0.3>';
count
-------
32
(1 row)
EXPLAIN (COSTS OFF) SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)';
QUERY PLAN
---------------------------------------------------
Aggregate
-> Index Scan using spoint3_idx on spheretmp1b
Index Cond: (p = '(3.09 , 1.25)'::spoint)
(3 rows)
SELECT count(*) FROM spheretmp1b WHERE p = spoint '(3.09 , 1.25)';
count
-------
4
(1 row)
-- test hash opclass
CREATE TABLE spheretmp1c AS TABLE spheretmp1;
SELECT p FROM spheretmp1c WHERE p <@ scircle '<(1,1),0.2>' ORDER BY p::text;
p
---------------
(0.67 , 0.97)
(0.67 , 0.97)
(0.67 , 0.97)
(0.67 , 0.97)
(1.07 , 1.09)
(1.07 , 1.09)
(1.07 , 1.09)
(1.07 , 1.09)
(1.24 , 0.95)
(1.24 , 0.95)
(1.24 , 0.95)
(1.24 , 0.95)
(12 rows)
WITH points AS (SELECT DISTINCT p FROM spheretmp1c WHERE p <@ scircle '<(1,1),0.2>')
SELECT p FROM points ORDER BY p::text;
p
---------------
(0.67 , 0.97)
(1.07 , 1.09)
(1.24 , 0.95)
(3 rows)
CREATE INDEX spheretmp1c_hash_idx ON spheretmp1c USING hash(p);
EXPLAIN (COSTS OFF) SELECT * FROM spheretmp1c WHERE p = '(0.67 , 0.97)';
QUERY PLAN
------------------------------------------------------
Index Scan using spheretmp1c_hash_idx on spheretmp1c
Index Cond: (p = '(0.67 , 0.97)'::spoint)
(2 rows)
|