Performance on multiple OR conditions inside ()

From: Håvard Wahl Kongsgård <haavard(dot)kongsgaard(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Performance on multiple OR conditions inside ()
Date: 2011-01-13 16:47:39
Message-ID: AANLkTingN4dwbSubov7_zbZ8+hxZTOsLGtci236yHbVV@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, I have a spatial query with multiple OR statements, for large tables
it's very slow. Is it possible to skip the spatial lookup on the other
conditions if first(previous) condition equal 1, and thereby increase the
performance?

SELECT vciia_main.sitrp,vciia_main.date_time from vciia_main,
south_vietnam72, roads, rails, houses, city where st_within(vciia_main.geom,
south_vietnam72.geom) and date_time is not null and
(st_dwithin(vciia_main.geom, roads.geom, 500) OR st_dwithin(vciia_main.geom,
rails.geom, 500) or st_dwithin(vciia_main.geom, city.geom, 800) or
st_dwithin(vciia_main.geom, houses.the_geom, 500))

--
Håvard Wahl Kongsgård
Peace Research Institute Oslo (PRIO)

http://havard.security-review.net/

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-01-13 17:20:20 Re: Record with a field consisting of table rows
Previous Message Pavel Stehule 2011-01-13 16:44:06 Re: Record with a field consisting of table rows