The Box Is Not The Shape
Two versions of the same population query, against PostGIS tables that both have GiST indexes on geom:
-- A
SELECT sum(b.pop) FROM census_blocks b, neighborhoods n
WHERE n.name = 'West Village' AND ST_Intersects(b.geom, n.geom);
-- 26,718
-- B
SELECT sum(b.pop) FROM census_blocks b, neighborhoods n
WHERE n.name = 'West Village' AND b.geom && n.geom;
-- 49,821
An engineer replaces A with B, reasoning that && uses the spatial index while ST_Intersects does not. What is actually true?
Sign in to answer questions and track your progress
Sign In