Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. -- create point table using single-precision coordinates
  2. CREATE TABLE pts (
  3. point_id serial,
  4. x real,
  5. y real
  6. );
  7.  
  8. -- create a view that converts these into a PostGIS geometry
  9. CREATE VIEW pts_view AS
  10. SELECT point_id, ST_SetSRID(ST_MakePoint(x, y), 4326) AS geom FROM pts;
  11.  
  12. -- create a functional index on the raw -> PostGIS conversion
  13. CREATE INDEX ON pts USING gist(ST_SetSRID(ST_MakePoint(x, y), 4326));
  14.  
  15. -- index is activated in a regular PostGIS query
  16. EXPLAIN SELECT * FROM ne_10m_admin_0_countries a INNER JOIN pts_view b ON ST_Intersects(a.geom, b.geom);
  17. QUERY PLAN
  18. ----------------------------------------------------------------------------------------------------------------------
  19. -- Nested Loop (cost=0.14..229.57 rows=173 width=35400)
  20. -- -> Seq Scan on ne_10m_admin_0_countries a (cost=0.00..73.55 rows=255 width=35364)
  21. -- -> Index Scan using pts_st_setsrid_idx on pts (cost=0.14..0.60 rows=1 width=12)
  22. -- Index Cond: (a.geom && st_setsrid(st_makepoint((x)::double precision, (y)::double precision), 4326))
  23. -- Filter: _st_intersects(a.geom, st_setsrid(st_makepoint((x)::double precision, (y)::double precision), 4326))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement