]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Minor tweaks to the star-query detection and processing.
authordrh <>
Fri, 24 Jan 2025 15:55:20 +0000 (15:55 +0000)
committerdrh <>
Fri, 24 Jan 2025 15:55:20 +0000 (15:55 +0000)
FossilOrigin-Name: 61f76a45ac7aa454419fd7539a3d8e60f0733fb5a2abd034d795328f3c1b6e9b

manifest
manifest.uuid
src/where.c
src/whereInt.h

index 04cbc622ad13a9ca770d9ec3ce41a508631ef8bc..a6cc524f901d30caa40e4aeb132605bbe933571b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C When\slooking\sfor\sstar-queries,\sdo\snot\scount\sa\stable\sas\sa\sdimension\stable\nif\sthat\stable\sis\sseparated\sfrom\sthe\sfact\stable\sby\san\sOUTER\sor\sCROSS\sjoin\nor\sif\sthe\stable\sis\sa\sself-join.
-D 2025-01-24T14:51:15.886
+C Minor\stweaks\sto\sthe\sstar-query\sdetection\sand\sprocessing.
+D 2025-01-24T15:55:20.191
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -863,8 +863,8 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 4e6181d8780ab0af2e1388d0754cbe6f2f04593d2b1ab6c41699a89942fd8997
 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
 F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
-F src/where.c 5112b3f0a27bc9708b26b8dc0a513a38c3f03e58a3ad2a6323aa706d8459d7b7
-F src/whereInt.h 2b0804f300c7f65de4046a1d81c65f01b208d6c08950ccd1fa6b8c16162a8af7
+F src/where.c 3dacc2fa210fa44a55041ddaa6f89da1626a48017817f196f12ceed52723bba0
+F src/whereInt.h 3b2ef4617758174d00c6940850e4988c1b195d39bcc20f2965319a1f7bffc714
 F src/wherecode.c 0c3d3199a2b769a5e2bb70feb5003dc85b3d86842ecaf903a47f2b4205ca5dab
 F src/whereexpr.c 0f93a29cabd3a338d09a1f5c6770620a1ac51ec1157f3229502a7e7767c60b6f
 F src/window.c 2bf01f9941a64fbcead61a0e3cb5db3fca5094b30d2ff0d23274c2a81d2e2385
@@ -2208,11 +2208,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 9a20b94080f5379867530772e081b737ae4cf6b416469dcabb85b8dd819f491f
-R fc36952f8e44ca6141073778b4516171
-T *branch * star-query-heuristic
-T *sym-star-query-heuristic *
-T -sym-trunk *
+P 5aebd7df0d577e98b3affd22b84b42dfe84a9f37fa29187505cc245b95460ba4
+R f847747d05c8cfe1b5f92bc976034b08
 U drh
-Z d58ed75293e728cbf22986bd4a983f27
+Z b010436488b72486e8da8913eae9dd55
 # Remove this line to create a well-formed Fossil manifest.
index 03fb6a033f121c1247308f54418671ab261ba819..f9eccc3e4a5879c6a240b1fb87410529872a5358 100644 (file)
@@ -1 +1 @@
-5aebd7df0d577e98b3affd22b84b42dfe84a9f37fa29187505cc245b95460ba4
+61f76a45ac7aa454419fd7539a3d8e60f0733fb5a2abd034d795328f3c1b6e9b
index 6327f7688e220eb4beb40dbc3ecd6c55d0080b0a..4fa281c15873c1e521205195588980981039e0bb 100644 (file)
@@ -5464,7 +5464,7 @@ static LogEst whereSortingCost(
 ** disable the SQLITE_StarQuery optimization.  In the CLI, the command
 ** to do that is:  ".testctrl opt -starquery".
 */
-static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
+static int computeMxChoice(WhereInfo *pWInfo){
   int nLoop = pWInfo->nLevel;    /* Number of terms in the join */
   WhereLoop *pWLoop;             /* For looping over WhereLoops */
 
@@ -5481,8 +5481,8 @@ static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
   }
 #endif /* SQLITE_DEBUG */
 
-  if( nRowEst==0
-   && nLoop>=5 
+  if( nLoop>=5 
+   && !pWInfo->bStarDone
    && OptimizationEnabled(pWInfo->pParse->db, SQLITE_StarQuery)
   ){
     SrcItem *aFromTabs;    /* All terms of the FROM clause */
@@ -5491,6 +5491,8 @@ static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
     Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */       
     WhereLoop *pStart;     /* Where to start searching for dimension-tables */
 
+    pWInfo->bStarDone = 1; /* Only do this computation once */
+
     /* Check to see if we are dealing with a star schema and if so, reduce
     ** the cost of fact tables relative to dimension tables, as a heuristic
     ** to help keep the fact tables in outer loops.
@@ -5555,12 +5557,10 @@ static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
         sqlite3DebugPrintf("\n");
       }
 #endif
-      if( pWInfo->nOutStarDelta==0 ){
-        for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
-          pWLoop->rStarDelta = 0;
-        }
+      for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
+        pWLoop->rStarDelta = 0;
       }
-      pWInfo->nOutStarDelta += rDelta;
+      pWInfo->nOutStarDelta = rDelta;
       for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
         if( pWLoop->maskSelf==m ){
           pWLoop->rRun -= rDelta;
@@ -5568,7 +5568,7 @@ static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
           pWLoop->rStarDelta = rDelta;
         }
       }
-    }      
+    }
   }
   return pWInfo->nOutStarDelta>0 ? 18 : 12;
 }
@@ -5646,7 +5646,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
   }else if( nLoop==2 ){
     mxChoice = 5;
   }else{
-    mxChoice = computeMxChoice(pWInfo, nRowEst);
+    mxChoice = computeMxChoice(pWInfo);
   }
   assert( nLoop<=pWInfo->pTabList->nSrc );
 
@@ -6015,6 +6015,9 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
   }
 
   pWInfo->nRowOut = pFrom->nRow + pWInfo->nOutStarDelta;
+#ifdef WHERETRACE_ENABLED
+  pWInfo->rTotalCost = pFrom->rCost + pWInfo->nOutStarDelta;
+#endif
 
   /* Free temporary memory and return success */
   sqlite3StackFreeNN(pParse->db, pSpace);
@@ -6895,7 +6898,8 @@ WhereInfo *sqlite3WhereBegin(
   assert( db->mallocFailed==0 );
 #ifdef WHERETRACE_ENABLED
   if( sqlite3WhereTrace ){
-    sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
+    sqlite3DebugPrintf("---- Solution cost=%d, nRow=%d",
+                       pWInfo->rTotalCost, pWInfo->nRowOut);
     if( pWInfo->nOBSat>0 ){
       sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
     }
index f44c040418e6f57aff3766c092cdda726f051856..5bea70ba9fa3374d0790cbdef7591f81242b07ab 100644 (file)
@@ -486,8 +486,12 @@ struct WhereInfo {
   unsigned untestedTerms :1;   /* Not all WHERE terms resolved by outer loop */
   unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
   unsigned sorted :1;          /* True if really sorted (not just grouped) */
+  unsigned bStarDone     :1;   /* True if check for star-query is complete */
   LogEst nOutStarDelta;     /* Artifical nOut reduction for star-query */
   LogEst nRowOut;           /* Estimated number of output rows */
+#ifdef WHERETRACE_ENABLED
+  LogEst rTotalCost;        /* Total cost of the solution */
+#endif
   int iTop;                 /* The very beginning of the WHERE loop */
   int iEndWhere;            /* End of the WHERE clause itself */
   WhereLoop *pLoops;        /* List of all WhereLoop objects */