/ Check-in [dc217b7c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the --trace option to the sqlite3_checker utility program.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dc217b7cfe680044d8742e317701abd0269162da8f5cb097361ae7f47fd9ba2d
User & Date: drh 2017-11-07 16:54:20
Context
2017-11-07
18:20
Fix a problem causing an INDEXED BY specifying an unusable partial index to be mishandled. check-in: 292a0408 user: dan tags: trunk
16:54
Add the --trace option to the sqlite3_checker utility program. check-in: dc217b7c user: drh tags: trunk
16:23
Enhance the checkindex.c virtual table so that it will output the index_name and after_key parameters. Also add a new diagnostic output column named scanner_sql which shows the SQL statement used to implement the current index scan. check-in: 32e2520c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/repair/sqlite3_checker.tcl.

    38     38         append line \n
    39     39       }
    40     40     }
    41     41   }
    42     42   
    43     43   # Do an incremental integrity check of a single index
    44     44   #
    45         -proc check_index {idxname batchsize} {
           45  +proc check_index {idxname batchsize bTrace} {
    46     46     set i 0
    47     47     set more 1
    48     48     set nerr 0
    49     49     set pct 00.0
    50     50     set max [db one {SELECT nEntry FROM sqlite_btreeinfo('main')
    51     51                       WHERE name=$idxname}]
    52     52     puts -nonewline "$idxname: $i of $max rows ($pct%)\r"
    53     53     flush stdout
    54         -  while {$more} {
    55         -    set more 0
    56         -    db eval {SELECT errmsg, current_key AS key
           54  +  if {$bTrace} {
           55  +    set sql {SELECT errmsg, current_key AS key,
           56  +                    CASE WHEN rowid=1 THEN scanner_sql END AS traceOut
           57  +               FROM incremental_index_check($idxname)
           58  +              WHERE after_key=$key
           59  +              LIMIT $batchsize}
           60  +  } else {
           61  +    set sql {SELECT errmsg, current_key AS key, NULL AS traceOut
    57     62                  FROM incremental_index_check($idxname)
    58     63                 WHERE after_key=$key
    59         -              LIMIT $batchsize} {
           64  +              LIMIT $batchsize}
           65  +  }
           66  +  while {$more} {
           67  +    set more 0
           68  +    db eval $sql {
    60     69         set more 1
    61     70         if {$errmsg!=""} {
    62     71           incr nerr
    63     72           puts "$idxname: key($key): $errmsg"
           73  +      } elseif {$traceOut!=""} {
           74  +        puts "$idxname: $traceOut"
    64     75         }
    65     76         incr i
           77  +      
    66     78       }
    67     79       set x [format {%.1f} [expr {($i*100.0)/$max}]]
    68     80       if {$x!=$pct} {
    69     81         puts -nonewline "$idxname: $i of $max rows ($pct%)\r"
    70     82         flush stdout
    71     83         set pct $x
    72     84       }
................................................................................
    93    105   
    94    106      --summary         Print summary information about the database
    95    107   
    96    108      --table NAME      Run a check of all indexes for table NAME
    97    109   
    98    110      --tclsh           Run the built-in TCL interpreter (for debugging)
    99    111   
          112  +   --trace           (Debugging only:) Output trace information on the scan
          113  +
   100    114      --version         Show the version number of SQLite
   101    115   }
   102    116     exit 1
   103    117   }
   104    118   
   105    119   set file_to_analyze {}
   106    120   append argv {}
   107    121   set bFreelistCheck 0
   108    122   set bSummary 0
   109    123   set zIndex {}
   110    124   set zTable {}
   111    125   set batchsize 1000
   112    126   set bAll 1
          127  +set bTrace 0
   113    128   set argc [llength $argv]
   114    129   for {set i 0} {$i<$argc} {incr i} {
   115    130     set arg [lindex $argv $i]
   116    131     if {[regexp {^-+tclsh$} $arg]} {
   117    132       tclsh
   118    133       exit 0
   119    134     }
................................................................................
   128    143       set bAll 0
   129    144       continue
   130    145     }
   131    146     if {[regexp {^-+summary$} $arg]} {
   132    147       set bSummary 1
   133    148       set bAll 0
   134    149       continue
          150  +  }
          151  +  if {[regexp {^-+trace$} $arg]} {
          152  +    set bTrace 1
          153  +    continue
   135    154     }
   136    155     if {[regexp {^-+batchsize$} $arg]} {
   137    156       incr i
   138    157       if {$i>=$argc} {
   139    158         puts stderr "missing argument on $arg"
   140    159         exit 1
   141    160       }
................................................................................
   220    239         }
   221    240       }
   222    241       puts [format {%7.1f %s index %s of table %s} \
   223    242               [expr {$sz/$scale}] $unit $name $tbl_name]
   224    243     }
   225    244   }
   226    245   if {$zIndex!=""} {
   227         -  check_index $zIndex $batchsize
          246  +  check_index $zIndex $batchsize $bTrace
   228    247   }
   229    248   if {$zTable!=""} {
   230    249     foreach idx [db eval {SELECT name FROM sqlite_master
   231    250                            WHERE type='index' AND rootpage>0
   232    251                              AND tbl_name=$zTable}] {
   233         -    check_index $idx $batchsize
          252  +    check_index $idx $batchsize $bTrace
   234    253     }
   235    254   }
   236    255   if {$bAll} {
   237    256     set allidx [db eval {SELECT name FROM sqlite_btreeinfo('main')
   238    257                           WHERE type='index' AND rootpage>0
   239    258                           ORDER BY nEntry}]
   240    259     foreach idx $allidx {
   241         -    check_index $idx $batchsize
          260  +    check_index $idx $batchsize $bTrace
   242    261     }
   243    262   }