diff options
-rw-r--r-- | manifest | 12 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/pragma.c | 22 |
3 files changed, 28 insertions, 8 deletions
@@ -1,5 +1,5 @@ -C Merge\strunk\sfixes\sinto\sthe\sbetter-optimize\sbranch. -D 2024-02-19T18:55:32.241 +C In\sPRAGMA\soptimize,\sscale\sback\sthe\sanalysis_limit\swhen\smany\sdifferent\stables\nand\sindexes\smust\sbe\sscanned. +D 2024-02-19T19:56:40.420 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 0bd3737acf69282fb1733e170a88a5caf3dba088092665e603ee5a6d651c0e2f +F src/pragma.c c72ba9c8b300d713a318e7d199bc1d3f717f961c75de403f8db291841f2f58aa F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c F src/printf.c d3392b2a20ee314ddeef34fb43c904bf4619eb20ff9a9e07e3950a7e4dcd6912 @@ -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 e147b18991dd462fff367442acb0504fdf193a31843ed34ec8c1ced30747bf8a f18b2524da6bbbcf372b292df52fbe6efa49fd6e1f1f13ef2447279d559f7a08 -R fada2b9bf9b286f261a00cb9eda0fee2 +P 2cf78a5b5fce7f2d49ce185d27f50722c91a1d6c91bbcecebd4bb5244a76769f +R c2c83408fc346dde3baee32faaf6bad7 U drh -Z 513df274231a3535cbd843c1569f620b +Z ec6824937a1b6fb54f3b9fdcf77219f7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b04ec72a3..aa9236de9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2cf78a5b5fce7f2d49ce185d27f50722c91a1d6c91bbcecebd4bb5244a76769f
\ No newline at end of file +636615358aebfef80a657d09f15f608df9e64882b2aaa5574ce31a4f1c71fd70
\ No newline at end of file diff --git a/src/pragma.c b/src/pragma.c index 77ec9a57e..18fc88ace 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -2460,7 +2460,7 @@ void sqlite3Pragma( ** of the current connection. ** ** (5) One or more of the following is true: - ** (5a) One or mroe indexes on the table lacks an entry + ** (5a) One or more indexes on the table lacks an entry ** in the sqlite_stat1 table. (Same as 4a) ** (5b) The number of rows in the table has increased or decreased by ** 10-fold. In other words, the current size of the table is @@ -2484,6 +2484,8 @@ void sqlite3Pragma( u32 opMask; /* Mask of operations to perform */ int nLimit; /* Analysis limit to use */ int nCheck = 0; /* Number of tables to be optimized */ + int nBtree = 0; /* Number of btrees to scan */ + int nIndex; /* Number of indexes on the current table */ if( zRight ){ opMask = (u32)sqlite3Atoi(zRight); @@ -2518,7 +2520,9 @@ void sqlite3Pragma( ** indicate a new, unanalyzed index */ szThreshold = pTab->nRowLogEst; + nIndex = 0; for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ + nIndex++; if( !pIdx->hasStat1 ){ szThreshold = -1; /* Always analyze if any index lacks statistics */ break; @@ -2545,6 +2549,7 @@ void sqlite3Pragma( ** transaction for efficiency */ sqlite3BeginWriteOperation(pParse, 0, iDb); } + nBtree += nIndex+1; /* Reanalyze if the table is 10 times larger or smaller than ** the last analysis. Unconditional reanalysis if there are @@ -2572,6 +2577,21 @@ void sqlite3Pragma( } } sqlite3VdbeAddOp0(v, OP_Expire); + + /* In a schema with a large number of tables and indexes, scale back + ** the analysis_limit to avoid excess run-time in the worst case. + */ + if( !db->mallocFailed && nBtree>100 ){ + int iAddr, iEnd; + VdbeOp *aOp; + int nLimit = 100*SQLITE_DEFAULT_OPTIMIZE_LIMIT/nBtree; + if( nLimit<100 ) nLimit = 100; + aOp = sqlite3VdbeGetOp(v, 0); + iEnd = sqlite3VdbeCurrentAddr(v); + for(iAddr=0; iAddr<iEnd; iAddr++){ + if( aOp[iAddr].opcode==OP_SqlExec ) aOp[iAddr].p2 = nLimit; + } + } break; } |