From: drh Date: Wed, 1 Nov 2017 13:09:02 +0000 (+0000) Subject: Minor cleanup in checkindex.c. Add progress displays when checking a X-Git-Tag: version-3.22.0~215^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02c21b7e34a35755b3e90bf5fb352af46e7df187;p=thirdparty%2Fsqlite.git Minor cleanup in checkindex.c. Add progress displays when checking a single index in the top-level TCL script for sqlite3_checker. FossilOrigin-Name: 3ca31cc3ffe1cce4a9961d29801eebd47f0093d1b53d0ea63386338a1d434fd3 --- diff --git a/ext/repair/checkindex.c b/ext/repair/checkindex.c index 16fb3b327e..362e199168 100644 --- a/ext/repair/checkindex.c +++ b/ext/repair/checkindex.c @@ -42,6 +42,7 @@ struct CidxTable { struct CidxCursor { sqlite3_vtab_cursor base; /* Base class. Must be first */ + sqlite3_int64 iRowid; sqlite3_stmt *pStmt; }; @@ -93,6 +94,10 @@ static int cidxConnect( int rc = SQLITE_OK; CidxTable *pRet; +#define IIC_ERRMSG 0 +#define IIC_CURRENT_KEY 1 +#define IIC_INDEX_NAME 2 +#define IIC_AFTER_KEY 3 rc = sqlite3_declare_vtab(db, "CREATE TABLE xyz(" " errmsg TEXT, current_key TEXT," @@ -130,10 +135,10 @@ static int cidxBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pInfo){ if( p->usable==0 ) continue; if( p->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; - if( p->iColumn==2 ){ + if( p->iColumn==IIC_INDEX_NAME ){ iIdxName = i; } - if( p->iColumn==3 ){ + if( p->iColumn==IIC_AFTER_KEY ){ iAfterKey = i; } } @@ -193,6 +198,7 @@ static int cidxNext(sqlite3_vtab_cursor *pCursor){ cidxCursorError(pCsr, "Cursor error: %s", sqlite3_errmsg(db)); } }else{ + pCsr->iRowid++; rc = SQLITE_OK; } return rc; @@ -737,6 +743,7 @@ static int cidxFilter( assert( rc==SQLITE_OK ); rc = cidxNext(pCursor); } + pCsr->iRowid = 1; return rc; } @@ -749,8 +756,8 @@ static int cidxColumn( int iCol ){ CidxCursor *pCsr = (CidxCursor*)pCursor; - assert( iCol==0 || iCol==1 ); - if( iCol==0 ){ + assert( iCol>=IIC_ERRMSG && iCol<=IIC_AFTER_KEY ); + if( iCol==IIC_ERRMSG ){ const char *zVal = 0; if( sqlite3_column_type(pCsr->pStmt, 0)==SQLITE_INTEGER ){ if( sqlite3_column_int(pCsr->pStmt, 0)==0 ){ @@ -760,7 +767,7 @@ static int cidxColumn( zVal = "row missing"; } sqlite3_result_text(ctx, zVal, -1, SQLITE_STATIC); - }else{ + }else if( iCol==IIC_CURRENT_KEY ){ sqlite3_result_value(ctx, sqlite3_column_value(pCsr->pStmt, 1)); } return SQLITE_OK; diff --git a/ext/repair/sqlite3_checker.tcl b/ext/repair/sqlite3_checker.tcl index 25a5d252e6..a29d0332a6 100644 --- a/ext/repair/sqlite3_checker.tcl +++ b/ext/repair/sqlite3_checker.tcl @@ -48,7 +48,11 @@ proc check_index {idxname batchsize} { set i 0 set more 1 set nerr 0 - puts -nonewline "$idxname: " + set pct 00.0 + set max [db one {SELECT nEntry FROM sqlite_btreeinfo('main') + WHERE name=$idxname}] + puts -nonewline "$idxname: $i of $max rows ($pct%)\r" + flush stdout while {$more} { set more 0 db eval {SELECT errmsg, current_key AS key @@ -57,20 +61,19 @@ proc check_index {idxname batchsize} { LIMIT $batchsize} { set more 1 if {$errmsg!=""} { - if {$nerr>0} { - puts -nonewline "$idxname: " - } incr nerr - puts "key($key): $errmsg" + puts "$idxname: key($key): $errmsg" } incr i } + set x [format {%.1f} [expr {($i*100.0)/$max}]] + if {$x!=$pct} { + puts -nonewline "$idxname: $i of $max rows ($pct%)\r" + flush stdout + set pct $x + } } - if {$nerr==0} { - puts "$i entries, ok" - } else { - puts "$idxname: $nerr errors out of $i entries" - } + puts "$idxname: $nerr errors out of $i entries" } # Print a usage message on standard error, then quit. @@ -107,7 +110,7 @@ set bFreelistCheck 0 set bSummary 0 set zIndex {} set zTable {} -set batchsize 100 +set batchsize 1000 set bAll 1 set argc [llength $argv] for {set i 0} {$i<$argc} {incr i} { diff --git a/manifest b/manifest index 222cd77113..bf8e3e2133 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\ssqlite3_checker\sfinds\sa\sproblem,\sshow\sthe\srow\skey\sas\spart\sof\sthe\serror\nmessage,\snot\sthe\srow\sindex\snumber. -D 2017-11-01T01:05:42.000 +C Minor\scleanup\sin\scheckindex.c.\s\sAdd\sprogress\sdisplays\swhen\schecking\sa\nsingle\sindex\sin\sthe\stop-level\sTCL\sscript\sfor\ssqlite3_checker. +D 2017-11-01T13:09:02.677 F Makefile.in b142eb20482922153ebc77b261cdfd0a560ed05a81e9f6d9a2b0e8192922a1d2 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a55372a22454e742ba7c8f6edf05b83213ec01125166ad7dcee0567e2f7fc81b @@ -328,9 +328,9 @@ F ext/rbu/sqlite3rbu.h b42bcd4d8357268c6c39ab2a60b29c091e89328fa8cc49c8fac5ab8d0 F ext/rbu/test_rbu.c 7073979b9cc80912bb03599ac8d85ab5d3bf03cfacd3463f2dcdd7822997533a F ext/repair/README.md 92f5e8aae749a4dae14f02eea8e1bb42d4db2b6ce5e83dbcdd6b1446997e0c15 F ext/repair/checkfreelist.c 0abb84b4545016d57ba1a2aa8884c72c73ed838968909858c03bc1f38fb6b054 -F ext/repair/checkindex.c f33d90ed6a556ad03511f7932891c2fd47ad93ddc998a4ab8bb56f4adf6fb206 +F ext/repair/checkindex.c a013a0a165b2e6f2b278a31566da04913856c88d6ed5457d477f89e78d5979d9 F ext/repair/sqlite3_checker.c.in 16d62615dfce1ff3eeac83d1a77fe376a7b660afa9db07e1fdd8b964dcc41510 -F ext/repair/sqlite3_checker.tcl 1eb23dcc262fb8b6e869775dc06bdfba3931f5c2ea5bfd41188c0b84fa6e35a7 +F ext/repair/sqlite3_checker.tcl 32d474decb6bb65e60bd3660dba0b75e7e0719d6f6fb6dba97e5b9249eec94a1 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 F ext/rtree/rtree.c cc91b6905bf55512c6ebc7dfdd37ac81c86f1753db8cfa6d62f0ee864464044f F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e @@ -1671,7 +1671,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 54530020260ea9e4cfd021f5ffccb74d78c469b717dce377d3df6eaf84b63719 -R 84bd4abb8e94f0df6079dbff9fcf5a09 +P 6ffe917d10e298cd80cd3a8c8c5116a2819145a176fb8cfccd5dbd88b10f39df +R 9a8d975a41c4365cfebb7312db115daa U drh -Z d157fe339c4385e31979ffec5d5c510b +Z d02ff4965492ed83b018c8e578de7329 diff --git a/manifest.uuid b/manifest.uuid index 69455d17b6..86f32e4c10 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6ffe917d10e298cd80cd3a8c8c5116a2819145a176fb8cfccd5dbd88b10f39df \ No newline at end of file +3ca31cc3ffe1cce4a9961d29801eebd47f0093d1b53d0ea63386338a1d434fd3 \ No newline at end of file