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
This commit is contained in:
+12
-5
@@ -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;
|
||||
|
||||
@@ -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} {
|
||||
|
||||
Reference in New Issue
Block a user