From: drh <> Date: Tue, 14 Apr 2026 20:07:29 +0000 (+0000) Subject: Various minor tweaks and refinements to the analyze() function. X-Git-Url: http://git.ipfire.org/index.cgi?a=commitdiff_plain;h=d962afef2d37666e8fcf642900acae4a62e37770;p=thirdparty%2Fsqlite.git Various minor tweaks and refinements to the analyze() function. FossilOrigin-Name: 48d94e72eaec443011dd1f7a7264e5222c05bb515c84deaf20ed4195b74d45ff --- diff --git a/ext/misc/analyze.c b/ext/misc/analyze.c index 900a6203fa..745ae30f64 100644 --- a/ext/misc/analyze.c +++ b/ext/misc/analyze.c @@ -117,8 +117,8 @@ static int analysisStmtFinish(Analysis *p, int rc, sqlite3_stmt *pStmt){ if( rc==SQLITE_DONE ){ rc = SQLITE_OK; } - if( rc!=SQLITE_OK ){ - analysisError(p, "SQL parse error: %s\nOriginal SQL: %s", + if( rc!=SQLITE_OK || (rc = sqlite3_reset(pStmt))!=SQLITE_OK ){ + analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); analysisReset(p); } @@ -351,20 +351,20 @@ static int analysisSubreport( rc = SQLITE_DONE; total_pages = leaf_pages + int_pages + ovfl_pages; - analysisLine(p, "Percentage of total database", ""); - analysisPercent(p, 0, (total_pages*100.0)/(double)nPage); + analysisLine(p, "Percentage of total database", "%.3g%%\n", + (total_pages*100.0)/(double)nPage); analysisLine(p, "Number of entries", "%lld\n", nentry); storage = total_pages*pgsz; analysisLine(p, "Bytes of storage consumed", "%lld\n", storage); - analysisLine(p, "Bytes of payload", "%-11lld", payload); + analysisLine(p, "Bytes of payload", "%-11lld ", payload); analysisPercent(p, 0, payload*100.0/(double)storage); if( ovfl_cnt>0 ){ - analysisLine(p, "Bytes of payload in overflow", "%-11lld", ovfl_payload); + analysisLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload); analysisPercent(p, 0, ovfl_payload*100.0/(double)payload); } total_unused = leaf_unused + int_unused + ovfl_unused; total_meta = storage - payload - total_unused; - analysisLine(p, "Bytes of metadata", "%-11lld", total_meta); + analysisLine(p, "Bytes of metadata","%-11lld ", total_meta); analysisPercent(p, 0, total_meta*100.0/(double)storage); if( cnt==1 ){ analysisLine(p, "B-tree depth", "%lld\n", depth); @@ -379,7 +379,7 @@ static int analysisSubreport( } analysisLine(p, "Maximum single-entry payload", "%lld\n", mx_payload); if( nentry>0 ){ - analysisLine(p, "Entries that use overflow", "%-11lld", ovfl_cnt); + analysisLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt); analysisPercent(p, 0, ovfl_cnt*100.0/(double)nentry); } if( int_pages>0 ){ @@ -397,14 +397,10 @@ static int analysisSubreport( if( ovfl_cnt ){ analysisLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused); } - analysisLine(p, "Unused bytes on all pages", "%-11lld", total_unused); + analysisLine(p, "Unused bytes on all pages", "%-11lld ", total_unused); analysisPercent(p, 0, total_unused*100.0/(double)storage); } - if( analysisStmtFinish(p, rc, pStmt) ){ - return rc; - }else{ - return SQLITE_OK; - } + return analysisStmtFinish(p, rc, pStmt); } /* @@ -439,7 +435,7 @@ static void analyzeFunc( s.zSchema = (const char*)sqlite3_value_text(argv[0]); if( s.zSchema==0 ) s.zSchema = "main"; sqlite3_randomness(sizeof(r), &r); - s.zSU = sqlite3_mprintf("analysis%016x%016x", r[0], r[1]); + s.zSU = sqlite3_mprintf("analysis%016llx%016llx", r[0], r[1]); if( s.zSU==0 ){ analysisError(&s, 0); return; } /* The s.zSU table contains the data used for the analysis. @@ -573,7 +569,10 @@ static void analyzeFunc( "SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr", s.zSchema); if( rc ) return; - analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid); + if( nWORowid>0 ){ + analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid); + analysisLine(&s, "Number of rowid tables", "%lld\n", i64 - nWORowid); + } nIndex = 0; rc = analysisSqlInt(&s, &nIndex, "SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'", @@ -595,7 +594,9 @@ static void analyzeFunc( " WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'", s.zSU); if( rc ) return; - analysisLine(&s, "Bytes of payload", "%lld\n\n", i64); + analysisLine(&s, "Bytes of payload", "%-11lld ", i64); + analysisPercent(&s, 0, i64*100.0/(double)(pgsz*nPage)); + sqlite3_str_append(s.pOut, "\n", 1); analysisTitle(&s, "Page counts for all tables with their indexes"); sqlite3_str_append(s.pOut, "\n", 1); @@ -609,7 +610,7 @@ static void analyzeFunc( if( pStmt==0 ) return; while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ sqlite3_int64 n = sqlite3_column_int64(pStmt,1); - analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld", n); + analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", n); analysisPercent(&s, 0, (n*100.0)/(double)nPage); } if( analysisStmtFinish(&s, rc, pStmt) ) return; @@ -627,7 +628,7 @@ static void analyzeFunc( if( pStmt==0 ) return; while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ sqlite3_int64 n = sqlite3_column_int64(pStmt,1); - analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld", n); + analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", n); analysisPercent(&s, 0, (n*100.0)/(double)nPage); } if( analysisStmtFinish(&s, rc, pStmt) ) return; @@ -652,6 +653,7 @@ static void analyzeFunc( "SELECT upper(tblname), tblname, sum(is_index) FROM temp.%s" " GROUP BY 1 ORDER BY 1", s.zSU); + if( pStmt==0 ) return; while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ const char *zUpper = (const char*)sqlite3_column_text(pStmt, 0); const char *zName = (const char*)sqlite3_column_text(pStmt, 1); @@ -665,7 +667,6 @@ static void analyzeFunc( if( rc ) break; }else{ sqlite3_stmt *pS2; - int rc2; char *zTitle = sqlite3_mprintf("Table %s and all its indexes", zUpper); char *zWhere = sqlite3_mprintf("tblname=%Q", zName); rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); @@ -704,9 +705,7 @@ static void analyzeFunc( sqlite3_free(zWhere); if( rc ) break; } - if( rc==SQLITE_DONE ) rc = SQLITE_OK; - rc2 = sqlite3_finalize(pS2); - if( rc==SQLITE_OK && rc2!=SQLITE_OK ) rc = rc2; + rc = analysisStmtFinish(&s, rc, pS2); if( rc ) break; } } diff --git a/manifest b/manifest index 9f702950b4..7da1e1c09d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Implementation\sof\sthe\sanalyze()\sSQL\sfunction\sis\snow\smostly\scomplete. -D 2026-04-14T19:36:33.575 +C Various\sminor\stweaks\sand\srefinements\sto\sthe\sanalyze()\sfunction. +D 2026-04-14T20:07:29.887 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -358,7 +358,7 @@ F ext/jni/src/tests/000-001-ignored.test e17e874c6ab3c437f1293d88093cf06286083b6 F ext/jni/src/tests/900-001-fts.test bf0ce17a8d082773450e91f2388f5bbb2dfa316d0b676c313c637a91198090f0 F ext/misc/README.md 6243cdc4d7eb791c41ef0716f3980b8b5f6aa8c61ff76a3958cbf0031c6ebfa7 F ext/misc/amatch.c 8d237cc014b3736922c26a76a451050d244aa4980c47c531f368f817b1e77b49 -F ext/misc/analyze.c 200aa4a378e54b710cd774d70a3a65d916972bcf695671eff306309cd37fa8da +F ext/misc/analyze.c 6091e1f4f10d626c17813f9aa80eab5c011900808494647140680fcf6eba8664 F ext/misc/anycollseq.c 5ffdfde9829eeac52219136ad6aa7cd9a4edb3b15f4f2532de52f4a22525eddb F ext/misc/appendvfs.c 9642c7a194a2a25dca7ad3e36af24a0a46d7702168c4ad7e59c9f9b0e16a3824 F ext/misc/base64.c 1445761667c16356e827fc6418294c869468be934429aaa8315035e76dd58acf @@ -2199,8 +2199,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 289fefc3edfeecb06dc11897d3ff24763fd9e25db44e369eeec29b9ed3de5ccc -R 635177803a58986bff71c8ff6e3e87a1 +P 1ca0386ab2df0d88ed52941469d459114f483ecf6b7e4691bcc32e909636cb7d +R bcb843bc1c4d4ebc599ef058d075bc70 U drh -Z cf63c806645e7784cf6fda78da65684e +Z 2ddf36c598ea4d8a6fbcc42c59861a2b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fdf1e55aa4..abeefc9841 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ca0386ab2df0d88ed52941469d459114f483ecf6b7e4691bcc32e909636cb7d +48d94e72eaec443011dd1f7a7264e5222c05bb515c84deaf20ed4195b74d45ff