Add new MASK bits to PRAGMA optimize: 0x70000.
FossilOrigin-Name: dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29
This commit is contained in:
parent
837efb4cbe
commit
42eb6a91cd
19
manifest
19
manifest
@ -1,5 +1,5 @@
|
||||
C The\sPRAGMA\soptimize\scommand\sinvokes\sANALYZE\sif\sa\stable\sshrinks\sby\s25\stimes\nin\saddition\sto\sif\sit\sgrows\sby\s25\stimes.
|
||||
D 2024-02-17T01:12:58.951
|
||||
C Add\snew\sMASK\sbits\sto\sPRAGMA\soptimize:\s\s0x70000.
|
||||
D 2024-02-17T16:39:52.117
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -681,7 +681,7 @@ F src/btmutex.c 79a43670447eacc651519a429f6ece9fd638563cf95b469d6891185ddae2b522
|
||||
F src/btree.c dfd351decf9f819393dae8fb7294cae69c3818069d27f47fee34d5b505e37b47
|
||||
F src/btree.h 03e3356f5208bcab8eed4e094240fdac4a7f9f5ddf5e91045ce589f67d47c240
|
||||
F src/btreeInt.h 3e2589726c4f105e653461814f65857465da68be1fac688de340c43b873f4062
|
||||
F src/build.c 05c9eb387638982092988d2ef4c00a91b0c29baa1b85923f082ce0cf2903ea7e
|
||||
F src/build.c 04f1bcee189f045ab086d84fee95db42cb49df82ff8e84af8136309ff3c8a75f
|
||||
F src/callback.c db3a45e376deff6a16c0058163fe0ae2b73a2945f3f408ca32cf74960b28d490
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c 23331529e654be40ca97d171cbbffe9b3d4c71cc53b78fe5501230675952da8b
|
||||
@ -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 2a49dd92e9f14eb7433c06d02f5d02b7e2890b05117e7c5be103a9da1251ba0d
|
||||
F src/pragma.c c5b767e7538a808fac4f17f8891acb1f14b4eed3458d971ddea4dd82f7623e0c
|
||||
F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
|
||||
F src/prepare.c 371f6115cb69286ebc12c6f2d7511279c2e47d9f54f475d46a554d687a3b312c
|
||||
F src/printf.c 18fbdf028345c8fbe6044f5f5bfda5a10d48d6287afef088cc21b0ca57985640
|
||||
@ -809,7 +809,7 @@ F src/upsert.c fa125a8d3410ce9a97b02cb50f7ae68a2476c405c76aa692d3acf6b8586e9242
|
||||
F src/utf.c f23165685a67b4caf8ec08fb274cb3f319103decfb2a980b7cfd55d18dfa855e
|
||||
F src/util.c 078f040366d5bd5f47658d045f901c768c1c636c6eaea121f3a1cbd63c3edb5b
|
||||
F src/vacuum.c 604fcdaebe76f3497c855afcbf91b8fa5046b32de3045bab89cc008d68e40104
|
||||
F src/vdbe.c a9b83d5ecd34d7e9d50dc7b643351541ddac74b5e2b19770cb3f2686cb815066
|
||||
F src/vdbe.c 6d2aecc9ab2f9db557b4841775d016e2697ff6312242e9a492cdf3e2529dffa6
|
||||
F src/vdbe.h 88e19a982df9027ec1c177c793d1a5d34dc23d8f06e3b2d997f43688b05ee0eb
|
||||
F src/vdbeInt.h 949669dfd8a41550d27dcb905b494f2ccde9a2e6c1b0b04daa1227e2e74c2b2c
|
||||
F src/vdbeapi.c 8f57d60c89da0b60e6d4e272358c511f6bae4e24330bdb11f8b42f986d1bf21b
|
||||
@ -2162,11 +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 1c33c5db2e05019d1a375109f79ad8588a3c17f81e4f4b8d66c880c3c860e87e
|
||||
R 56c40cfd7fd1a612586d6162b2f4f953
|
||||
T *branch * optimize-after-shrink
|
||||
T *sym-optimize-after-shrink *
|
||||
T -sym-trunk *
|
||||
P 40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7
|
||||
R 518017150456f4f932816e90c763b561
|
||||
U drh
|
||||
Z ebc951629700e2b49319b3c4b80fffe0
|
||||
Z 4ff4c253b76c891ec5769cfa9bfe8766
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
40532ffba91cf332c1ea4add80184031a9d6e10514d2d9b9a6cfd613091b81f7
|
||||
dd4497062569eec9ddfdaa7d6394c83ff40a7a59c6697a161bc4ff6d8af3bb29
|
@ -2923,11 +2923,11 @@ void sqlite3EndTable(
|
||||
/* Test for cycles in generated columns and illegal expressions
|
||||
** in CHECK constraints and in DEFAULT clauses. */
|
||||
if( p->tabFlags & TF_HasGenerated ){
|
||||
sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
|
||||
sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
|
||||
sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"",
|
||||
db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
|
||||
}
|
||||
sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
|
||||
sqlite3VdbeAddOp4(v, OP_SqlExec, 0x0001, 0, 0,
|
||||
sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)",
|
||||
db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
|
||||
}
|
||||
|
94
src/pragma.c
94
src/pragma.c
@ -2383,44 +2383,57 @@ void sqlite3Pragma(
|
||||
**
|
||||
** The optional argument is a bitmask of optimizations to perform:
|
||||
**
|
||||
** 0x0001 Debugging mode. Do not actually perform any optimizations
|
||||
** but instead return one line of text for each optimization
|
||||
** that would have been done. Off by default.
|
||||
** 0x00001 Debugging mode. Do not actually perform any optimizations
|
||||
** but instead return one line of text for each optimization
|
||||
** that would have been done. Off by default.
|
||||
**
|
||||
** 0x0002 Run ANALYZE on tables that might benefit. On by default.
|
||||
** See below for additional information.
|
||||
** 0x00002 Run ANALYZE on tables that might benefit. On by default.
|
||||
** See below for additional information.
|
||||
**
|
||||
** 0x0004 (Not yet implemented) Record usage and performance
|
||||
** information from the current session in the
|
||||
** database file so that it will be available to "optimize"
|
||||
** pragmas run by future database connections.
|
||||
** 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.
|
||||
**
|
||||
** 0x0008 (Not yet implemented) Create indexes that might have
|
||||
** been helpful to recent queries
|
||||
** 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.
|
||||
**
|
||||
** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
|
||||
** of the optimizations listed above except Debug Mode, including new
|
||||
** optimizations that have not yet been invented. If new optimizations are
|
||||
** ever added that should be off by default, those off-by-default
|
||||
** optimizations will have bitmasks of 0x10000 or larger.
|
||||
** 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
|
||||
** added in the future. Optimizations that are off by default and must
|
||||
** be explicitly requested have masks of 0x10000 or greater.
|
||||
**
|
||||
** DETERMINATION OF WHEN TO RUN ANALYZE
|
||||
**
|
||||
** In the current implementation, a table is analyzed if only if all of
|
||||
** the following are true:
|
||||
**
|
||||
** (1) MASK bit 0x02 is set.
|
||||
** (1) MASK bit 0x00002 is set.
|
||||
**
|
||||
** (2) The query planner used sqlite_stat1-style statistics for one or
|
||||
** more indexes of the table at some point during the lifetime of
|
||||
** the current connection.
|
||||
** (2) Either the 0x10000 MASK bit is set or else the query planner used
|
||||
** sqlite_stat1-style statistics for one or more indexes of the table
|
||||
** 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 by 25 times or more
|
||||
** 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.
|
||||
**
|
||||
** (4) The table is an ordinary table, not a virtual table or view.
|
||||
**
|
||||
** (5) The table name does not begin with "sqlite_".
|
||||
**
|
||||
** The rules for when tables are analyzed are likely to change in
|
||||
** future releases.
|
||||
** future releases. Future versions of SQLite might accept a string
|
||||
** literal argument to this pragma that contains a mnemonic description
|
||||
** of the options rather than a bitmap.
|
||||
*/
|
||||
case PragTyp_OPTIMIZE: {
|
||||
int iDbLast; /* Loop termination point for the schema loop */
|
||||
@ -2432,6 +2445,11 @@ void sqlite3Pragma(
|
||||
LogEst szThreshold; /* Size threshold above which reanalysis needed */
|
||||
char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
|
||||
u32 opMask; /* Mask of operations to perform */
|
||||
int nLimit; /* Analysis limit to use */
|
||||
|
||||
#ifndef SQLITE_DEFAULT_OPTIMIZE_LIMIT
|
||||
# define SQLITE_DEFAULT_OPTIMIZE_LIMIT 400
|
||||
#endif
|
||||
|
||||
if( zRight ){
|
||||
opMask = (u32)sqlite3Atoi(zRight);
|
||||
@ -2439,6 +2457,14 @@ void sqlite3Pragma(
|
||||
}else{
|
||||
opMask = 0xfffe;
|
||||
}
|
||||
if( (opMask & 0x20000)==0 ){
|
||||
nLimit = 0;
|
||||
}else if( db->nAnalysisLimit>0
|
||||
&& db->nAnalysisLimit<SQLITE_DEFAULT_OPTIMIZE_LIMIT ){
|
||||
nLimit = 0;
|
||||
}else{
|
||||
nLimit = SQLITE_DEFAULT_OPTIMIZE_LIMIT;
|
||||
}
|
||||
iTabCur = pParse->nTab++;
|
||||
for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
|
||||
if( iDb==1 ) continue;
|
||||
@ -2447,10 +2473,20 @@ void sqlite3Pragma(
|
||||
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
|
||||
pTab = (Table*)sqliteHashData(k);
|
||||
|
||||
/* This only works for ordinary tables */
|
||||
if( !IsOrdinaryTable(pTab) ) continue;
|
||||
|
||||
/* Do not scan system tables */
|
||||
if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ) continue;
|
||||
|
||||
/* If table pTab has not been used in a way that would benefit from
|
||||
** having analysis statistics during the current session, then skip it.
|
||||
** This also has the effect of skipping virtual tables and views */
|
||||
if( (pTab->tabFlags & TF_MaybeReanalyze)==0 ) continue;
|
||||
** having analysis statistics during the current session, then skip it,
|
||||
** unless the 0x10000 MASK bit is set. */
|
||||
if( (pTab->tabFlags & TF_MaybeReanalyze)==0
|
||||
&& (opMask & 0x10000)==0
|
||||
){
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Reanalyze if the table is 25 times larger than the last analysis */
|
||||
szThreshold = pTab->nRowLogEst;
|
||||
@ -2461,11 +2497,12 @@ void sqlite3Pragma(
|
||||
}
|
||||
}
|
||||
if( szThreshold>=0 ){
|
||||
LogEst iRange = (opMask & 0x40000) ? 33 : 46;
|
||||
sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
|
||||
sqlite3VdbeAddOp4Int(v, OP_IfSizeBetween, iTabCur,
|
||||
sqlite3VdbeCurrentAddr(v)+3+(opMask&1),
|
||||
szThreshold>=46 ? szThreshold-46 : -1,
|
||||
szThreshold+46);
|
||||
szThreshold>=iRange ? szThreshold-iRange : -1,
|
||||
szThreshold+iRange);
|
||||
sqlite3VdbeAddOp1(v, OP_Close, iTabCur);
|
||||
VdbeCoverage(v);
|
||||
}
|
||||
@ -2476,7 +2513,8 @@ void sqlite3Pragma(
|
||||
sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
|
||||
sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
|
||||
}else{
|
||||
sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
|
||||
sqlite3VdbeAddOp4(v, OP_SqlExec, nLimit ? 0x02 : 00, nLimit, 0,
|
||||
zSubSql, P4_DYNAMIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
src/vdbe.c
21
src/vdbe.c
@ -6922,11 +6922,18 @@ case OP_CreateBtree: { /* out2 */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: SqlExec * * * P4 *
|
||||
/* Opcode: SqlExec P1 P2 * P4 *
|
||||
**
|
||||
** Run the SQL statement or statements specified in the P4 string.
|
||||
** Disable Auth and Trace callbacks while those statements are running if
|
||||
** P1 is true.
|
||||
**
|
||||
** The P1 parameter is a bitmask of options:
|
||||
**
|
||||
** 0x0001 Disable Auth and Trace callbacks while the statements
|
||||
** in P4 are running.
|
||||
**
|
||||
** 0x0002 Set db->nAnalysisLimit to P2 while the statements in
|
||||
** P4 are running.
|
||||
**
|
||||
*/
|
||||
case OP_SqlExec: {
|
||||
char *zErr;
|
||||
@ -6934,6 +6941,7 @@ case OP_SqlExec: {
|
||||
sqlite3_xauth xAuth;
|
||||
#endif
|
||||
u8 mTrace;
|
||||
int savedAnalysisLimit;
|
||||
|
||||
sqlite3VdbeIncrWriteCounter(p, 0);
|
||||
db->nSqlExec++;
|
||||
@ -6942,18 +6950,23 @@ case OP_SqlExec: {
|
||||
xAuth = db->xAuth;
|
||||
#endif
|
||||
mTrace = db->mTrace;
|
||||
if( pOp->p1 ){
|
||||
savedAnalysisLimit = db->nAnalysisLimit;
|
||||
if( pOp->p1 & 0x0001 ){
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
db->xAuth = 0;
|
||||
#endif
|
||||
db->mTrace = 0;
|
||||
}
|
||||
if( pOp->p1 & 0x0002 ){
|
||||
db->nAnalysisLimit = pOp->p2;
|
||||
}
|
||||
rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
|
||||
db->nSqlExec--;
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
db->xAuth = xAuth;
|
||||
#endif
|
||||
db->mTrace = mTrace;
|
||||
db->nAnalysisLimit = savedAnalysisLimit;
|
||||
if( zErr || rc ){
|
||||
sqlite3VdbeError(p, "%s", zErr);
|
||||
sqlite3_free(zErr);
|
||||
|
Loading…
Reference in New Issue
Block a user