]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improve whereSolver() so that it always finds a unique solution.
authordrh <>
Mon, 29 Sep 2025 18:17:19 +0000 (18:17 +0000)
committerdrh <>
Mon, 29 Sep 2025 18:17:19 +0000 (18:17 +0000)
FossilOrigin-Name: ae303dab2f534e2c5132112b61fa5a097e7010fd8b652badee669fbe9df5cf53

manifest
manifest.uuid
src/where.c

index f9e282afb6191beae5b6d9da25b47dfbb2e51836..1d754caf1a74b4368a615ffe958a01c79283524e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sJSONB\slogic\sso\sthat\sit\scorrectly\sinterprets\slarge\sJSON5\shexadecimal\ninteger\sliterals\sas\spositive\snumbers.
-D 2025-09-29T14:09:43.536
+C Improve\swhereSolver()\sso\sthat\sit\salways\sfinds\sa\sunique\ssolution.
+D 2025-09-29T18:17:19.545
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -818,7 +818,7 @@ F src/vxworks.h 9d18819c5235b49c2340a8a4d48195ec5d5afb637b152406de95a9436beeaeab
 F src/wal.c a278339ecf5f194fd71fff1f0da1368de50e3a32edc3e9944e1ee1f4610476ff
 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
 F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
-F src/where.c 9d7b4095ae0a34d9604c3e185c65cdf6eca5f2e8707403c526eed798867cece4
+F src/where.c 9e6b0da119a155ee2b0f8f16fc012a23aa5d7cfca8d2298ab5687c05b9110ecd
 F src/whereInt.h 8d94cb116c9e06205c3d5ac87af065fc044f8cf08bfdccd94b6ea1c1308e65da
 F src/wherecode.c 71c5c6804b7f882dec8ec858758accae02fcfca13df3cc720f1f258e663ec7c5
 F src/whereexpr.c 403a44eeec1a0f0914fccc6a59376b6924bc00ef6728fe6ffce4cf3051b320fc
@@ -2169,9 +2169,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 27ae98629406bbaee2857f75c069b2ccd4757b247f0742e51b9e619e96b6dc45 5a93d9dce2d134ca450955bb272baba43dfc76beb540b643bf4bd31f7eb9e0b9
-R c5eadcc40e883cfd8ce7db7f1b19a45b
-T +closed 5a93d9dce2d134ca450955bb272baba43dfc76beb540b643bf4bd31f7eb9e0b9
+P 0ad5d77fc0a9d205cc061ee4923d885f6f28f77c1efef3cc10297036ce164e6d
+R 9d0688a1783d31445cb1e5a298e6561f
 U drh
-Z 83bdf9e436f1896ed55289b3bb74f5a6
+Z 7fcc32fcbbfc1112a0376663c5e3564b
 # Remove this line to create a well-formed Fossil manifest.
index c253922f20e37f3ebc4935e745c58b1e0e06c94f..e8524ca4f01ac0bc75dec069958fa1b6eb26e3fa 100644 (file)
@@ -1 +1 @@
-0ad5d77fc0a9d205cc061ee4923d885f6f28f77c1efef3cc10297036ce164e6d
+ae303dab2f534e2c5132112b61fa5a097e7010fd8b652badee669fbe9df5cf53
index 77a976734a6a903c0ed2d843b452b911b25ba98f..6d3c1d9077b2ee8017f260be02218c5676bdd25c 100644 (file)
@@ -5853,8 +5853,15 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
         ** mxChoice best-so-far paths.
         **
         ** First look for an existing path among best-so-far paths
-        ** that covers the same set of loops and has the same isOrdered
-        ** setting as the current path candidate.
+        ** that:
+        **     (1) covers the same set of loops, and
+        **     (2) has a compatible isOrdered value.
+        **
+        ** "Compatible isOrdered value" means either
+        **     (A) both have isOrdered==-1, or
+        **     (B) both have isOrder>=0, or
+        **     (C) ordering does not matter because this is the last round
+        **         of the solver.
         **
         ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
         ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
@@ -5863,7 +5870,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
         testcase( nTo==0 );
         for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
           if( pTo->maskLoop==maskNew
-           && ((pTo->isOrdered^isOrdered)&0x80)==0
+           && ( ((pTo->isOrdered^isOrdered)&0x80)==0 || ii==nFrom-1 )
           ){
             testcase( jj==nTo-1 );
             break;
@@ -6018,11 +6025,10 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
     return SQLITE_ERROR;
   }
  
-  /* Find the lowest cost path.  pFrom will be left pointing to that path */
+  /* Only one path is available, which is the best path */
+  assert( nFrom==1 );
   pFrom = aFrom;
-  for(ii=1; ii<nFrom; ii++){
-    if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
-  }
+
   assert( pWInfo->nLevel==nLoop );
   /* Load the lowest cost path into pWInfo */
   for(iLoop=0; iLoop<nLoop; iLoop++){