Spatial query on large table with multiple self joins performing slow

后端 未结 4 1617
刺人心
刺人心 2021-01-13 15:38

I am working on queries on a large table in Postgres 9.3.9. It is a spatial dataset and it is spatially indexed. Say, I have need to find 3 types of objects: A, B and C. The

4条回答
  •  走了就别回头了
    2021-01-13 16:19

    Try this with inner join syntax and compare the results, there should be no duplicates. My guess is it should take 1/3rd the time or better than the original query :

    select a.id as a_id, a.name as a_name, a.geog as a_geo,
           b.id as b_id, b.name as b_name, b.geog as b_geo,
           c.id as c_id, c.name as c_name, c.geog as c_geo
    from table1 as a
    INNER JOIN table1 as b on b.type='B'
    INNER JOIN table1 as c on c.type='C'
    WHERE a.type='A' and
         (ST_DWithin(a.geo, b.geo, 100) and ST_DWithin(a.geo, c.geo, 100))
    

提交回复
热议问题