]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Initial implementation of SQLITE_DBSTATUS_SPILL. Does not yet take into
authordrh <>
Thu, 18 Sep 2025 14:51:23 +0000 (14:51 +0000)
committerdrh <>
Thu, 18 Sep 2025 14:51:23 +0000 (14:51 +0000)
account sorters or transient tables.

FossilOrigin-Name: 4e63ee20f80e486ecc4aa4523afa43f994c267e638f8f084f0d6df369aa74a1d

manifest
manifest.tags
manifest.uuid
src/shell.c.in
src/sqlite.h.in
src/sqliteInt.h
src/status.c

index 08d8b07c901b76e50dd8517c61f0fa8444733f91..c29aeb9b1dc86447223d1ac185bc7f2047ad0f0a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\ssqlite3_db_status64()\sinterface.
-D 2025-09-17T19:19:52.225
+C Initial\simplementation\sof\sSQLITE_DBSTATUS_SPILL.\s\sDoes\snot\syet\stake\sinto\naccount\ssorters\sor\stransient\stables.
+D 2025-09-18T14:51:23.014
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -743,13 +743,13 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c b95181711d59c36d9789e67f76c4cfec64b99f9629a50be5e6566e117b87d957
-F src/shell.c.in 458c1a24d19251db547770fac50ae9c94dca42c310f8ecc937e3c587cd76ac8d
-F src/sqlite.h.in 131a18ff5e648447b8412ee6a0de757ce025e061d3ddd737a5fe72d7001b24d1
+F src/shell.c.in 6ca902bb9aa56ae7f83769b39652b975fd0b347f984ab13f4565de80e4ecb3e9
+F src/sqlite.h.in 31dcc6e5a55e308438034faf80ebca13d7331ac5a87136d5caa0baff957fe13f
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 3f0c4ed6934e7309a61c6f3c30f70a30a5b869f785bb3d9f721a36c5e4359126
-F src/sqliteInt.h 27c73e48878d31ef230ba867d1f8c3af6aed357fd93ccc605d3f1aae007ea62b
+F src/sqliteInt.h 87418f40cbdd986b4a58c649e598fd6cde89e98d3b5c770d2899b5f6c755ebb9
 F src/sqliteLimit.h fe70bd8983e5d317a264f2ea97473b359faf3ebb0827877a76813f5cf0cdc364
-F src/status.c 03d441b856391f7863da28cf1d59f61a38e24782ac4b75b0454dba42f8f6cdf7
+F src/status.c 34ccabc1bca527e800c1924fb926aa09b5828605c1431a4cf0eb5b8a549982b0
 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
 F src/tclsqlite.c 3c604c49e6cf4211960a9ddb9505280fd22cde32175f40884c641c0f5a286036
 F src/tclsqlite.h 614b3780a62522bc9f8f2b9fb22689e8009958e7aa77e572d0f3149050af348a
@@ -2175,11 +2175,11 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 9abaa0ac2b3049341f36ff683ff6eebb589698bd910624aa24f11398d557b3c2
-R 805db115b49d544ce20e2219bf55f575
-T *branch * db-status64
-T *sym-db-status64 *
-T -sym-trunk *
+P bb5b982dba774e6b8011e6c980d34131c378967fadc59a18fed1cefda596449a
+R bf295d84b4712b604b76c3297c606f19
+T *branch * dbstatus-spill
+T *sym-dbstatus-spill *
+T -sym-db-status64 *
 U drh
-Z aa94c20ffd25bd9873ab760178273927
+Z 8d1169484e2c5669b92530153307ed69
 # Remove this line to create a well-formed Fossil manifest.
index a52e59e0a42cd7a20686a0046b69e537c4396085..1ead1ba1fd1ec2c755814f6d6a59fa2c796e6ffd 100644 (file)
@@ -1,2 +1,2 @@
-branch db-status64
-tag db-status64
+branch dbstatus-spill
+tag dbstatus-spill
index 812067e2623ff5fa88cd42076dcb411716c262ea..25fcf57a27e68adc379dbdb9ec36ae890b78a78d 100644 (file)
@@ -1 +1 @@
-bb5b982dba774e6b8011e6c980d34131c378967fadc59a18fed1cefda596449a
+4e63ee20f80e486ecc4aa4523afa43f994c267e638f8f084f0d6df369aa74a1d
index 08bc810f0a52086cbed70d0eac36e705369db8f7..816cfe73c4baf24b6ff994add26c840a021df6cc 100644 (file)
@@ -3412,8 +3412,8 @@ static int display_stats(
   ShellState *pArg,           /* Pointer to ShellState */
   int bReset                  /* True to reset the stats */
 ){
-  int iCur;
-  int iHiwtr;
+  int iCur, iHiwtr;
+  sqlite3_int64 iCur64, iHiwtr64;
   FILE *out;
   if( pArg==0 || pArg->out==0 ) return 0;
   out = pArg->out;
@@ -3502,6 +3502,8 @@ static int display_stats(
     sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
     sqlite3_fprintf(out,
            "Page cache misses:                   %d\n", iCur);
+    iHiwtr64 = iCur64 = -1;
+    sqlite3_db_status64(db, SQLITE_DBSTATUS_SPILL, &iCur64, &iHiwtr64, 0);
     iHiwtr = iCur = -1;
     sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
     sqlite3_fprintf(out,
@@ -3510,6 +3512,9 @@ static int display_stats(
     sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_SPILL, &iCur, &iHiwtr, 1);
     sqlite3_fprintf(out,
            "Page cache spills:                   %d\n", iCur);
+    sqlite3_fprintf(out,
+           "Temporary data spilled to disk:      %lld\n", iCur64);
+    sqlite3_db_status64(db, SQLITE_DBSTATUS_SPILL, &iCur64, &iHiwtr64, 1);
     iHiwtr = iCur = -1;
     sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
     sqlite3_fprintf(out,
index 33b0496778ff94c12b3932ce332905064c26774c..273a4893d1dc1a9fdd189c8ae7c3f380c6df6419 100644 (file)
@@ -9044,6 +9044,14 @@ int sqlite3_db_status64(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);
 ** <dd>This parameter returns zero for the current value if and only if
 ** all foreign key constraints (deferred or immediate) have been
 ** resolved.)^  ^The highwater mark is always 0.
+**
+** [[SQLITE_DBSTATUS_SPILL] ^(<dt>SQLITE_DBSTATUS_SPILL</dt>
+** <dd>^(This parameter returns the number of bytes written to temporary
+** files on disk that could have been kept in memory had sufficient memory
+** been available.  This value includes writes to intermediate tables that
+** are part of complex queries, external sorts that spill to disk, and
+** writes to TEMP tables.)^
+** ^The highwater mark is always 0.
 ** </dd>
 ** </dl>
 */
@@ -9060,7 +9068,8 @@ int sqlite3_db_status64(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);
 #define SQLITE_DBSTATUS_DEFERRED_FKS        10
 #define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
 #define SQLITE_DBSTATUS_CACHE_SPILL         12
-#define SQLITE_DBSTATUS_MAX                 12   /* Largest defined DBSTATUS */
+#define SQLITE_DBSTATUS_SPILL               13
+#define SQLITE_DBSTATUS_MAX                 13   /* Largest defined DBSTATUS */
 
 
 /*
index f012650088d9e765c8bf2d77b0a51668a1a4337a..6ea0d7657c7304db12300d8f62df2cf437e47f28 100644 (file)
@@ -1784,6 +1784,7 @@ struct sqlite3 {
   i64 nDeferredImmCons;         /* Net deferred immediate constraints */
   int *pnBytesFreed;            /* If not NULL, increment this in DbFree() */
   DbClientData *pDbData;        /* sqlite3_set_clientdata() content */
+  u64 nSpill;                   /* TEMP content spilled to disk */
 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
   /* The following variables are all protected by the STATIC_MAIN
   ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
index 074a91f71338e104aa984f0b76ca9f49e9691239..6f79fe36fc4de71588986234cc631d20e14c1e60 100644 (file)
@@ -382,6 +382,26 @@ int sqlite3_db_status64(
       break;
     }
 
+    /* Set *pCurrent to the number of bytes that the db database connection
+    ** has spilled to the filesystem in temporary files that could have been
+    ** stored in memory, had sufficient memory been available.
+    ** The *pHighwater is always set to zero.
+    */
+    case SQLITE_DBSTATUS_SPILL: {
+      u64 nRet = 0;
+      if( db->aDb[1].pBt ){
+        Pager *pPager = sqlite3BtreePager(db->aDb[1].pBt);
+        sqlite3PagerCacheStat(pPager, SQLITE_DBSTATUS_CACHE_WRITE,
+                              resetFlag, &nRet);
+        nRet *= sqlite3BtreeGetPageSize(db->aDb[1].pBt);
+      }
+      nRet += db->nSpill;
+      if( resetFlag ) db->nSpill = 0;
+      *pHighwtr = 0;
+      *pCurrent = nRet;
+      break;
+    }
+
     /* Set *pCurrent to non-zero if there are unresolved deferred foreign
     ** key constraints.  Set *pCurrent to zero if all foreign key constraints
     ** have been satisfied.  The *pHighwtr is always set to zero.