-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
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
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.
** 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 */
}
#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 */
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.
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;
pWLoop->rStarDelta = rDelta;
}
}
- }
+ }
}
return pWInfo->nOutStarDelta>0 ? 18 : 12;
}
}else if( nLoop==2 ){
mxChoice = 5;
}else{
- mxChoice = computeMxChoice(pWInfo, nRowEst);
+ mxChoice = computeMxChoice(pWInfo);
}
assert( nLoop<=pWInfo->pTabList->nSrc );
}
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);
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);
}
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 */