我有一个包含两个表,区域和属性的数据库,每个包含100万行。现在我们发现在给定区域内有多少属性,我们正在使用此查询,但需要时间来获取
SELECT count(*) FROM properties
WHERE ST_Intersects(geom, '01030000000100000005000000456458C51B375240C173EFE1922333400E10CCD1E3375240335019FF3E23334011AAD4EC81385240E4BD6A65C227334068B3EA73B5375240FA449E245D2B3340456458C51B375240C173EFE192233340')
我们可以采用更好的方法吗?
执行计划
"Aggregate (cost=38932.37..38932.38 rows=1 width=0)"
" -> Bitmap Heap Scan on properties (cost=463.41..38921.03 rows=4533 width=0)"
" Recheck Cond: (geom && '01030000000100000005000000456458C51B375240C173EFE1922333400E10CCD1E3375240335019FF3E23334011AAD4EC81385240E4BD6A65C227334068B3EA73B5375240FA449E245D2B3340456458C51B375240C173EFE192233340'::geometry)"
" Filter: _st_intersects(geom, '01030000000100000005000000456458C51B375240C173EFE1922333400E10CCD1E3375240335019FF3E23334011AAD4EC81385240E4BD6A65C227334068B3EA73B5375240FA449E245D2B3340456458C51B375240C173EFE192233340'::geometry)"
" Index Cond: (geom && '01030000000100000005000000456458C51B375240C173EFE1922333400E10CCD1E3375240335019FF3E23334011AAD4EC81385240E4BD6A65C227334068B3EA73B5375240FA449E245D2B3340456458C51B375240C173EFE192233340'::geometry)"
答案 0 :(得分:0)
教科书的答案是,您应首先检查每个几何体上边界框的重叠。我当然发现两个表中有大量几何图形的查询:
select xxx from A, B
where A.geom && B.geom
AND
ST_INTERSECTS(a.geom,b.geom);
...比单独使用ST_INTERSECTS更快地运行四个数量级。