1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
CREATE TABLE test_geo AS SELECT BOX( POINT( x,y ), POINT( x,y ) ) AS coords FROM (SELECT random() x, random() y FROM generate_series( 1,1000000 ) s ) foo;
VACUUM test_geo;
EXPLAIN ANALYZE SELECT count(*) FROM test_geo WHERE coords && '((0.5,0.5),(0.51,0.51))'::BOX;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------
Aggregate (cost=19865.60..19865.61 rows=1 width=0) (actual time=136.094..136.095 rows=1 loops=1)
-> Seq Scan on test_geo (cost=0.00..19853.10 rows=5000 width=0) (actual time=0.393..136.064 rows=98 loops=1)
Filter: (coords && '(0.51,0.51),(0.5,0.5)'::box)
Total runtime: 136.134 ms
(4 lignes)
CREATE INDEX test_geo_coords ON test_geo USING gist( coords );
EXPLAIN ANALYZE SELECT count(*) FROM test_geo WHERE coords && '((0.5,0.5),(0.51,0.51))'::BOX;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=7242.06..7242.07 rows=1 width=0) (actual time=0.522..0.522 rows=1 loops=1)
-> Bitmap Heap Scan on test_geo (cost=215.35..7229.55 rows=5000 width=0) (actual time=0.327..0.508 rows=98 loops=1)
Recheck Cond: (coords && '(0.51,0.51),(0.5,0.5)'::box)
-> Bitmap Index Scan on test_geo_coords (cost=0.00..214.10 rows=5000 width=0) (actual time=0.307..0.307 rows=98 loops=1)
Index Cond: (coords && '(0.51,0.51),(0.5,0.5)'::box)
Total runtime: 0.564 ms |
Partager