Hi list,<br><br>I have a wfs layer (data stored at postgis) and that layer have a complex data statement<br><br>mapfile<br>-----------xxxxxxxxxxxx-------<br>LISTCOIID - cgi param<br>##################<br>#LAYER WFS PARCEL<br>

##################<br> LAYER<br>    NAME &#39;parcels&#39;<br>    #DEBUG 5<br>    METADATA<br>    &quot;wfs_title&quot; &quot;parcels&quot;<br>    &quot;wfs_request_method&quot; &quot;get&quot;<br>    &quot;wfs_service&quot; &quot;wfs&quot;<br>

    &quot;gml_featureid&quot; &quot;id&quot;<br>    &quot;gml_include_items&quot; &quot;all&quot;<br>    &quot;wfs_encoding&quot; &quot;UTF8&quot;<br>    END<br><br>    TYPE POLYGON<br>    STATUS ON<br>    DUMP TRUE<br>    CONNECTIONTYPE postgis<br>

    CONNECTION &quot;host=localhost user=&#39;postgres&#39; password=postgres_password dbname=&#39;wfs_server&#39;&quot;<br>    DATA &quot;the_geom FROM (select distinct <a href="http://parcel.id">parcel.id</a>,parcel.the_geom from mapserver_parcels parcel where parcel.parcelid in( SELECT distinct <a href="http://col.id">col.id</a> FROM college col WHERE col.date_exclude IS NULL AND ((%LISTCOIID% = <a href="http://col.id">col.id</a>) OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag, perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null AND colv.date_exclude is null AND pa.date_exclude is null AND colv.perm_group_FK = pagi.perm_group_fk AND pagi.perm_group_fk = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND pagi.perm_acess_fk = <a href="http://pa.id">pa.id</a> AND <a href="http://pa.name">pa.name</a> = &#39;Test1&#39; AND colv.org_interference_fk = %LISTCOIID% AND colv.org_interference_fk_fk = <a href="http://col.id">col.id</a>) &gt; 0))) as foo USING UNIQUE id USING SRID=4326&quot;<br>

    #PROCESSING &quot;CLOSE_CONNECTION=DEFER&quot;<br>    PROJECTION<br>    &#39;init=epsg:4326&#39;<br>    #   &quot;+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs&quot;<br>    END<br><br>     CLASS<br>       NAME &#39;parcels&#39;<br>

       STYLE<br>         SYMBOL 0<br>         SIZE 10<br>         OUTLINECOLOR 0 0 0<br>         COLOR 150 123 90<br>       END<br>    END<br>  END<br>------------xxxxxxxxxxxxx----------------<br><br>when i activated the postgres log, i notice a strange, don&#39;t expected behavior. Mapserver changes the query (the data statement)  and refactory in 4(four) other queries:<br>

<br>query 1:<br><br>select encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;) as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id">parcel.id</a>,parcel.the_geom from mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id">col.id</a> FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id">col.id</a>) OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag, perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null AND colv.date_exclude is null AND pa.date_exclude is null AND colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND pagi.perm_acess_fk = <a href="http://pa.id">pa.id</a> AND <a href="http://pa.name">pa.name</a> = org_interference_fk AND colv.org_interference_fk = 25 AND colv.org_interference_fk_fk = <a href="http://col.id">col.id</a>) &gt; 0))) as foo where the_geom &amp;&amp; GeomFromText(&#39;POLYGON((-48.05 -15.77,-48.05 -15.71,-47.85 -15.71,-47.85 -15.77,-48.05 -15.77))&#39;,4326)<br>

<br>query 2:<br><br>select * from (select distinct <a href="http://parcel.id">parcel.id</a>,parcel.the_geom from mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id">col.id</a> FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id">col.id</a>) OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag, perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null AND colv.date_exclude is null AND pa.date_exclude is null AND colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND    pagi.perm_acess_fk = <a href="http://pa.id">pa.id</a> AND <a href="http://pa.name">pa.name</a> = org_interference_fk AND colv.org_interference_fk = 25 AND colv.org_interference_fk_fk = <a href="http://col.id">col.id</a>) &gt; 0))) as foo where false limit 0<br>

<br><br>query 3:<br><br>select &quot;id&quot;,encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;) as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id">parcel.id</a>,parcel.the_geom from mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id">col.id</a> FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id">col.id</a>) OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag, perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null AND colv.date_exclude is null AND pa.date_exclude is null AND colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND pagi.perm_acess_fk = <a href="http://pa.id">pa.id</a> AND <a href="http://pa.name">pa.name</a> = org_interference_fk AND colv.org_interference_fk = 25 AND colv.org_interference_fk_fk = <a href="http://col.id">col.id</a>) &gt; 0))) as foo where &quot;id&quot; = 245<br>

<br><br>query 4:<br><br><br>select &quot;id&quot;,encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;) as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id">parcel.id</a>,parcel.the_geom from mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id">col.id</a> FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id">col.id</a>) OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag, perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null AND colv.date_exclude is null AND pa.date_exclude is null AND colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND    pagi.perm_acess_fk = <a href="http://pa.id">pa.id</a> AND <a href="http://pa.name">pa.name</a> = org_interference_fk AND colv.org_interference_fk = 25 AND colv.org_interference_fk_fk = <a href="http://col.id">col.id</a>) &gt; 0))) as foo where &quot;id&quot; = 246<br>

<br>query 5<br>select &quot;id&quot;,encode(AsBinary(force_collection(force_2d(&quot;the_geom&quot;)),&#39;NDR&#39;),&#39;base64&#39;) as geom,&quot;id&quot; from (select distinct <a href="http://parcel.id">parcel.id</a>,parcel.the_geom from mapserver_parcels parcel where parcel.parcelid in(SELECT distinct <a href="http://col.id">col.id</a> FROM college col WHERE col.date_exclude IS NULL AND ((25 = <a href="http://col.id">col.id</a>) OR (SELECT count(*) FROM perm_group_item pagi, visual colv , perm_group pag, perm_acess pa WHERE pagi.date_exclude is null AND pag.date_exclude is null AND colv.date_exclude is null AND pa.date_exclude is null AND colv.perm_group_FK = pagi.perm_group_ AND pagi.perm_group_ = <a href="http://pag.id">pag.id</a> AND pag.date_exclude IS NULL AND    pagi.perm_acess_fk = <a href="http://pa.id">pa.id</a> AND <a href="http://pa.name">pa.name</a> = org_interference_fk AND colv.org_interference_fk = 25 AND colv.org_interference_fk_fk = <a href="http://col.id">col.id</a>) &gt; 0))) as foo where &quot;id&quot; = 247<br>

------------xxxxxxxxxxxxxx----------------<br><br>the wfs layer are returning 3 geometries (that is the expected result) but i don&#39;t understand why mapserver is generating this four queries.<br><br>the first query (query 1) returns the id column (pk on my table) and the_geom (geometry column).<br>

<br>the second query (query 2) don&#39;t return nothing.<br><br>the third query (query 3) return the first id and the first the_geom values (query 1 already did that).<br><br>the forth query (query 4) return the second id and the second the_geom values (query 1 already did that).<br>

<br>the fifth query (query 5) return the third id and the third the_geom values (query 1 already did that).<br><br>-------------------------------------------<br><br>Aproximated times:<br><br>query 1: 3s<br>query 2: 18ms<br>

query 3: 2.6s<br>query 4: 2.5s<br>query 5: 2.7s<br>------------------------------------------<br><br><br>The problem with this extra-queries is that they consume time so the query uses 8 seconds to bring back the information when should use 3 seconds to brinq back information.<br>

<br>This refactory of the queries made by mapserver is alright or this is a bug?<br><br>Luigi Castro Cardeles<br><br>