<HTML dir=ltr><HEAD><TITLE>Re: More of pooling, mapquery.c</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText56598 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Thanks again Tamas (and other),</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>I have missed that piece. It could be the missing part.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>I will try it tomorrow.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Thanks again,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>Johan</FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2><SPAN lang=SV style="FONT-SIZE: 10pt"><FONT face=Arial>___________________________________</FONT></SPAN></DIV></DIV>
<DIV id=idSignature30716 dir=ltr>
<DIV>
<DIV dir=ltr align=left>
<H3 style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV><FONT face=Arial size=3>Johan Hallgren</FONT></SPAN></H3>
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV></SPAN> </DIV>
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">WM-data</SPAN></DIV>
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">Pelle Bergs backe 3</SPAN></DIV>
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"></SPAN><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">Box 1938, 791 19 Falun</SPAN></DIV>
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial">
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial; mso-ansi-language: SV; mso-no-proof: yes">Tel (och mobil): 023-547 46 (int: +46-2354746)</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-no-proof: yes"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></DIV></SPAN><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"><U><FONT color=#0000ff>johan.e.hallgren</FONT></U><A href="mailto:johan.e.hallgren@wmdata.com" target=_blank>@wmdata.com</A></SPAN></DIV>
<DIV class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=SV style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"><A href="https://webaccess.wmdata.com/exchweb/bin/redir.asp?URL=http://www.wmdata.se/" target=_blank>http://www.wmdata.se</A></SPAN></DIV></DIV></FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>Från:</B> Tamas Szekeres [mailto:szekerest@gmail.com]<BR><B>Skickat:</B> må 2007-05-07 14:17<BR><B>Till:</B> Hallgren Johan E<BR><B>Kopia:</B> MAPSERVER-DEV@lists.umn.edu<BR><B>Ämne:</B> Re: More of pooling, mapquery.c<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Did you test with<BR><BR>PROCESSING CLOSE_CONNECTION=DEFER option with your SDE layer?<BR><BR>Best regards,<BR><BR>Tamas<BR><BR><BR>2007/5/7, Hallgren Johan E <jhhal@wmdata.com>:<BR>><BR>><BR>><BR>><BR>> Hello again,<BR>><BR>><BR>><BR>> I have made a test with the following code with extremely good performance.<BR>> I have only tested this specific call, but couldn't the concept be<BR>> implemented in other functions as well? As I see it, it will implement the<BR>> Connection pool between mapscript calls.<BR>><BR>><BR>><BR>> My added sections start with Johan START and ends with Johan END.<BR>><BR>><BR>><BR>> int msQueryByAttributes(mapObj *map, int qlayer, char *qitem, char *qstring,<BR>> int mode)<BR>><BR>> {<BR>><BR>> layerObj *lp;<BR>><BR>> int status;<BR>><BR>><BR>><BR>> /* Johan START */<BR>><BR>> int bLayerWasOpen;<BR>><BR>> /* Johan START */<BR>><BR>><BR>><BR>> int old_filtertype=-1;<BR>><BR>> char *old_filterstring=NULL, *old_filteritem=NULL;<BR>><BR>><BR>><BR>> rectObj searchrect;<BR>><BR>><BR>><BR>> shapeObj shape;<BR>><BR>><BR>><BR>> if(qlayer < 0 || qlayer >= map->numlayers) {<BR>><BR>> msSetError(MS_MISCERR, "No query layer defined.",<BR>> "msQueryByAttributes()");<BR>><BR>> return(MS_FAILURE);<BR>><BR>> }<BR>><BR>><BR>><BR>> lp = &(map->layers[qlayer]);<BR>><BR>><BR>><BR>> /* free any previous search results, do now in case one of the following<BR>> tests fails */<BR>><BR>> if(lp->resultcache) {<BR>><BR>> if(lp->resultcache->results) free(lp->resultcache->results);<BR>><BR>> free(lp->resultcache);<BR>><BR>> lp->resultcache = NULL;<BR>><BR>> }<BR>><BR>><BR>><BR>> if(!msIsLayerQueryable(lp)) {<BR>><BR>> msSetError(MS_QUERYERR, "Requested layer has no templates defined so is<BR>> not queryable.", "msQueryByAttributes()");<BR>><BR>> return(MS_FAILURE);<BR>><BR>> }<BR>><BR>><BR>><BR>> if(!qstring) {<BR>><BR>> msSetError(MS_QUERYERR, "No query expression defined.",<BR>> "msQueryByAttributes()");<BR>><BR>> return(MS_FAILURE);<BR>><BR>> }<BR>><BR>><BR>><BR>> /* save any previously defined filter */<BR>><BR>> if(lp->filter.string) {<BR>><BR>> old_filtertype = lp->filter.type;<BR>><BR>> old_filterstring = strdup(lp->filter.string);<BR>><BR>> if(lp->filteritem)<BR>><BR>> old_filteritem = strdup(lp->filteritem);<BR>><BR>> }<BR>><BR>><BR>><BR>> /* apply the passed query parameters */<BR>><BR>> if(qitem)<BR>><BR>> lp->filteritem = strdup(qitem);<BR>><BR>> else<BR>><BR>> lp->filteritem = NULL;<BR>><BR>> msLoadExpressionString(&(lp->filter), qstring);<BR>><BR>><BR>><BR>> msInitShape(&shape);<BR>><BR>><BR>><BR>> /* open this layer */<BR>><BR>> /* Johan START */<BR>><BR>> //int bLayerWasOpen;<BR>><BR>> bLayerWasOpen = msLayerIsOpen(lp);<BR>><BR>> if (!bLayerWasOpen)<BR>><BR>> {<BR>><BR>> status = msLayerOpen(lp);<BR>><BR>> if(status != MS_SUCCESS) return(MS_FAILURE);<BR>><BR>> }<BR>><BR>> //status = msLayerOpen(lp);<BR>><BR>> // if(status != MS_SUCCESS) return(MS_FAILURE);<BR>><BR>> /*Johan END*/<BR>><BR>><BR>><BR>> /* build item list (no annotation) */<BR>><BR>> status = msLayerWhichItems(lp, MS_TRUE, MS_FALSE, NULL);<BR>><BR>> if(status != MS_SUCCESS) return(MS_FAILURE);<BR>><BR>><BR>><BR>> /* identify target shapes */<BR>><BR>> searchrect = map->extent;<BR>><BR>> #ifdef USE_PROJ<BR>><BR>> if(lp->project && msProjectionsDiffer(&(lp->projection),<BR>> &(map->projection)))<BR>><BR>> msProjectRect(&(map->projection), &(lp->projection),<BR>> &searchrect); /* project the searchrect to source coords */<BR>><BR>> else<BR>><BR>> lp->project = MS_FALSE;<BR>><BR>> #endif<BR>><BR>> status = msLayerWhichShapes(lp, searchrect);<BR>><BR>> if(status == MS_DONE) { /* no overlap */<BR>><BR>> msLayerClose(lp);<BR>><BR>> msSetError(MS_NOTFOUND, "No matching record(s) found, layer and area of<BR>> interest do not overlap.", "msQueryByAttributes()");<BR>><BR>> return(MS_FAILURE);<BR>><BR>> } else if(status != MS_SUCCESS) {<BR>><BR>> msLayerClose(lp);<BR>><BR>> return(MS_FAILURE);<BR>><BR>> }<BR>><BR>><BR>><BR>> lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /*<BR>> allocate and initialize the result cache */<BR>><BR>> lp->resultcache->results = NULL;<BR>><BR>> lp->resultcache->numresults = lp->resultcache->cachesize = 0;<BR>><BR>> lp->resultcache->bounds.minx = lp->resultcache->bounds.miny =<BR>> lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;<BR>><BR>><BR>><BR>> while((status = msLayerNextShape(lp, &shape)) == MS_SUCCESS) { /* step<BR>> through the shapes */<BR>><BR>><BR>><BR>> shape.classindex = msShapeGetClass(lp, &shape, map->scale);<BR>><BR>> if(!(lp->template) && ((shape.classindex == -1) ||<BR>> (lp->class[shape.classindex].status == MS_OFF))) { /* not a valid shape */<BR>><BR>> msFreeShape(&shape);<BR>><BR>> continue;<BR>><BR>> }<BR>><BR>><BR>><BR>> if(!(lp->template) && !(lp->class[shape.classindex].template)) { /* no<BR>> valid template */<BR>><BR>> msFreeShape(&shape);<BR>><BR>> continue;<BR>><BR>> }<BR>><BR>><BR>><BR>> #ifdef USE_PROJ<BR>><BR>> if(lp->project &&<BR>> msProjectionsDiffer(&(lp->projection), &(map->projection)))<BR>><BR>> msProjectShape(&(lp->projection), &(map->projection),<BR>> &shape);<BR>><BR>> else<BR>><BR>> lp->project = MS_FALSE;<BR>><BR>> #endif<BR>><BR>><BR>><BR>> addResult(lp->resultcache, shape.classindex, shape.index,<BR>> shape.tileindex);<BR>><BR>><BR>><BR>> if(lp->resultcache->numresults == 1)<BR>><BR>> lp->resultcache->bounds = shape.bounds;<BR>><BR>> else<BR>><BR>> msMergeRect(&(lp->resultcache->bounds),<BR>> &shape.bounds);<BR>><BR>><BR>><BR>> msFreeShape(&shape);<BR>><BR>><BR>><BR>> if(mode == MS_SINGLE) { /* no need to look any further */<BR>><BR>> status = MS_DONE;<BR>><BR>> break;<BR>><BR>> }<BR>><BR>> }<BR>><BR>><BR>><BR>> if(status != MS_DONE) return(MS_FAILURE);<BR>><BR>><BR>><BR>> /* the FILTER set was just temporary, clean up here */<BR>><BR>> freeExpression(&(lp->filter));<BR>><BR>> if(lp->filteritem) {<BR>><BR>> free(lp->filteritem);<BR>><BR>> lp->filteritem = NULL;<BR>><BR>> lp->filteritemindex = -1;<BR>><BR>> }<BR>><BR>><BR>><BR>> /* restore any previously defined filter */<BR>><BR>> if(old_filterstring) {<BR>><BR>> lp->filter.type = old_filtertype;<BR>><BR>> lp->filter.string = strdup(old_filterstring);<BR>><BR>> free(old_filterstring);<BR>><BR>> if(old_filteritem) {<BR>><BR>> lp->filteritem = strdup(old_filteritem);<BR>><BR>> free(old_filteritem);<BR>><BR>> }<BR>><BR>> }<BR>><BR>><BR>><BR>> /*Johan START*/<BR>><BR>> if (!bLayerWasOpen)<BR>><BR>> {<BR>><BR>> msLayerClose(lp);<BR>><BR>> }<BR>><BR>> //msLayerClose(lp);<BR>><BR>> /*Johan END*/<BR>><BR>><BR>><BR>><BR>><BR>> /* was anything found? */<BR>><BR>> if(lp->resultcache && lp->resultcache->numresults > 0)<BR>><BR>> return(MS_SUCCESS);<BR>><BR>><BR>><BR>> msSetError(MS_NOTFOUND, "No matching record(s) found.",<BR>> "msQueryByAttributes()");<BR>><BR>> return(MS_FAILURE);<BR>><BR>> }<BR>><BR>><BR>><BR>><BR>><BR>> /Ugh<BR>> ___________________________________<BR>> Johan Hallgren<BR>><BR>><BR>><BR>><BR>><BR>> WM-data a LogicaCMG company<BR>><BR>><BR>> Pelle Bergs backe 3<BR>><BR>><BR>> Box 1938, 791 19 Falun<BR>><BR>><BR>><BR>> Tel: 023-547 46 (int: +46-2354746)<BR>><BR>> Mobil: 070-588 44 28 (int: +46-705884428)<BR>><BR>><BR>> johan.e.hallgren@wmdata.com<BR>><BR>><BR>> <A href="http://www.wmdata.se/">http://www.wmdata.se</A><BR>><BR>><BR></FONT></P></DIV></BODY></HTML>