我注意到,运行此子查询如何优化此子查询作为连接?
选择 ST_Area(ST_Union(ST_Transform(ST_Intersection((选择POLY1 poly1.the_geom WHERE poly1.polygon_type = 'P'),poly2.the_geom),3857) ))
AS area_of_P FROM POLY1,POLY2
比运行此连接显著慢
SELECT ST_AREA(ST_Union(ST_Transform(ST_Intersection(poly1.the_geom,poly2.the_geom),3857)))
AS area_of_poly
FROM POLY2
LEFT JOIN上st_intersects POLY1(poly1.the_geom ,poly2.the_geom)
WHERE poly2.polygon_type = 'P'
然而,我需要在这个第二裘扩大INED版本返回多个列,每个计算出的给定的多边形类型的区域,即
SELECT ST_Area(ST_Union(ST_Transform(ST_Intersection((从POLY1 SELECT poly1.the_geom WHERE poly1.polygon_type = 'P' ),poly2.the_geom),3857))) AS area_of_P,
ST_Area(ST_Union(ST_Transform(ST_Intersection((从POLY1 WHERE poly1.polygon_type = 'S'),poly2.the_geom),3857 SELECT poly1.the_geom ))) AS area_of_S
FROM poly1,poly2
对不起,我应该让这个更清楚。我想返回两列。一个是多边形类型'P'的区域,另一个是多边形类型'S'的区域。 – John
查看已更新的答案。 –
完全按照我需要的那样工作。谢谢布雷特。 – John