]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add an optional bitmask of allowed optimizations on the "PRAGMA optimize"
authordrh <drh@noemail.net>
Thu, 2 Mar 2017 14:17:21 +0000 (14:17 +0000)
committerdrh <drh@noemail.net>
Thu, 2 Mar 2017 14:17:21 +0000 (14:17 +0000)
command.  The 0x01 bit is Debug Mode.

FossilOrigin-Name: a35388eef4096c1856b025dbd90143409d4a72d3

manifest
manifest.uuid
src/pragma.c
src/pragma.h
tool/mkpragmatab.tcl

index bbbb0936a4ac63dd1298079e66af88002f4a7001..fb60f9c239d80c379c4999d8a3c7ebf2da10d80c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\srecent\strunk\senhancements.
-D 2017-03-02T13:22:04.261
+C Add\san\soptional\sbitmask\sof\sallowed\soptimizations\son\sthe\s"PRAGMA\soptimize"\ncommand.\s\sThe\s0x01\sbit\sis\sDebug\sMode.
+D 2017-03-02T14:17:21.291
 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc a89ea37ab5928026001569f056973b9059492fe2
@@ -389,8 +389,8 @@ F src/parse.y af8830094f4aecb91cb69721f3601ad10c36abc4
 F src/pcache.c 62835bed959e2914edd26afadfecce29ece0e870
 F src/pcache.h 2cedcd8407eb23017d92790b112186886e179490
 F src/pcache1.c e3967219b2a92b9edcb9324a4ba75009090d3953
-F src/pragma.c 4b32b014bb4b460bbf0103e4631809428c1ce16b
-F src/pragma.h d97dd835c7f4dfb6857487707313385d44fa76c0
+F src/pragma.c 75fdb05838c303cf0ce5846ca011b8103531c42c
+F src/pragma.h c9c763958fec92b04125571472c9500b351c5f7f
 F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a
 F src/printf.c 67427bbee66d891fc6f6f5aada857e9cdb368c1c
 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
@@ -1498,7 +1498,7 @@ F tool/mkmsvcmin.tcl 95b37e202cbed873aa8ffdbb493b9db45927be2b
 F tool/mkopcodec.tcl d1b6362bd3aa80d5520d4d6f3765badf01f6c43c
 F tool/mkopcodeh.tcl a01d2c1d8a6205b03fc635adf3735b4c523befd3
 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
-F tool/mkpragmatab.tcl 9b499f7301fadeddeae52b95f962ef7e5a718f50
+F tool/mkpragmatab.tcl 2ffe6d5fdc2d3381621d6c77978ba054466e757f
 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
 F tool/mksqlite3c-noext.tcl fef88397668ae83166735c41af99d79f56afaabb
 F tool/mksqlite3c.tcl 06b2e6a0f21cc0a5d70fbbd136b3e0a96470645e
@@ -1560,7 +1560,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 7a959f6d1ea038988cdb4c02d6f37abaec2580a0 29f54b899e5cf22ece98ab41c39c41d75a4b228d
-R 6bb37f552ece3665cee38d0fc37ff06c
+P c60cdb47612c05c252613e50a8ac10635469fdfe
+R dbee345c7724a1e9049a9032bbb0a60b
 U drh
-Z 8ce562b5567814952b66c349d10ab9fa
+Z f9893159b19aa2a55c1ddc2fbced30b3
index e6cd24f62f0d8d360b9f69c4e021b48a29c95469..33843811468f5617a6a9d46e170b3cd247ea2b0c 100644 (file)
@@ -1 +1 @@
-c60cdb47612c05c252613e50a8ac10635469fdfe
\ No newline at end of file
+a35388eef4096c1856b025dbd90143409d4a72d3
\ No newline at end of file
index 916ed4aa57e5d129dbe08b32580c826cb4dca63c..c5f2a77eef19fa71cd95123d2d581b1759ff6bfb 100644 (file)
@@ -1864,34 +1864,51 @@ void sqlite3Pragma(
 
   /*
   **  PRAGMA optimize
+  **  PRAGMA optimize(MASK)
   **  PRAGMA schema.optimize
+  **  PRAGMA schema.optimize(MASK)
   **
   ** Attempt to optimize the database.  All schemas are optimized in the first
-  ** form, and only the specified schema is optimized in the second form.
+  ** two forms, and only the specified schema is optimized in the latter two.
   **
   ** The details of optimizations performed by this pragma does are expected
   ** to change and improve over time.  Applications should anticipate that
   ** this pragma will perform new optimizations in future releases.
   **
-  ** Argments to this pragma are currently ignored, but future enhancements
-  ** might make use of arguments to control which optimizations are allowed
-  ** or to suggest limits on how much CPU time and I/O should be expended
-  ** in the optimization effort.
+  ** The optional argument is a bitmask of optimizations to perform:
   **
-  ** The current implementation runs ANALYZE on any tables which might have 
-  ** benefitted from having recent statistics at some point since the start
-  ** of the current connection.  Only tables in "schema" are analyzed in the 
-  ** second form.  In the first form, all tables except TEMP tables are
-  ** checked.
+  **    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.
   **
-  ** In the current implementation, a table is analyzed only if both of
+  **    0x0002    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.
+  **
+  **    0x0008    (Not yet implemented) Create indexes that might have
+  **              been helpful to recent queries
+  **
+  ** The default MASK is 0x000e, which means perform all of the optimizations
+  ** listed above except do not set Debug Mode.  New optimizations may be
+  ** added in future releases but they will be turned off by default.  The
+  ** default MASK will always be 0x0e.
+  **
+  ** DETERMINATION OF WHEN TO RUN ANALYZE
+  **
+  ** In the current implementation, a table is analyzed if only if all of
   ** the following are true:
   **
-  ** (1) The query planner used sqlite_stat1-style statistics for one or
+  ** (1) MASK bit 0x02 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) One or more indexes of the table are currently unanalyzed OR
+  ** (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
   **     since the last time ANALYZE was run.
   **
@@ -1907,7 +1924,14 @@ void sqlite3Pragma(
     Index *pIdx;           /* An index of the table */
     LogEst szThreshold;    /* Size threshold above which reanalysis is needd */
     char *zSubSql;         /* SQL statement for the OP_SqlExec opcode */
+    u32 opMask;            /* Mask of operations to perform */
 
+    if( zRight ){
+      opMask = (u32)sqlite3Atoi(zRight);
+      if( (opMask & 0x02)==0 ) break;
+    }else{
+      opMask = 0xe;
+    }
     iTabCur = pParse->nTab++;
     for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
       if( iDb==1 ) continue;
@@ -1932,12 +1956,18 @@ void sqlite3Pragma(
         if( szThreshold ){
           sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
           sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur, 
-                            sqlite3VdbeCurrentAddr(v)+2, szThreshold);
+                         sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
           VdbeCoverage(v);
         }
         zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
                                  db->aDb[iDb].zDbSName, pTab->zName);
-        sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
+        if( opMask & 0x01 ){
+          int r1 = sqlite3GetTempReg(pParse);
+          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);
+        }
       }
     }
     sqlite3VdbeAddOp0(v, OP_Expire);
index 363975df55a5421eb634a886a0b420143fa6a066..9b1c723b3ed2158ccf88420d5cacef777f6be18a 100644 (file)
@@ -417,7 +417,7 @@ static const PragmaName aPragmaName[] = {
 #endif
  {/* zName:     */ "optimize",
   /* ePragTyp:  */ PragTyp_OPTIMIZE,
-  /* ePragFlg:  */ PragFlg_NoColumns,
+  /* ePragFlg:  */ PragFlg_Result1,
   /* ColNames:  */ 0, 0,
   /* iArg:      */ 0 },
 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
index f0ba49b5452dac05516c6e132fe47e57742698a4..59b245cc761e5bda700c9c293afdb3c98d00c5fe 100644 (file)
@@ -363,7 +363,7 @@ set pragma_def {
   FLAG: Result0
 
   NAME: optimize
-  FLAG: NoColumns
+  FLAG: Result1
 }
 
 # Open the output file