**
******************************************************************************
**
-** Partial reimplement of the sqlite3_analyzer utility program as
-** loadable SQL function.
+** This extension implements an SQL function:
+**
+** diskused(X)
+**
+** Where X is the schema name (typically 'main'). The output is text
+** that describes how much filesystem space the various tables and indexes
+** of the database consume.
+**
+** This function is a replacement for the (now deprecated)
+** "sqlite3_analyzer" utility program. This function is built
+** into the CLI and is used to implement the ".diskused" command there.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
/*
** State information for the analysis
*/
-typedef struct Analysis Analysis;
-struct Analysis {
+typedef struct DiskUsed DiskUsed;
+struct DiskUsed {
sqlite3 *db; /* Database connection */
sqlite3_context *context; /* SQL function context */
sqlite3_str *pOut; /* Write output here */
};
/*
-** Free all resources that the Analysis object references and
-** reset the Analysis object.
+** Free all resources that the DiskUsed object references and
+** reset the DiskUsed object.
**
-** Call this routine multiple times on the same Analysis object
+** Call this routine multiple times on the same DiskUsed object
** is a harmless no-op, as long as the memory for the object itself
** has not been freed.
*/
-static void analysisReset(Analysis *p){
+static void diskusedReset(DiskUsed *p){
if( p->zSU ){
char *zSql = sqlite3_mprintf("DROP TABLE temp.%s;", p->zSU);
if( zSql ){
** Report an error using formatted text. If zFormat==NULL then report
** an OOM error.
*/
-static void analysisError(Analysis *p, const char *zFormat, ...){
+static void diskusedError(DiskUsed *p, const char *zFormat, ...){
char *zErr;
if( zFormat ){
va_list ap;
sqlite3_result_error(p->context, zErr, -1);
sqlite3_free(zErr);
}
- analysisReset(p);
+ diskusedReset(p);
}
/*
** Prepare and return an SQL statement.
*/
-static sqlite3_stmt *analysisVPrep(Analysis *p, const char *zFmt, va_list ap){
+static sqlite3_stmt *diskusedVPrep(DiskUsed *p, const char *zFmt, va_list ap){
char *zSql;
int rc;
sqlite3_stmt *pStmt = 0;
zSql = sqlite3_vmprintf(zFmt, ap);
- if( zSql==0 ){ analysisError(p,0); return 0; }
+ if( zSql==0 ){ diskusedError(p,0); return 0; }
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
if( rc ){
- analysisError(p, "SQL parse error: %s\nOriginal SQL: %s",
+ diskusedError(p, "SQL parse error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), zSql);
sqlite3_finalize(pStmt);
- analysisReset(p);
+ diskusedReset(p);
pStmt = 0;
}
sqlite3_free(zSql);
return pStmt;
}
-static sqlite3_stmt *analysisPrepare(Analysis *p, const char *zFormat, ...){
+static sqlite3_stmt *diskusedPrepare(DiskUsed *p, const char *zFormat, ...){
va_list ap;
sqlite3_stmt *pStmt = 0;
va_start(ap, zFormat);
- pStmt = analysisVPrep(p,zFormat,ap);
+ pStmt = diskusedVPrep(p,zFormat,ap);
va_end(ap);
return pStmt;
}
**
** The prepared statement is closed in either case.
*/
-static int analysisStmtFinish(Analysis *p, int rc, sqlite3_stmt *pStmt){
+static int diskusedStmtFinish(DiskUsed *p, int rc, sqlite3_stmt *pStmt){
if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
}
if( rc!=SQLITE_OK || (rc = sqlite3_reset(pStmt))!=SQLITE_OK ){
- analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s",
+ diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), sqlite3_sql(pStmt));
- analysisReset(p);
+ diskusedReset(p);
}
sqlite3_finalize(pStmt);
return rc;
/*
** Run SQL. Return the number of errors.
*/
-static int analysisSql(Analysis *p, const char *zFormat, ...){
+static int diskusedSql(DiskUsed *p, const char *zFormat, ...){
va_list ap;
int rc;
sqlite3_stmt *pStmt = 0;
va_start(ap, zFormat);
- pStmt = analysisVPrep(p,zFormat,ap);
+ pStmt = diskusedVPrep(p,zFormat,ap);
va_end(ap);
if( pStmt==0 ) return 1;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){}
if( rc==SQLITE_DONE ){
rc = SQLITE_OK;
}else{
- analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s",
+ diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), sqlite3_sql(pStmt));
- analysisReset(p);
+ diskusedReset(p);
}
sqlite3_finalize(pStmt);
return rc;
** Run an SQL query that returns an integer. Write that integer
** into *piRes. Return the number of errors.
*/
-static int analysisSqlInt(
- Analysis *p,
+static int diskusedSqlInt(
+ DiskUsed *p,
sqlite3_int64 *piRes,
const char *zFormat, ...
){
int rc;
sqlite3_stmt *pStmt = 0;
va_start(ap, zFormat);
- pStmt = analysisVPrep(p,zFormat,ap);
+ pStmt = diskusedVPrep(p,zFormat,ap);
va_end(ap);
if( pStmt==0 ) return 1;
rc = sqlite3_step(pStmt);
}else{
if( p->db ){
/* p->db is NULL if there was some prior error */
- analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s",
+ diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s",
sqlite3_errmsg(p->db), sqlite3_sql(pStmt));
}
- analysisReset(p);
+ diskusedReset(p);
}
sqlite3_finalize(pStmt);
return rc;
** comment. Otherwise begin with a new-line. Always finish with a
** newline.
*/
-static void analysisTitle(Analysis *p, const char *zFormat, ...){
+static void diskusedTitle(DiskUsed *p, const char *zFormat, ...){
char *zFirst;
char *zTitle;
size_t nTitle;
zTitle = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( zTitle==0 ){
- analysisError(p, 0);
+ diskusedError(p, 0);
return;
}
zFirst = sqlite3_str_length(p->pOut)==0 ? "/" : "\n*";
** 50 columns with "." characters, and followed by whatever text is
** described by zFormat.
*/
-static void analysisLine(
- Analysis *p, /* Analysis context */
+static void diskusedLine(
+ DiskUsed *p, /* DiskUsed context */
const char *zDesc, /* Description */
const char *zFormat, /* Argument to the description */
...
zTxt = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( zTxt==0 ){
- analysisError(p, 0);
+ diskusedError(p, 0);
return;
}
nDesc = strlen(zDesc);
** two or three significant digits, with the decimal point being the fourth
** character.
*/
-static void analysisPercent(Analysis *p, double r){
+static void diskusedPercent(DiskUsed *p, double r){
char zNum[100];
char *zDP;
int nLeadingDigit;
** a boolean expression that can go in the WHERE clause to select
** the relevant rows of the s.zSU table.
*/
-static int analysisSubreport(
- Analysis *p, /* Analysis context */
+static int diskusedSubreport(
+ DiskUsed *p, /* DiskUsed context */
char *zTitle, /* Title for this subreport */
char *zWhere, /* WHERE clause for this subreport */
sqlite3_int64 pgsz, /* Database page size */
int rc;
if( zTitle==0 || zWhere==0 ){
- analysisError(p, 0);
+ diskusedError(p, 0);
return SQLITE_NOMEM;
}
- pStmt = analysisPrepare(p,
+ pStmt = diskusedPrepare(p,
"SELECT\n"
" sum(if(is_without_rowid OR is_index,nentry,leaf_entries)),\n" /* 0 */
" sum(payload),\n" /* 1 */
if( pStmt==0 ) return 1;
rc = sqlite3_step(pStmt);
if( rc==SQLITE_ROW ){
- analysisTitle(p, "%s", zTitle);
+ diskusedTitle(p, "%s", zTitle);
nentry = sqlite3_column_int64(pStmt, 0);
payload = sqlite3_column_int64(pStmt, 1);
rc = SQLITE_DONE;
total_pages = leaf_pages + int_pages + ovfl_pages;
- analysisLine(p, "Percentage of total database", "%.3g%%\n",
+ diskusedLine(p, "Percentage of total database", "%.3g%%\n",
(total_pages*100.0)/(double)nPage);
- analysisLine(p, "Number of entries", "%lld\n", nentry);
+ diskusedLine(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);
- analysisPercent(p, payload*100.0/(double)storage);
+ diskusedLine(p, "Bytes of storage consumed", "%lld\n", storage);
+ diskusedLine(p, "Bytes of payload", "%-11lld ", payload);
+ diskusedPercent(p, payload*100.0/(double)storage);
if( ovfl_cnt>0 ){
- analysisLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload);
- analysisPercent(p, ovfl_payload*100.0/(double)payload);
+ diskusedLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload);
+ diskusedPercent(p, 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);
- analysisPercent(p, total_meta*100.0/(double)storage);
+ diskusedLine(p, "Bytes of metadata","%-11lld ", total_meta);
+ diskusedPercent(p, total_meta*100.0/(double)storage);
if( cnt==1 ){
- analysisLine(p, "B-tree depth", "%lld\n", depth);
+ diskusedLine(p, "B-tree depth", "%lld\n", depth);
if( int_cell>1 ){
- analysisLine(p, "Average fanout", "%.1f\n",
+ diskusedLine(p, "Average fanout", "%.1f\n",
(double)(int_cell+int_pages)/(double)int_pages);
}
}
if( nentry>0 ){
- analysisLine(p, "Average payload per entry", "%.1f\n",
+ diskusedLine(p, "Average payload per entry", "%.1f\n",
(double)payload/(double)nentry);
- analysisLine(p, "Average unused bytes per entry", "%.1f\n",
+ diskusedLine(p, "Average unused bytes per entry", "%.1f\n",
(double)total_unused/(double)nentry);
- analysisLine(p, "Average metadata per entry", "%.1f\n",
+ diskusedLine(p, "Average metadata per entry", "%.1f\n",
(double)total_meta/(double)nentry);
}
- analysisLine(p, "Maximum single-entry payload", "%lld\n", mx_payload);
+ diskusedLine(p, "Maximum single-entry payload", "%lld\n", mx_payload);
if( nentry>0 ){
- analysisLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt);
- analysisPercent(p, ovfl_cnt*100.0/(double)nentry);
+ diskusedLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt);
+ diskusedPercent(p, ovfl_cnt*100.0/(double)nentry);
}
if( int_pages>0 ){
- analysisLine(p, "Index pages used", "%lld\n", int_pages);
+ diskusedLine(p, "Index pages used", "%lld\n", int_pages);
}
- analysisLine(p, "Primary pages used", "%lld\n", leaf_pages);
+ diskusedLine(p, "Primary pages used", "%lld\n", leaf_pages);
if( ovfl_cnt ){
- analysisLine(p, "Overflow pages used", "%lld\n", ovfl_pages);
+ diskusedLine(p, "Overflow pages used", "%lld\n", ovfl_pages);
}
- analysisLine(p, "Total pages used", "%lld\n", total_pages);
+ diskusedLine(p, "Total pages used", "%lld\n", total_pages);
if( int_pages>0 ){
- analysisLine(p, "Unused bytes on index pages", "%lld\n", int_unused);
+ diskusedLine(p, "Unused bytes on index pages", "%lld\n", int_unused);
}
- analysisLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused);
+ diskusedLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused);
if( ovfl_cnt ){
- analysisLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused);
+ diskusedLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused);
}
- analysisLine(p, "Unused bytes on all pages", "%-11lld ", total_unused);
- analysisPercent(p, total_unused*100.0/(double)storage);
+ diskusedLine(p, "Unused bytes on all pages", "%-11lld ", total_unused);
+ diskusedPercent(p, total_unused*100.0/(double)storage);
}
- return analysisStmtFinish(p, rc, pStmt);
+ return diskusedStmtFinish(p, rc, pStmt);
}
/*
-** SQL Function: analyze(SCHEMA)
+** SQL Function: diskused(SCHEMA)
**
** Analyze the database schema named in the argument. Return text
-** containing the analysis.
+** containing the space utilization stats.
*/
-static void analyzeFunc(
+static void diskusedFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
sqlite3_int64 nFreeList;
sqlite3_int64 nIndex;
sqlite3_int64 nWORowid;
- Analysis s;
+ DiskUsed s;
sqlite3_uint64 r[2];
(void)argc;
s.context = context;
s.pOut = sqlite3_str_new(0);
if( sqlite3_str_errcode(s.pOut) ){
- analysisError(&s, 0);
+ diskusedError(&s, 0);
return;
}
s.zSchema = (const char*)sqlite3_value_text(argv[0]);
if( s.zSchema==0 ){
s.zSchema = "main";
}else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){
- analysisReset(&s);
+ diskusedReset(&s);
sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC);
return;
}
ii = 0;
- rc = analysisSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list"
+ rc = diskusedSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list"
" WHERE name=%Q COLLATE nocase",s.zSchema);
if( rc || ii==0 ){
- analysisReset(&s);
+ diskusedReset(&s);
sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC);
return;
}
sqlite3_randomness(sizeof(r), &r);
- s.zSU = sqlite3_mprintf("analysis%016llx%016llx", r[0], r[1]);
- if( s.zSU==0 ){ analysisError(&s, 0); return; }
+ s.zSU = sqlite3_mprintf("diskused%016llx%016llx", r[0], r[1]);
+ if( s.zSU==0 ){ diskusedError(&s, 0); return; }
/* The s.zSU table contains the data used for the analysis.
** The table name contains 128-bits of randomness to avoid
** collisions with preexisting tables in temp.
*/
- rc = analysisSql(&s,
+ rc = diskusedSql(&s,
"CREATE TABLE temp.%s(\n"
" name text, -- A table or index\n"
" tblname text, -- Table that owns name\n"
/* Populate the s.zSU table
*/
- rc = analysisSql(&s,
+ rc = diskusedSql(&s,
"WITH\n"
" allidx(idxname) AS (\n"
" SELECT name FROM \"%w\".sqlite_schema WHERE type='index'\n"
if( rc ) return;
nPage = 0;
- rc = analysisSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema);
+ rc = diskusedSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema);
if( rc ) return;
if( nPage<=0 ){
/* Very brief reply for an empty database */
- analysisReset(&s);
+ diskusedReset(&s);
sqlite3_result_text(context, "empty database", -1, SQLITE_STATIC);
return;
}
/* Begin generating the report */
- analysisTitle(&s, "Database storage utilization report");
+ diskusedTitle(&s, "Database storage utilization report");
pgsz = 0;
- rc = analysisSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema);
+ rc = diskusedSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema);
if( rc ) return;
- analysisLine(&s, "Page size in bytes","%lld\n",pgsz);
- analysisLine(&s, "Pages in the database", "%lld\n", nPage);
+ diskusedLine(&s, "Page size in bytes","%lld\n",pgsz);
+ diskusedLine(&s, "Pages in the database", "%lld\n", nPage);
nPageInUse = 0;
- rc = analysisSqlInt(&s, &nPageInUse,
+ rc = diskusedSqlInt(&s, &nPageInUse,
"SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM temp.%s", s.zSU);
if( rc ) return;
- analysisLine(&s, "Pages that store data", "%-11lld ", nPageInUse);
- analysisPercent(&s, (nPageInUse*100.0)/(double)nPage);
+ diskusedLine(&s, "Pages that store data", "%-11lld ", nPageInUse);
+ diskusedPercent(&s, (nPageInUse*100.0)/(double)nPage);
nFreeList = 0;
- rc = analysisSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema);
+ rc = diskusedSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema);
if( rc ) return;
- analysisLine(&s, "Pages on the freelist", "%-11lld ", nFreeList);
- analysisPercent(&s, (nFreeList*100.0)/(double)nPage);
+ diskusedLine(&s, "Pages on the freelist", "%-11lld ", nFreeList);
+ diskusedPercent(&s, (nFreeList*100.0)/(double)nPage);
ii = 0;
- rc = analysisSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
+ rc = diskusedSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema);
if( rc ) return;
if( ii==0 || nPage<=1 ){
ii = 0;
double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0);
ii = (sqlite3_int64)ceil(rAvPage);
}
- analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii);
- analysisPercent(&s, (ii*100.0)/(double)nPage);
+ diskusedLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii);
+ diskusedPercent(&s, (ii*100.0)/(double)nPage);
ii = 0;
- rc = analysisSqlInt(&s, &ii,
+ rc = diskusedSqlInt(&s, &ii,
"SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'",
s.zSchema);
if( rc ) return;
- analysisLine(&s, "Number of tables", "%lld\n", ii);
+ diskusedLine(&s, "Number of tables", "%lld\n", ii);
nWORowid = 0;
- rc = analysisSqlInt(&s, &nWORowid,
+ rc = diskusedSqlInt(&s, &nWORowid,
"SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr",
s.zSchema);
if( rc ) return;
if( nWORowid>0 ){
- analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid);
- analysisLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid);
+ diskusedLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid);
+ diskusedLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid);
}
nIndex = 0;
- rc = analysisSqlInt(&s, &nIndex,
+ rc = diskusedSqlInt(&s, &nIndex,
"SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'",
s.zSchema);
if( rc ) return;
- analysisLine(&s, "Number of indexes", "%lld\n", nIndex);
+ diskusedLine(&s, "Number of indexes", "%lld\n", nIndex);
ii = 0;
- rc = analysisSqlInt(&s, &ii,
+ rc = diskusedSqlInt(&s, &ii,
"SELECT count(*) FROM \"%w\".sqlite_schema"
" WHERE name GLOB 'sqlite_autoindex_*' AND type='index'",
s.zSchema);
if( rc ) return;
- analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii);
- analysisLine(&s, "Number of implied indexes", "%lld\n", ii);
- analysisLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage);
+ diskusedLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii);
+ diskusedLine(&s, "Number of implied indexes", "%lld\n", ii);
+ diskusedLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage);
ii = 0;
- rc = analysisSqlInt(&s, &ii,
+ rc = diskusedSqlInt(&s, &ii,
"SELECT sum(payload) FROM temp.%s"
" WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'",
s.zSU);
if( rc ) return;
- analysisLine(&s, "Bytes of payload", "%-11lld ", ii);
- analysisPercent(&s, ii*100.0/(double)(pgsz*nPage));
+ diskusedLine(&s, "Bytes of payload", "%-11lld ", ii);
+ diskusedPercent(&s, ii*100.0/(double)(pgsz*nPage));
- analysisTitle(&s, "Page counts for all tables with their indexes");
- pStmt = analysisPrepare(&s,
+ diskusedTitle(&s, "Page counts for all tables with their indexes");
+ pStmt = diskusedPrepare(&s,
"SELECT upper(tblname),\n"
" sum(int_pages+leaf_pages+ovfl_pages)\n"
" FROM temp.%s\n"
if( pStmt==0 ) return;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
sqlite3_int64 nn = sqlite3_column_int64(pStmt,1);
- analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn);
- analysisPercent(&s, (nn*100.0)/(double)nPage);
+ diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn);
+ diskusedPercent(&s, (nn*100.0)/(double)nPage);
}
- if( analysisStmtFinish(&s, rc, pStmt) ) return;
+ if( diskusedStmtFinish(&s, rc, pStmt) ) return;
- analysisTitle(&s, "Page counts for all tables and indexes separately");
- pStmt = analysisPrepare(&s,
+ diskusedTitle(&s, "Page counts for all tables and indexes separately");
+ pStmt = diskusedPrepare(&s,
"SELECT upper(name),\n"
" sum(int_pages+leaf_pages+ovfl_pages)\n"
" FROM temp.%s\n"
if( pStmt==0 ) return;
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
sqlite3_int64 nn = sqlite3_column_int64(pStmt,1);
- analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn);
- analysisPercent(&s, (nn*100.0)/(double)nPage);
+ diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn);
+ diskusedPercent(&s, (nn*100.0)/(double)nPage);
}
- if( analysisStmtFinish(&s, rc, pStmt) ) return;
+ if( diskusedStmtFinish(&s, rc, pStmt) ) return;
- rc = analysisSubreport(&s, "All tables and indexes", "1", pgsz, nPage);
+ rc = diskusedSubreport(&s, "All tables and indexes", "1", pgsz, nPage);
if( rc ) return;
- rc = analysisSubreport(&s, "All tables", "NOT is_index", pgsz, nPage);
+ rc = diskusedSubreport(&s, "All tables", "NOT is_index", pgsz, nPage);
if( rc ) return;
if( nWORowid>0 ){
- rc = analysisSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid",
+ rc = diskusedSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid",
pgsz, nPage);
if( rc ) return;
- rc = analysisSubreport(&s, "All rowid tables",
+ rc = diskusedSubreport(&s, "All rowid tables",
"NOT is_without_rowid AND NOT is_index",
pgsz, nPage);
if( rc ) return;
}
- rc = analysisSubreport(&s, "All indexes", "is_index", pgsz, nPage);
+ rc = diskusedSubreport(&s, "All indexes", "is_index", pgsz, nPage);
if( rc ) return;
- pStmt = analysisPrepare(&s,
+ pStmt = diskusedPrepare(&s,
"SELECT upper(tblname), tblname, sum(is_index) FROM temp.%s"
" GROUP BY 1 ORDER BY 1",
s.zSU);
if( nSubIndex==0 ){
char *zTitle = sqlite3_mprintf("Table %s", zUpper);
char *zWhere = sqlite3_mprintf("name=%Q", zName);
- rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage);
+ rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
sqlite3_stmt *pS2;
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);
+ rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
zTitle = sqlite3_mprintf("Table %s w/o any indexes", zUpper);
zWhere = sqlite3_mprintf("name=%Q", zName);
- rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage);
+ rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
if( nSubIndex>1 ){
zTitle = sqlite3_mprintf("All indexes of table %s", zUpper);
zWhere = sqlite3_mprintf("tblname=%Q AND is_index", zName);
- rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage);
+ rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
}
- pS2 = analysisPrepare(&s,
+ pS2 = diskusedPrepare(&s,
"SELECT name, upper(name) FROM temp.%s"
" WHERE is_index AND tblname=%Q",
s.zSU, zName);
const char *zN = (const char*)sqlite3_column_text(pS2, 0);
zTitle = sqlite3_mprintf("Index %s", zU);
zWhere = sqlite3_mprintf("name=%Q", zN);
- rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage);
+ rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage);
sqlite3_free(zTitle);
sqlite3_free(zWhere);
if( rc ) break;
}
- rc = analysisStmtFinish(&s, rc, pS2);
+ rc = diskusedStmtFinish(&s, rc, pS2);
if( rc ) break;
}
}
- if( analysisStmtFinish(&s, rc, pStmt) ) return;
+ if( diskusedStmtFinish(&s, rc, pStmt) ) return;
/* Append SQL statements that will recreate the raw data used for
** the analysis.
*/
- analysisTitle(&s, "Raw data used to generate this report");
+ diskusedTitle(&s, "Raw data used to generate this report");
sqlite3_str_appendf(s.pOut,
"The following SQL will create a table named \"space_used\" which\n"
"contains most of the information used to generate the report above.\n"
");\n"
"INSERT INTO space_used VALUES\n"
);
- pStmt = analysisPrepare(&s,
+ pStmt = diskusedPrepare(&s,
"SELECT quote(name), quote(tblname),\n" /* 0..1 */
" is_index, is_without_rowid, nentry, leaf_entries,\n" /* 2..5 */
" depth, payload, ovfl_payload, ovfl_cnt, mx_payload,\n" /* 6..10 */
sqlite3_column_int64(pStmt, 17));
}
if( rc!=SQLITE_DONE ){
- analysisError(&s, "SQL run-time error: %s\nSQL: %s",
+ diskusedError(&s, "SQL run-time error: %s\nSQL: %s",
sqlite3_errmsg(s.db), sqlite3_sql(pStmt));
sqlite3_finalize(pStmt);
return;
sqlite3_free);
s.pOut = 0;
}
- analysisReset(&s);
+ diskusedReset(&s);
}
#ifdef _WIN32
__declspec(dllexport)
#endif
-int sqlite3_analyze_init(
+int sqlite3_diskused_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
- rc = sqlite3_create_function(db, "analyze", 1,
+ rc = sqlite3_create_function(db, "diskused", 1,
SQLITE_UTF8|SQLITE_INNOCUOUS,
- 0, analyzeFunc, 0, 0);
+ 0, diskusedFunc, 0, 0);
return rc;
}