]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Better comments. Slight tuning of parameters.
authordrh <>
Sun, 31 Dec 2023 20:04:32 +0000 (20:04 +0000)
committerdrh <>
Sun, 31 Dec 2023 20:04:32 +0000 (20:04 +0000)
FossilOrigin-Name: 1cc32eccda8d126264c644df72e308e25c1e41cf4fb68c2f1b6d6d98cbc23ca5

manifest
manifest.uuid
src/analyze.c

index 44c02fd740a9f69f0eba95a07b658e9130e2b600..74e81be18dcbd49ade99dc42d89d77d1f193ea5e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Ensure\sthat\sall\selements\sof\saiRowLogEst[]\shave\sbeen\sinitialized\seven\sif\nthe\sstat\sentry\sis\struncated.
-D 2023-12-31T12:38:43.242
+C Better\scomments.\s\sSlight\stuning\sof\sparameters.
+D 2023-12-31T20:04:32.564
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -670,7 +670,7 @@ F sqlite3.1 acdff36db796e2d00225b911d3047d580cd136547298435426ce9d40347973cc
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
 F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2
 F src/alter.c 30c2333b8bb3af71e4eb9adeadee8aa20edb15917ed44b8422e5cd15f3dfcddc
-F src/analyze.c ac9f1c4c1b84290a4020c9a997472ed547fb69a6a7842b2c08f3e812350afe1b
+F src/analyze.c 47711a594b1e9784164d32715725f01bdb9fed52fd6cfaa2432730e8c3c2b746
 F src/attach.c cc9d00d30da916ff656038211410ccf04ed784b7564639b9b61d1839ed69fd39
 F src/auth.c 19b7ccacae3dfba23fc6f1d0af68134fa216e9040e53b0681b4715445ea030b4
 F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523
@@ -2156,8 +2156,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 41773fa760f10964b3f276a9a45f7e32df0082b516edc76d70609e7eb5f81b14
-R 86aadf86c2aebf26ba64c00e21b31fa8
+P c216921b115169ebfd239267b4ab5ad0fc960ffadce09044b68812f49110d607
+R df3f6be38a64508c745873953ba288dd
 U drh
-Z 5b1f740a8f3b3d58901009fd961c1842
+Z 151bd3600feff84e5eb2b344bddccb6f
 # Remove this line to create a well-formed Fossil manifest.
index bb11e30cec6d5045caf5ed1a88c80e09032e2822..8594bab57765c1a585cd79c89b6a245860332f1e 100644 (file)
@@ -1 +1 @@
-c216921b115169ebfd239267b4ab5ad0fc960ffadce09044b68812f49110d607
\ No newline at end of file
+1cc32eccda8d126264c644df72e308e25c1e41cf4fb68c2f1b6d6d98cbc23ca5
\ No newline at end of file
index 8a3609b842c12da6a43ec8813598913c0033a50e..968f162adf8edd5eb8dc46c2fccc0b3e23486a18 100644 (file)
@@ -881,8 +881,13 @@ static void statGet(
         ** estimated number of rows in the index. */
         iVal = p->nEst;
       }else if( iVal<mx/10 ){
-        /* Report uneven= if the maximum run of identical values ever
-        ** reaches or exceeds 10 times the average run */
+        /*              ^^-- TUNING: threshold for when uneven=NNN is reported
+        ** tag-20231231-01:  Report uneven= if the maximum run of identical
+        ** values ever reaches or exceeds 10 (or so) times the average run.
+        ** The reporting threshold of 10 is tunable, but if changed, one
+        ** should also consider changing the aiRowLogEst adjustment factor at
+        ** tag-20231231-02.
+        */
         int iRatio = mx/iVal;
         if( iUneven<iRatio ) iUneven = iRatio;
       }else if( iVal==2 && p->nRow*10 <= nDistinct*11 ){
@@ -894,11 +899,21 @@ static void statGet(
 
       /* Add the "slow" argument if the peak number of rows obtained
       ** from a full equality match is so large that a full table scan
-      ** seems likely to be faster.
+      ** seems likely to be faster than using the index.  The query planner
+      ** will use the "slow" argument as a hint to avoid using this index
+      ** for equality lookups.
+      **
+      ** We let ANALYZE determine "slow" rather than the query planner for
+      ** two reasons: (1) It leaves a visible trace in the sqlite_stat1 table
+      ** that an index is not useful, and hence serves as a hint to the
+      ** application developers that the index is a good candidate to be
+      ** dropped.  (2) Being able to use UPDATE to control the presence or
+      ** absence of the "slow" argument in sqlite_stat1 enables greater
+      ** control over the query planner during testing.
       */
       if( i==p->nKeyCol-1
-       && nRow > 1000
-       && nRow <= iVal*iUneven + sqlite3LogEst(nRow*2/3)
+       && nRow > 1000 && nRow <= iVal*iUneven + sqlite3LogEst(nRow) - 6 
+              /* ^^^^------------- TUNING ----------------------------^ */
       ){
         sqlite3_str_appendf(&sStat, " slow");
       }
@@ -1576,6 +1591,7 @@ static void decodeIntArray(
     pIndex->bUnordered = 0;
     pIndex->noSkipScan = 0;
     pIndex->bSlow = 0;
+    assert( aLog!=0 );
     while( z[0] ){
       if( sqlite3_strglob("unordered*", z)==0 ){
         pIndex->bUnordered = 1;
@@ -1591,9 +1607,22 @@ static void decodeIntArray(
         /* An argument of "uneven=NNN" means that the maximum length
         ** run of the same value is NNN times longer than the average.
         ** Go through the iaRowLogEst[] values for the index and increase
-        ** them so that so that they are each no less than 1/8th the
-        ** maximum value. */
-        LogEst scale = sqlite3LogEst(sqlite3Atoi(z+7)) - 30;
+        ** them by 0.1*NNN, so that so that they are each about 1/10th of
+        ** of the maximum value.
+        **
+        ** The stat column continues to hold the average run length, and
+        ** then the average is adjusted by the uneven=NNN value.  We do this
+        ** instead of adjusting the run length values in the main body of
+        ** the stat column for backwards compatibility to older versions of
+        ** SQLite that expect values in state to be the true the average.
+        ** Also because the file format specifies that the values in the main
+        ** body of the stat column should be the true average.
+        **
+        ** tag-20231231-02: The 1/10th threshold is tunable.  But if changed,
+        ** one should make a similar adjustment to the uneven=NNN threashold
+        ** at tag-20231231-01:                TUNING ----vv        */
+        LogEst scale = sqlite3LogEst(sqlite3Atoi(z+7)) - 33;
+        assert( sqlite3LogEst(10)==33 );
         if( scale>0 ){
           LogEst mx = aLog[0];
           int jj;