<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>RE: [postgis-users] Large geometry issue</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Martin,<BR>
<BR>
Sorry for the lack of coherence -- 2530 vertices in this test polygon ... it should be in the original posting I sent, an attached zip file with two tables; this is the single entry in the oli_req table. The other table has some 13000 rows of polygons which are either completely within or overlapping with the large poly.<BR>
<BR>
If you can't get at that let me know and I'll send you a copy ...<BR>
<BR>
Greg W.<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: postgis-users-bounces@postgis.refractions.net on behalf of Martin Davis<BR>
Sent: Thu 7/5/2007 5:09 PM<BR>
To: PostGIS Users Discussion<BR>
Subject: Re: [postgis-users] Large geometry issue<BR>
<BR>
Greg,<BR>
<BR>
Can you elaborate on your statement &quot;2530 in a sinlge polygon&quot;?&nbsp; Do you<BR>
mean holes or subPolygons in a MultiPolygon?<BR>
<BR>
Either way, currently JTS is not optimized for working with very large<BR>
numbers of holes and sub-polygons.&nbsp; As Paul says, we are currently<BR>
working on improving this.&nbsp; Hopefully we can at least match the<BR>
performance of the Other DMBS(es) for this situation!<BR>
<BR>
Would it be possible for me to obtain this geometry for testing?<BR>
<BR>
Martin<BR>
<BR>
<BR>
<BR>
Gregory Williamson wrote:<BR>
&gt;<BR>
&gt; Dear peoples,<BR>
&gt;<BR>
&gt; I have a problem with a query that uses an absurdly large geometry<BR>
&gt; (2530 in a single polygon). This is srid -1 (part of a large test of<BR>
&gt; postgres vs some other database product). Everything has been vacuumed<BR>
&gt; and analyzed.<BR>
&gt;<BR>
&gt; The initial search to find candidates in a target table is quite fast:<BR>
&gt; catest=# select count(*) from wtm_sub_cell w, order_line_item x WHERE<BR>
&gt; x.bbox &amp;&amp; w.geometry AND x.id_as_int = 114672;<BR>
&gt;&nbsp; count<BR>
&gt; -------<BR>
&gt;&nbsp; 13168<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 9.472 ms<BR>
&gt;<BR>
&gt; Trying to get the list narrowed to geometries that are completely<BR>
&gt; contained by the requested shape is slow:<BR>
&gt; catest=# select count(*) from wtm_sub_cell w, order_line_item x WHERE<BR>
&gt; x.bbox &amp;&amp; w.geometry AND distance(x.geometry,w.geometry) = 0 and<BR>
&gt; x.id_as_int = 114672;<BR>
&gt;&nbsp; count<BR>
&gt; -------<BR>
&gt;&nbsp;&nbsp; 1112<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 69277.780 ms<BR>
&gt;<BR>
&gt; So I have two questions:<BR>
&gt;&nbsp;&nbsp; a) anything better to use than &quot;distance(x,y) = 0) ? I tried<BR>
&gt; st_within -- it is about the same speed but returns no polys, which is<BR>
&gt; strange to me, but I also haven't looked at these in detail yet. For<BR>
&gt; example:<BR>
&gt; catest=# select count(*) from wtm_sub_cell w, order_line_item x WHERE<BR>
&gt; x.bbox &amp;&amp; w.geometry AND st_within(x.geometry,w.geometry) and<BR>
&gt; x.id_as_int = 114672;<BR>
&gt;&nbsp; count<BR>
&gt; -------<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 1173.185 ms<BR>
&gt; (same results with st_within(w.geometry,x.geometry):<BR>
&gt; catest=# select count(*) from wtm_sub_cell w, order_line_item x WHERE<BR>
&gt; x.bbox &amp;&amp; w.geometry AND st_within(w.geometry,x.geometry) and<BR>
&gt; x.id_as_int = 114672;<BR>
&gt;&nbsp; count<BR>
&gt; -------<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt;<BR>
&gt;&nbsp;&nbsp; b) anything I can do to speed things up ? I have tried boosting work<BR>
&gt; mem to 16 megs (from 1) and it made no apparent difference.<BR>
&gt;<BR>
&gt;<BR>
&gt;<BR>
&gt; I have a self contained test case that shows the same behavior -- the<BR>
&gt; one large poly and all the candidates in another table. Apologies for<BR>
&gt; the size; hopefully it's not been mangled in the transfers.<BR>
&gt;<BR>
&gt; Explain analyze of the sample (the sequential is sensible since there<BR>
&gt; is only one row in the table):<BR>
&gt; catest=# explain analyze select count(*) from wsc_candidates w,<BR>
&gt; oli_req x WHERE w.geometry &amp;&amp; x.bbox AND<BR>
&gt; distance(w.geometry,x.oli_req_geom) &gt; 0 AND x.oli_req_id = 114672;<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&gt; QUERY PLAN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&gt; -------------------------------------------------------------------------------------------------------------------------------------------------------<BR>
&gt;&nbsp; Aggregate&nbsp; (cost=20.28..20.29 rows=1 width=0) (actual<BR>
&gt; time=77232.858..77232.859 rows=1 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Nested Loop&nbsp; (cost=0.00..9.30 rows=4389 width=0) (actual<BR>
&gt; time=6.389..77221.506 rows=12056 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join Filter: (distance(w.geometry, x.oli_req_geom) &gt;<BR>
&gt; 0::double precision)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Seq Scan on oli_req x&nbsp; (cost=0.00..1.01 rows=1<BR>
&gt; width=40602) (actual time=0.007..0.009 rows=1 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Filter: (oli_req_id = 114672)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Index Scan using wsc_c_spatial_ndx on wsc_candidates w&nbsp;<BR>
&gt; (cost=0.00..8.27 rows=1 width=109) (actual time=0.022..25.991<BR>
&gt; rows=13168 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Index Cond: (w.geometry &amp;&amp; x.bbox)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Filter: (w.geometry &amp;&amp; x.bbox)<BR>
&gt;&nbsp; Total runtime: 77232.901 ms<BR>
&gt; (9 rows)<BR>
&gt;<BR>
&gt; Time: 77233.773 ms<BR>
&gt;<BR>
&gt;<BR>
&gt; And for the real thing:<BR>
&gt; catest=# explain analyze select count(*) from wtm_sub_cell w,<BR>
&gt; order_line_item x WHERE w.geometry &amp;&amp; x.bbox AND<BR>
&gt; distance(w.geometry,x.geometry) = 0 AND x.id_as_int = 114672;<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QUERY<BR>
&gt; PLAN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&gt; --------------------------------------------------------------------------------------------------------------------------------------------<BR>
&gt;&nbsp; Aggregate&nbsp; (cost=141.83..141.84 rows=1 width=0) (actual<BR>
&gt; time=77457.587..77457.588 rows=1 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Nested Loop&nbsp; (cost=5.99..141.83 rows=1 width=0) (actual<BR>
&gt; time=15.682..77456.541 rows=1112 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Join Filter: (distance(w.geometry, x.geometry) = 0::double<BR>
&gt; precision)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Index Scan using oli_id_ndx on order_line_item x&nbsp;<BR>
&gt; (cost=0.00..8.30 rows=1 width=383) (actual time=0.012..0.018 rows=1<BR>
&gt; loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Index Cond: (id_as_int = 114672)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Bitmap Heap Scan on wtm_sub_cell w&nbsp; (cost=5.99..132.97<BR>
&gt; rows=32 width=109) (actual time=2.988..21.796 rows=13168 loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Filter: (w.geometry &amp;&amp; x.bbox)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Bitmap Index Scan on wsc_geom_idx1&nbsp;<BR>
&gt; (cost=0.00..5.98 rows=32 width=0) (actual time=2.828..2.828 rows=13168<BR>
&gt; loops=1)<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Index Cond: (w.geometry &amp;&amp; x.bbox)<BR>
&gt;&nbsp; Total runtime: 77457.633 ms<BR>
&gt; (10 rows)<BR>
&gt;<BR>
&gt; Time: 77458.458 ms<BR>
&gt;<BR>
&gt;<BR>
&gt; The tables involved by size:<BR>
&gt; catest=# select count(*) from wsc_candidates;<BR>
&gt;&nbsp; count<BR>
&gt; -------<BR>
&gt;&nbsp; 13168<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 2.586 ms<BR>
&gt; catest=# select count(*) from oli_req;<BR>
&gt;&nbsp; count<BR>
&gt; -------<BR>
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 0.193 ms<BR>
&gt; catest=# select count(*) from wtm_sub_cell;<BR>
&gt;&nbsp;&nbsp; count<BR>
&gt; ---------<BR>
&gt;&nbsp; 6399928<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 1776.508 ms<BR>
&gt; catest=# select count(*) from order_line_item;<BR>
&gt;&nbsp; count<BR>
&gt; --------<BR>
&gt;&nbsp; 395921<BR>
&gt; (1 row)<BR>
&gt;<BR>
&gt; Time: 176.083 ms<BR>
&gt;<BR>
&gt;<BR>
&gt; Many thanks for your time and bandwidth!<BR>
&gt;<BR>
&gt; Greg Williamson<BR>
&gt; Senior DBA<BR>
&gt; GlobeXplorer LLC, a DigitalGlobe company<BR>
&gt;<BR>
&gt; Confidentiality Notice: This e-mail message, including any<BR>
&gt; attachments, is for the sole use of the intended recipient(s) and may<BR>
&gt; contain confidential and privileged information and must be protected<BR>
&gt; in accordance with those provisions. Any unauthorized review, use,<BR>
&gt; disclosure or distribution is prohibited. If you are not the intended<BR>
&gt; recipient, please contact the sender by reply e-mail and destroy all<BR>
&gt; copies of the original message.<BR>
&gt;<BR>
&gt; (My corporate masters made me say this.)<BR>
&gt;<BR>
&gt; ------------------------------------------------------------------------<BR>
&gt;<BR>
&gt; _______________________________________________<BR>
&gt; postgis-users mailing list<BR>
&gt; postgis-users@postgis.refractions.net<BR>
&gt; <A HREF="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</A><BR>
&gt;&nbsp;&nbsp;<BR>
<BR>
--<BR>
Martin Davis<BR>
Senior Technical Architect<BR>
Refractions Research, Inc.<BR>
(250) 383-3022<BR>
<BR>
_______________________________________________<BR>
postgis-users mailing list<BR>
postgis-users@postgis.refractions.net<BR>
<A HREF="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</A><BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>