]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Change the 0x20000 bit (use analysis limit) to 0x10, meaning that this feature
authordrh <>
Mon, 19 Feb 2024 13:06:27 +0000 (13:06 +0000)
committerdrh <>
Mon, 19 Feb 2024 13:06:27 +0000 (13:06 +0000)
is on by default.  The default analysis limit is changed to 2000 which is
almost always sufficient for accurate analysis results.

FossilOrigin-Name: 4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444

manifest
manifest.uuid
src/pragma.c
test/busy.test

index e3c3328eb19488b55159e4ebc0611085e7410f7e..54ba56837e05813595ca7fe682d51f36178d345f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Hold\sa\stransaction\sduring\sPRAGMA\soptimize,\sfor\sperformance.
-D 2024-02-18T01:12:22.988
+C Change\sthe\s0x20000\sbit\s(use\sanalysis\slimit)\sto\s0x10,\smeaning\sthat\sthis\sfeature\nis\son\sby\sdefault.\s\sThe\sdefault\sanalysis\slimit\sis\schanged\sto\s2000\swhich\sis\nalmost\salways\ssufficient\sfor\saccurate\sanalysis\sresults.
+D 2024-02-19T13:06:27.586
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -732,7 +732,7 @@ F src/parse.y bfd6da46fc895cd8237400ff485d04ab0b32e47eb56de20982bb7f53e56c1f42
 F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75
 F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5
 F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00
-F src/pragma.c c7ef49d3332badd6e17ac46e0aca762d7973c1e28156bc480c47aa3e56ae4d03
+F src/pragma.c b877efa88ea41560ee5dd95daa30c8cadb743381c59b8921a5143bf0792c6e3b
 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c
 F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640
@@ -947,7 +947,7 @@ F test/boundary4.test 89e02fa66397b8a325d5eb102b5806f961f8ec4b
 F test/btree01.test fef17d9e999ac4f04095948e3438fbe674f4e07bb2c63bb1cad41d87baee077f
 F test/btree02.test 7555a5440453d900410160a52554fe6478af4faf53098f7235f1f443d5a1d6cc
 F test/btreefault.test a82a23b0578bc587afbf9a622c8f54a54f63762f062ba8a35613cfee38ab42f9
-F test/busy.test 510dc6daaad18bcbbc085bcc6217d6dc418def5e73f72ce1475eea0cb7834727
+F test/busy.test caff7164c16ce06a53af51f9e4c2753d4cc64250e00790a5e48b9c4f4be37597
 F test/busy2.test 20823a5d7c42fb257d9f108c66312d90b1bb4ec3d80ba6b4e371073727560f98
 F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de
 F test/cacheflush.test af25bb1509df04c1da10e38d8f322d66eceedf61
@@ -2162,8 +2162,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 dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29
-R 5aca31e5331abdce830c908f0aade7ae
+P d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56
+R e258fa6228ef566d2b5670b2822a20d1
 U drh
-Z 497aafa2ad4da05132856bc0e0f3518f
+Z e864b92d6fb5e0c6f09ca55fa83dd960
 # Remove this line to create a well-formed Fossil manifest.
index 0aec312a780cdff4b900e7a6970b2fdd04eb636a..9cda73c43e934161ac4b643080466e7db235f4dc 100644 (file)
@@ -1 +1 @@
-d13b79eae6df7f9d1f3b8062ddc75a12ff038196b3d752d2672a9925fa45ca56
\ No newline at end of file
+4abd47b5917099a2f74e53e12c987da0722304a5e9a93b6d43015c1f45c48444
\ No newline at end of file
index 9bb971ed77585ecbf4ac2801c75bca787b871711..6e1fc8bc002054922931041d702322ac48a388d4 100644 (file)
 ** ../tool/mkpragmatab.tcl. */
 #include "pragma.h"
 
+/*
+** When the 0x10 bit of PRAGMA optimize is set, any ANALYZE commands
+** will be run with an analysis_limit set to the lessor of the value of
+** the following macro or to the actual analysis_limit if it is non-zero,
+** in order to prevent PRAGMA optimize from running for too long.
+**
+** The value of 2000 is chosen emperically so that the worst-case run-time
+** for PRAGMA optimize does not exceed 100 milliseconds against a variety
+** of test databases on a RaspberryPI-4 compiled using -Os and without
+** -DSQLITE_DEBUG.  Of course, your mileage may vary.  For the purpose of
+** his paragraph, "worst-case" means that ANALYZE ends up being
+** run on every table in the database.  The worst case typically only
+** happens if PRAGMA optimize is run on a database file for which ANALYZE
+** has not been previously run and the 0x10000 flag is included so that
+** all tables are analyzed.  The usual case for PRAGMA optimize is that
+** no ANALYZE commands will be run at all, or if any ANALYZE happens it
+** will be against a single table, so that expected timing for PRAGMA
+** optimize on a PI-4 is more like 1 millisecond or less with the 0x10000
+** flag or less than 100 microseconds without the 0x10000 flag.
+**
+** An analysis limit of 2000 is almost always sufficient for the query
+** planner to fully characterize an index.  The additional accuracy from
+** a larger analysis is not usually helpful.
+*/
+#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT
+# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 2000
+#endif
+
 /*
 ** Interpret the given string as a safety level.  Return 0 for OFF,
 ** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA.  Return 1 for an empty or
@@ -2390,20 +2418,19 @@ void sqlite3Pragma(
   **    0x00002    Run ANALYZE on tables that might benefit.  On by default.
   **               See below for additional information.
   **
+  **    0x00010    Run all ANALYZE operations using an analysis_limit that
+  **               is the lessor of the current analysis_limit and the
+  **               SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option.
+  **               The default value of SQLITE_DEFAULT_OPTIMIZE_LIMIT is
+  **               currently (2024-02-19) set to 2000, which is such that
+  **               the worst case run-time for PRAGMA optimize on a 100MB
+  **               database will usually be less than 100 milliseconds on
+  **               a RaspberryPI-4 class machine.  Off by default.
+  **
   **    0x10000    Look at tables to see if they need to be reanalyzed
   **               even if they have not been queried during the current
   **               connection.  Off by default.
   **
-  **    0x20000    Run all ANALYZE operations using an analysis_limit that
-  **               is the lessor of the current analysis_limit and the
-  **               SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option,
-  **               nominally 400.  Off by default.
-  **
-  **    0x40000    Tables become candidates for reanalysis if their size
-  **               grows or shrinks by 10x.  Without this option, they
-  **               become candidates for reanalysis if their size grows
-  **               or shrinks by 25x.  Off (25x mode) by default.
-  **
   ** The default MASK is and always shall be 0x0fffe.  In the current
   ** implementation, the default mask only covers the 0x00002 optimization,
   ** though additional optimizations that are covered by 0x0fffe might be
@@ -2422,9 +2449,9 @@ void sqlite3Pragma(
   **     at some point during the lifetime of the current connection.
   **
   ** (3) One or more indexes of the table are currently unanalyzed OR
-  **     the number of rows in the table has increased or decreased
-  **     25 times or more (10 times or more if the 0x40000 bit is set)
-  **     since the last time ANALYZE was run.
+  **     the number of rows in the table has increased or decreased by
+  **     10-fold (the new size is either greater than 10 times the old
+  **     size or less than 1/10th of the old size).
   **
   ** (4) The table is an ordinary table, not a virtual table or view.
   **
@@ -2448,17 +2475,13 @@ void sqlite3Pragma(
     int nLimit;            /* Analysis limit to use */
     int once = 0;          /* One-time initialization done */
 
-#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT
-# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 400
-#endif
-
     if( zRight ){
       opMask = (u32)sqlite3Atoi(zRight);
       if( (opMask & 0x02)==0 ) break;
     }else{
       opMask = 0xfffe;
     }
-    if( (opMask & 0x20000)==0 ){
+    if( (opMask & 0x10)==0 ){
       nLimit = 0;
     }else if( db->nAnalysisLimit>0
            && db->nAnalysisLimit<SQLITE_DEFAULT_OPTIMIZE_LIMIT ){
@@ -2490,12 +2513,13 @@ void sqlite3Pragma(
         }
 
         /* Hold a write transaction open for efficiency */
-        if( !once ){
+        if( !once || 1 ){
           sqlite3BeginWriteOperation(pParse, 0, iDb);
           once = 1;
         }
 
-        /* Reanalyze if the table is 25 times larger than the last analysis */
+        /* Reanalyze if the table is 10 times larger or smaller than
+        ** the last analysis */
         szThreshold = pTab->nRowLogEst;
         for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
           if( !pIdx->hasStat1 ){
@@ -2504,7 +2528,7 @@ void sqlite3Pragma(
           }
         }
         if( szThreshold>=0 ){
-          LogEst iRange = (opMask & 0x40000) ? 33 : 46;
+          LogEst iRange = 33;   /* 10x size change */
           sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
           sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur,
                          sqlite3VdbeCurrentAddr(v)+3+(opMask&1),
index be0515b013072ec3b50a2f99bfd7097ef623dab4..896c7fa651e44eeb0c180d1afbc47c25c744f290 100644 (file)
@@ -106,7 +106,7 @@ do_test 3.4 {
 proc busy_handler {n} { return 1 }
 do_test 3.5 {
   catchsql { PRAGMA optimize }
-} {0 {}}
+} {1 {database is locked}}
 
 do_test 3.6 {
   execsql { COMMIT } db2