[mapserver-commits] r11746 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sun May 22 15:13:33 EDT 2011


Author: rouault
Date: 2011-05-22 12:13:33 -0700 (Sun, 22 May 2011)
New Revision: 11746

Modified:
   trunk/mapserver/mapogr.cpp
Log:
OGR datasources: 2 speed optimizations: 1) avoid looping over layers when the DATA is a SELECT statement; 2) use OGR_L_GetName() when available (OGR >= 1.8.0) to benefit from optimizations of some OGR drivers that don't need to query the full layer defn

Modified: trunk/mapserver/mapogr.cpp
===================================================================
--- trunk/mapserver/mapogr.cpp	2011-05-22 18:51:29 UTC (rev 11745)
+++ trunk/mapserver/mapogr.cpp	2011-05-22 19:13:33 UTC (rev 11746)
@@ -1440,11 +1440,34 @@
 
   int  iLayer;
 
-  for( iLayer = 0; iLayer < OGR_DS_GetLayerCount(hDS); iLayer++ )
+  if( EQUALN(pszLayerDef,"SELECT ",7) )
   {
+      ACQUIRE_OGR_LOCK;
+      hLayer = OGR_DS_ExecuteSQL( hDS, pszLayerDef, NULL, NULL );
+      if( hLayer == NULL )
+      {
+          msSetError(MS_OGRERR,
+                     "ExecuteSQL(%s) failed.\n%s",
+                     "msOGRFileOpen()",
+                     pszLayerDef, CPLGetLastErrorMsg() );
+          RELEASE_OGR_LOCK;
+          msConnPoolRelease( layer, hDS );
+          CPLFree( pszLayerDef );
+          return NULL;
+      }
+      RELEASE_OGR_LOCK;
+      nLayerIndex = -1;
+  }
+
+  for( iLayer = 0; hLayer == NULL && iLayer < OGR_DS_GetLayerCount(hDS); iLayer++ )
+  {
       hLayer = OGR_DS_GetLayer( hDS, iLayer );
-      if( hLayer != NULL 
+      if( hLayer != NULL
+#if GDAL_VERSION_NUM >= 1800
+          && EQUAL(OGR_L_GetName(hLayer),pszLayerDef) )
+#else
           && EQUAL(OGR_FD_GetName( OGR_L_GetLayerDefn(hLayer) ),pszLayerDef) )
+#endif
       {
           nLayerIndex = iLayer;
           break;
@@ -1460,25 +1483,6 @@
           hLayer = OGR_DS_GetLayer( hDS, nLayerIndex );
   }
 
-  if( hLayer == NULL && EQUALN(pszLayerDef,"SELECT",6) )
-  {
-      ACQUIRE_OGR_LOCK;
-      hLayer = OGR_DS_ExecuteSQL( hDS, pszLayerDef, NULL, NULL );
-      if( hLayer == NULL )
-      {
-          msSetError(MS_OGRERR, 
-                     "ExecuteSQL(%s) failed.\n%s",
-                     "msOGRFileOpen()", 
-                     pszLayerDef, CPLGetLastErrorMsg() );
-          RELEASE_OGR_LOCK;
-          msConnPoolRelease( layer, hDS );
-          CPLFree( pszLayerDef );
-          return NULL;
-      }
-      RELEASE_OGR_LOCK;
-      nLayerIndex = -1;
-  }
-
   if (hLayer == NULL)
   {
       msSetError(MS_OGRERR, "GetLayer(%s) failed for OGR connection `%s'.",



More information about the mapserver-commits mailing list