[mapguide-commits] r6333 - trunk/MgDev/Server/src/Gws/GwsQueryEngine

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Dec 14 19:00:37 EST 2011


Author: jng
Date: 2011-12-14 16:00:37 -0800 (Wed, 14 Dec 2011)
New Revision: 6333

Modified:
   trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsFeatureSourceQuery.cpp
   trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsPreparedFeatureQuery.cpp
   trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsRightSortedJoinQueryResults.cpp
Log:
#1888: Fix incorrect join algorithm chosen by the GwsQueryEngine if the join involves SDF/SHP sources. Also includes extra conditional code for debugging feature joins. Reviewed by Bruce Dechant.

Modified: trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsFeatureSourceQuery.cpp
===================================================================
--- trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsFeatureSourceQuery.cpp	2011-12-13 07:10:47 UTC (rev 6332)
+++ trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsFeatureSourceQuery.cpp	2011-12-15 00:00:37 UTC (rev 6333)
@@ -23,7 +23,12 @@
 
 #include "stdafx.h"
 #include "GwsQueryEngineImp.h"
+#include <SDF/SdfCommandType.h>
+#include <SHP/ShpCommandType.h>
 
+//Uncomment to see what join algorithm is used for the join operation
+//
+//#define DEBUG_FEATURE_JOIN
 
 /////////////////////////////////////////////////////////////////////
 //
@@ -31,14 +36,33 @@
 //
 /////////////////////////////////////////////////////////////////////
 
-static bool supportOrdering (FdoIConnection * conn)
+static bool supportOrdering (FdoIConnection * conn, bool bSingleJoinProperty)
 {
     FdoPtr<FdoICommandCapabilities> ptrCap;
     ptrCap = conn->GetCommandCapabilities();
     assert (ptrCap);
     if (ptrCap == NULL)
         return false;
-    return ptrCap->SupportsSelectOrdering();
+
+    //Even if standard select ordering is not supported, we can still 
+    //sort if the join is on a single property and the extended select
+    //command is supported
+    FdoInt32 size = 0;
+    FdoInt32* pTypes = ptrCap->GetCommands(size);
+    bool bSupportsExtendedSelect = false;
+    for(int i = 0; i < size; i++ )
+    {
+        if( pTypes[i] == SdfCommandType_ExtendedSelect || 
+            pTypes[i] == ShpCommandType_ExtendedSelect || 
+            pTypes[i] == FdoCommandType_ExtendedSelect)
+        {
+            bSupportsExtendedSelect = true;
+            break;
+        }
+    }
+
+    return ptrCap->SupportsSelectOrdering() ||
+        (bSupportsExtendedSelect && bSingleJoinProperty);
 }
 
 
@@ -322,7 +346,7 @@
             FdoPtr<FdoIConnection>  conn =
                         m_connectionpool->GetConnection (
                                                 lfqdef->ClassName ().FeatureSource ());
-            lSupportsOrdering = supportOrdering (conn);
+            lSupportsOrdering = supportOrdering (conn, lCols->GetCount() == 1);
             pLeftQuery = PrepareFeatureQuery (
                 lfqdef, lSupportsOrdering ? lCols.p : NULL, lfqdef->GetOrderingOption(), subsuffix);
 
@@ -356,7 +380,7 @@
             FdoPtr<FdoIConnection>  conn =
                         m_connectionpool->GetConnection (
                                                 rfqdef->ClassName ().FeatureSource ());
-            rSupportsOrdering = supportOrdering (conn);
+            rSupportsOrdering = supportOrdering (conn, rCols->GetCount() == 1);
 
             pRightQuery = PrepareFeatureQuery (rfqdef,
                                             rSupportsOrdering ? rCols.p : NULL,
@@ -422,6 +446,23 @@
             }
         }
 
+#ifdef DEBUG_FEATURE_JOIN
+        std::string sJoinType;
+        if (joinmethod == eGwsNestedLoops)
+            sJoinType = "eGwsNestedLoops";
+        else if (joinmethod == eGwsSortMerge)
+            sJoinType = "eGwsSortMerge";
+        else if (joinmethod == eGwsNestedLoopSortedBlock)
+            sJoinType = "eGwsNestedLoopSortedBlock";
+        else if (joinmethod == eGwsBatchSortedBlock)
+            sJoinType = "eGwsBatchSortedBlock";
+        else if (joinmethod == eGwsHash)
+            sJoinType = "eGwsHash";
+
+        if (!sJoinType.empty())
+            printf("CGwsFeatureSourceQuery::PrepareJoinQuery() - Using method: %s\n", sJoinType.c_str());
+#endif
+
         prepQuery = CreatePreparedJoinQuery (pFQuery->Type (),
                                              joinmethod,
                                              pLeftQuery,

Modified: trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsPreparedFeatureQuery.cpp
===================================================================
--- trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsPreparedFeatureQuery.cpp	2011-12-13 07:10:47 UTC (rev 6332)
+++ trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsPreparedFeatureQuery.cpp	2011-12-15 00:00:37 UTC (rev 6333)
@@ -30,6 +30,10 @@
 #include "FdoExpressionEngineCopyFilter.h"
 #include "FdoExpressionEngineFilterProcessor.h"
 
+//Uncomment to track how many FdoISelect commands are executed for a join
+//operation. Each executed command prints [Query] to stdout
+//
+//#define TRACE_GWS_QUERY
 
 /////////////////////////////////////////////////////////////////////
 //
@@ -392,6 +396,9 @@
     try {
         FdoPtr<FdoFilter> filter = ((FdoISelect *)m_pCommand.p)->GetFilter ();
         PrepareFilter (filter, m_bIsAxisAlignedRectangleFilter);
+        #ifdef TRACE_GWS_QUERY
+        printf("[Query]");
+        #endif
         #ifdef _DEBUG_BATCHSORT_JOIN
         if(filter)
         {

Modified: trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsRightSortedJoinQueryResults.cpp
===================================================================
--- trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsRightSortedJoinQueryResults.cpp	2011-12-13 07:10:47 UTC (rev 6332)
+++ trunk/MgDev/Server/src/Gws/GwsQueryEngine/GwsRightSortedJoinQueryResults.cpp	2011-12-15 00:00:37 UTC (rev 6333)
@@ -24,7 +24,7 @@
 #include "stdafx.h"
 #include "GwsQueryEngineImp.h"
 
-
+//#define DEBUG_SORT_MERGE_JOIN
 /////////////////////////////////////////////////////////////////////
 //
 // class CGwsRightSortedJoinQueryResults
@@ -115,6 +115,16 @@
         m_joinvals = joinvals;
         int res = m_joinkeys.Compare (m_joinvals);
 
+#ifdef DEBUG_SORT_MERGE_JOIN
+        wchar_t* lbuffer = new wchar_t[2048];
+        m_joinkeys.ToString(lbuffer, 2048);
+        wchar_t* rbuffer = new wchar_t[2048];
+        m_joinvals.ToString(rbuffer, 2048);
+        printf("%S == %S : %d\n", lbuffer, rbuffer, res);
+        delete [] lbuffer;
+        delete [] rbuffer;
+#endif
+
         if (res == 1) {
             bRes = m_reader->ReadNext ();
             if (! bRes)



More information about the mapguide-commits mailing list