Hi, <br><br>Another method might be to create a new (spatial) index with a where clause and feeding exactly that clause into your query - the planner should then decide to use this partial index (check constraint exclusion settings also) and you won&#39;t have to do anything to the data itself. &nbsp;I&#39;ve got this to work with a spatial index and a where clause against a boolean field but haven&#39;t tried it with a spatial where clause.<br>
<br>Steve<br><br><br><br><i>&gt;Unfortunately, Stanley, I&#39;m going to have to politely disagree. If a <br>&gt;view is set up to be a filter on a table (even with proper indexes in <br>&gt;place), it will always be slower than looking at the same data in a <br>
&gt;materialized view. At the very least, you&#39;ll have the overhead of the <br>&gt;view&#39;s filter applied to every query written. <br>&gt;<br>&gt;Depending on the query, you may also get much worse results with a view <br>
&gt;than using a separate table.<br>&gt;<br>&gt;Consider a query that is interested in the entire contents of the view&#39;s <br>&gt;resultset. (IE. SELECT count(*) FROM my_view). In this case, if the <br>&gt;view represents only a small portion of the data from much larger table, <br>
&gt;the query planner will most likely opt to perform an index scan, <br>&gt;retrieving the rows of interest. On the other hand, if the view were <br>&gt;materialized into a table, the query planner would choose a sequential <br>
&gt;scan which is significantly faster than performing an index scan over <br>&gt;the same dataset.<br>&gt;<br>&gt;This is one of the ideas behind table inheritance - break a large table <br>&gt;into smaller, quicker sub-tables by separating most often / least often <br>
&gt;used data.<br>&gt;<br>&gt;Dylan, I would advise that you perform some timings on your most often <br>&gt;used queries, comparing a view and an equivalent materialized view. <br>&gt;Perhaps the incurred performance penalties is not worth your bother to <br>
&gt;create and maintain duplicate datasets. But then again ...<br>&gt;<br>&gt;<br>&gt;Cheers,<br>&gt;Kevin<br>&gt;<br>&gt;<br>&gt;<br>&gt;&gt;Sufficool, Stanley wrote:<br>&gt;&gt; I would think this depends on your back-end storage. If you have <br>
&gt;&gt; substantial backend storage, then the seek time on a view using a <br>&gt;&gt; constraint on an indexed column should be negligible.<br>&gt;&gt; <br>&gt;&gt; However, if you are running a single disk, the separate <br>
&gt;&gt; (non-fragmented) table _may_ be slightly faster.<br>&gt;&gt; <br>&gt;&gt; This is based on no knowledge of how PostgreSQL breaks up it&#39;s table <br>&gt;&gt; spaces into file system functions. Most ORDBMS&#39;s have files for index <br>
&gt;&gt; and files for data (or in MS, one huge file) which causes non-cached <br>&gt;&gt; index data to cause moderate disk thrashing on initial scans. However <br>&gt;&gt; once the index is cached, you are only looking at seek times between <br>
&gt;&gt; rows/sectors in the data.<br>&gt;&gt; <br>&gt;&gt; If anyone wishes to tell me that I&#39;m talking out my ----, please do. I <br>&gt;&gt; would like to know what PG optimizes in cases like these.<br>&gt;&gt;<br>
&gt;&gt; -----Original Message-----<br>&gt;&gt; *From:* postgis-users-bounces at <a href="http://postgis.refractions.net">postgis.refractions.net</a><br>&gt;&gt; [mailto:<a href="mailto:postgis-users-bounces">postgis-users-bounces</a> at <a href="http://postgis.refractions.net">postgis.refractions.net</a>] *On Behalf<br>
&gt;&gt; Of *Dylan Lorimer<br>&gt;&gt; *Sent:* Wednesday, April 30, 2008 1:54 PM<br>&gt;&gt; *To:* PostGIS Users Discussion<br>&gt;&gt; *Subject:* [postgis-users] View or New Table?<br>&gt;&gt;<br>&gt;&gt; Hi,<br>&gt;&gt;<br>
&gt;&gt; Perhaps an obvious question, but I was wondering if there is a<br>&gt;&gt; huge speed hit when running queries against a table vs running the<br>&gt;&gt; same queries against a view of a larger table constrained to the<br>
&gt;&gt; data that is pertinent.<br>&gt;&gt;<br>&gt;&gt; Concrete example: millions of points all over the world, but I<br>&gt;&gt; only care about those over Africa. I could either create a new<br>&gt;&gt; table storing only those points over Africa, or I could create a<br>
&gt;&gt; view on the original table that is constrained by a join on a<br>&gt;&gt; table containing the borders of the African continent.<br>&gt;&gt;<br>&gt;&gt; If I have requisite indexes in place, will it still be faster to<br>
&gt;&gt; use the new table instead of the view?<br>&gt;&gt; Cheers,<br>&gt;&gt; dylan<br>&gt;&gt;<br>&gt;&gt; -- <br>&gt;&gt; Dylan Lorimer | Strategic Partner Management<br>&gt;&gt; 415.573.2909 (Grand Central) | 650.644.0182 (Fax)<br>
&gt;&gt;<br>&gt;&gt; If you received this communication by mistake, please don&#39;t<br>&gt;&gt; forward it to anyone else (it may contain confidential or<br>&gt;&gt; privileged information), please erase all copies of it, including<br>
&gt;&gt; all attachments, and please let the sender know it went to the<br>&gt;&gt; wrong person. Thanks. <br>&gt;&gt;<br>&gt;&gt; ------------------------------------------------------------------------<br>&gt;&gt;<br>&gt;&gt; _______________________________________________<br>
&gt;&gt; postgis-users mailing list<br>&gt;&gt; postgis-users at <a href="http://postgis.refractions.net">postgis.refractions.net</a><br>&gt;&gt; <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
&gt;&gt; </i><br>