Improve sql query
Closed this issue · 1 comments
zhik commented
- When querying for overlapping districts with
State Senate Districts
:10
, the betanyc.carto endpoint will throw "You are over platform's limits: SQL query timeout error. Refactor your query before running again or contact CARTO support for more details."
The current query takes too long
WITH
al as (SELECT ST_MakeValid(the_geom) as the_geom, id, namecol, namealt FROM all_bounds),
se as (SELECT the_geom FROM al WHERE id = 'ss' AND namecol = '10'),
inter as (SELECT DISTINCT al.id, al.namecol, al.namealt, ST_Area(se.the_geom) as area, ST_Area(ST_Intersection(al.the_geom, se.the_geom)) as searea FROM al, se WHERE ST_Intersects(al.the_geom, se.the_geom))
SELECT * FROM inter WHERE searea / area > .005
zhik commented
Another method is improving the all_bounds.geojson before importing it into Carto.
Currently ST_MakeValid needs to be used which takes up some computing time. Also the current geographies don't have to be so accurate so they can be simplified too.