Thanks Paul :D,<br><br>is there any ticket already open about that modification?<br><br>best regards,<br clear="all">Luigi Castro Cardeles<br>
<br><br><div class="gmail_quote">2009/8/7 Paul Ramsey <span dir="ltr">&lt;<a href="mailto:pramsey@cleverelephant.ca">pramsey@cleverelephant.ca</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

It&#39;s not a bug, it&#39;s a feature!<br>
<br>
What you are seeing is the mapserver query life cycle. It is designed<br>
to be run on top of shape files, so when used on databases, it is very<br>
redundant. First it gathers the id&#39;s of all the features that match<br>
the criteria. Then it goes back and iterates through, getting each<br>
feature one at a time.<br>
<br>
The upcoming 5.6 release of mapserver will replace this query life<br>
cycle with one that is much more efficient for databases.<br>
<br>
P.<br>
<div><div></div><div class="h5"><br>
On Fri, Aug 7, 2009 at 4:52 AM, Luigi Castro<br>
Cardeles&lt;<a href="mailto:luigi.cardeles@gmail.com">luigi.cardeles@gmail.com</a>&gt; wrote:<br>
&gt; Hi list,<br>
&gt;<br>
&gt; I have a wfs layer (data stored at postgis) and that layer have a complex<br>
&gt; data statement<br>
&gt;<br>
&gt; mapfile<br>
&gt; -----------xxxxxxxxxxxx-------<br>
&gt; LISTCOIID - cgi param<br>
&gt; ##################<br>
&gt; #LAYER WFS PARCEL<br>
&gt; ##################<br>
&gt;  LAYER<br>
&gt;     NAME &#39;parcels&#39;<br>
&gt;     #DEBUG 5<br>
&gt;     METADATA<br>
&gt;     &quot;wfs_title&quot; &quot;parcels&quot;<br>
&gt;     &quot;wfs_request_method&quot; &quot;get&quot;<br>
&gt;     &quot;wfs_service&quot; &quot;wfs&quot;<br>
&gt;     &quot;gml_featureid&quot; &quot;id&quot;<br>
&gt;     &quot;gml_include_items&quot; &quot;all&quot;<br>
&gt;     &quot;wfs_encoding&quot; &quot;UTF8&quot;<br>
&gt;     END<br>
&gt;<br>
&gt;     TYPE POLYGON<br>
&gt;     STATUS ON<br>
&gt;     DUMP TRUE<br>
&gt;     CONNECTIONTYPE postgis<br>
&gt;     CONNECTION &quot;host=localhost user=&#39;postgres&#39; password=postgres_password<br>
&gt; dbname=&#39;wfs_server&#39;&quot;<br>
&gt;     DATA &quot;the_geom FROM (select distinct <a href="http://parcel.id" target="_blank">parcel.id</a>,parcel.the_geom from<br>
&gt; mapserver_parcels parcel where parcel.parcelid in( SELECT distinct <a href="http://col.id" target="_blank">col.id</a><br>
&gt; FROM college col WHERE col.date_exclude IS NULL AND ((%LISTCOIID% = <a href="http://col.id" target="_blank">col.id</a>)<br>
&gt; OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag,<br>
&gt; perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null<br>
&gt; AND colv.date_exclude is null AND pa.date_exclude is null AND<br>
&gt; colv.perm_group_FK = pagi.perm_group_fk AND pagi.perm_group_fk = <a href="http://pag.id" target="_blank">pag.id</a> AND<br>
&gt; pag.date_exclude IS NULL AND pagi.perm_acess_fk = <a href="http://pa.id" target="_blank">pa.id</a> AND <a href="http://pa.name" target="_blank">pa.name</a> =<br>
&gt; &#39;Test1&#39; AND colv.org_interference_fk = %LISTCOIID% AND<br>
&gt; colv.org_interference_fk_fk = <a href="http://col.id" target="_blank">col.id</a>) &gt; 0))) as foo USING UNIQUE id USING<br>
&gt; SRID=4326&quot;<br>
&gt;     #PROCESSING &quot;CLOSE_CONNECTION=DEFER&quot;<br>
&gt;     PROJECTION<br>
&gt;     &#39;init=epsg:4326&#39;<br>
&gt;     #   &quot;+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs&quot;<br>
&gt;     END<br>
&gt;<br>
&gt;      CLASS<br>
&gt;        NAME &#39;parcels&#39;<br>
&gt;        STYLE<br>
&gt;          SYMBOL 0<br>
&gt;          SIZE 10<br>
&gt;          OUTLINECOLOR 0 0 0<br>
&gt;          COLOR 150 123 90<br>
&gt;        END<br>
&gt;     END<br>
&gt;   END<br>
&gt; ------------xxxxxxxxxxxxx----------------<br>
&gt;<br>
&gt; when i activated the postgres log, i notice a strange, don&#39;t expected<br>
&gt; behavior. Mapserver changes the query (the data statement)  and refactory in<br>
&gt; 4(four) other queries:<br>
&gt;<br>
&gt; query 1:<br>
&gt;<br>
&gt; select<br>
&gt; encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;) as<br>
&gt; geom,&quot;id&quot; from (select distinct <a href="http://parcel.id" target="_blank">parcel.id</a>,parcel.the_geom from<br>
&gt; mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id" target="_blank">col.id</a><br>
&gt; FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id" target="_blank">col.id</a>) OR<br>
&gt; (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag,<br>
&gt; perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null<br>
&gt; AND colv.date_exclude is null AND pa.date_exclude is null AND<br>
&gt; colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id" target="_blank">pag.id</a> AND<br>
&gt; pag.date_exclude IS NULL AND colv.perm_group_FK = pagi.perm_group_ AND<br>
&gt; pagi.perm_group_ = <a href="http://pag.id" target="_blank">pag.id</a> AND pag.date_exclude IS NULL AND<br>
&gt; pagi.perm_acess_fk = <a href="http://pa.id" target="_blank">pa.id</a> AND <a href="http://pa.name" target="_blank">pa.name</a> = org_interference_fk AND<br>
&gt; colv.org_interference_fk = 25 AND colv.org_interference_fk_fk = <a href="http://col.id" target="_blank">col.id</a>) &gt;<br>
&gt; 0))) as foo where the_geom &amp;&amp; GeomFromText(&#39;POLYGON((-48.05 -15.77,-48.05<br>
&gt; -15.71,-47.85 -15.71,-47.85 -15.77,-48.05 -15.77))&#39;,4326)<br>
&gt;<br>
&gt; query 2:<br>
&gt;<br>
&gt; select * from (select distinct <a href="http://parcel.id" target="_blank">parcel.id</a>,parcel.the_geom from<br>
&gt; mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id" target="_blank">col.id</a><br>
&gt; FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id" target="_blank">col.id</a>) OR<br>
&gt; (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag,<br>
&gt; perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null<br>
&gt; AND colv.date_exclude is null AND pa.date_exclude is null AND<br>
&gt; colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id" target="_blank">pag.id</a> AND<br>
&gt; pag.date_exclude IS NULL AND    pagi.perm_acess_fk = <a href="http://pa.id" target="_blank">pa.id</a> AND <a href="http://pa.name" target="_blank">pa.name</a> =<br>
&gt; org_interference_fk AND colv.org_interference_fk = 25 AND<br>
&gt; colv.org_interference_fk_fk = <a href="http://col.id" target="_blank">col.id</a>) &gt; 0))) as foo where false limit 0<br>
&gt;<br>
&gt;<br>
&gt; query 3:<br>
&gt;<br>
&gt; select<br>
&gt; &quot;id&quot;,encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;)<br>
&gt; as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id" target="_blank">parcel.id</a>,parcel.the_geom from<br>
&gt; mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id" target="_blank">col.id</a><br>
&gt; FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id" target="_blank">col.id</a>) OR<br>
&gt; (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag,<br>
&gt; perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null<br>
&gt; AND colv.date_exclude is null AND pa.date_exclude is null AND<br>
&gt; colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id" target="_blank">pag.id</a> AND<br>
&gt; pag.date_exclude IS NULL AND pagi.perm_acess_fk = <a href="http://pa.id" target="_blank">pa.id</a> AND <a href="http://pa.name" target="_blank">pa.name</a> =<br>
&gt; org_interference_fk AND colv.org_interference_fk = 25 AND<br>
&gt; colv.org_interference_fk_fk = <a href="http://col.id" target="_blank">col.id</a>) &gt; 0))) as foo where &quot;id&quot; = 245<br>
&gt;<br>
&gt;<br>
&gt; query 4:<br>
&gt;<br>
&gt;<br>
&gt; select<br>
&gt; &quot;id&quot;,encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;)<br>
&gt; as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id" target="_blank">parcel.id</a>,parcel.the_geom from<br>
&gt; mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id" target="_blank">col.id</a><br>
&gt; FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id" target="_blank">col.id</a>) OR<br>
&gt; (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag,<br>
&gt; perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null<br>
&gt; AND colv.date_exclude is null AND pa.date_exclude is null AND<br>
&gt; colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id" target="_blank">pag.id</a> AND<br>
&gt; pag.date_exclude IS NULL AND    pagi.perm_acess_fk = <a href="http://pa.id" target="_blank">pa.id</a> AND <a href="http://pa.name" target="_blank">pa.name</a> =<br>
&gt; org_interference_fk AND colv.org_interference_fk = 25 AND<br>
&gt; colv.org_interference_fk_fk = <a href="http://col.id" target="_blank">col.id</a>) &gt; 0))) as foo where &quot;id&quot; = 246<br>
&gt;<br>
&gt; query 5<br>
&gt; select<br>
&gt; &quot;id&quot;,encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;)<br>
&gt; as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id" target="_blank">parcel.id</a>,parcel.the_geom from<br>
&gt; mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id" target="_blank">col.id</a><br>
&gt; FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id" target="_blank">col.id</a>) OR<br>
&gt; (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag,<br>
&gt; perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null<br>
&gt; AND colv.date_exclude is null AND pa.date_exclude is null AND<br>
&gt; colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id" target="_blank">pag.id</a> AND<br>
&gt; pag.date_exclude IS NULL AND    pagi.perm_acess_fk = <a href="http://pa.id" target="_blank">pa.id</a> AND <a href="http://pa.name" target="_blank">pa.name</a> =<br>
&gt; org_interference_fk AND colv.org_interference_fk = 25 AND<br>
&gt; colv.org_interference_fk_fk = <a href="http://col.id" target="_blank">col.id</a>) &gt; 0))) as foo where &quot;id&quot; = 247<br>
&gt; ------------xxxxxxxxxxxxxx----------------<br>
&gt;<br>
&gt; the wfs layer are returning 3 geometries (that is the expected result) but i<br>
&gt; don&#39;t understand why mapserver is generating this four queries.<br>
&gt;<br>
&gt; the first query (query 1) returns the id column (pk on my table) and<br>
&gt; the_geom (geometry column).<br>
&gt;<br>
&gt; the second query (query 2) don&#39;t return nothing.<br>
&gt;<br>
&gt; the third query (query 3) return the first id and the first the_geom values<br>
&gt; (query 1 already did that).<br>
&gt;<br>
&gt; the forth query (query 4) return the second id and the second the_geom<br>
&gt; values (query 1 already did that).<br>
&gt;<br>
&gt; the fifth query (query 5) return the third id and the third the_geom values<br>
&gt; (query 1 already did that).<br>
&gt;<br>
&gt; -------------------------------------------<br>
&gt;<br>
&gt; Aproximated times:<br>
&gt;<br>
&gt; query 1: 3s<br>
&gt; query 2: 18ms<br>
&gt; query 3: 2.6s<br>
&gt; query 4: 2.5s<br>
&gt; query 5: 2.7s<br>
&gt; ------------------------------------------<br>
&gt;<br>
&gt;<br>
&gt; The problem with this extra-queries is that they consume time so the query<br>
&gt; uses 8 seconds to bring back the information when should use 3 seconds to<br>
&gt; brinq back information.<br>
&gt;<br>
&gt; This refactory of the queries made by mapserver is alright or this is a bug?<br>
&gt;<br>
&gt; Luigi Castro Cardeles<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; mapserver-users mailing list<br>
&gt; <a href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a><br>
&gt; <a href="http://lists.osgeo.org/mailman/listinfo/mapserver-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/mapserver-users</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br>