/ Check-in [8c846311]
Login

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

Overview
Comment:Changes to sqlite3_analyzer to try to avoid integer overflow problems when linking against older versions of TCL.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8c846311a0cd510bbf9361213bb60764e9b797aa
User & Date: drh 2011-09-27 13:40:26
Context
2011-09-28
00:50
Enhance the stat VFS to report out the total size of all pages used by a table, even if the ZIPVFS compression backend is in play. Update the sqlite3_analyzer logic to use these new outputs. check-in: 19b8eaaf user: drh tags: trunk
2011-09-27
13:40
Changes to sqlite3_analyzer to try to avoid integer overflow problems when linking against older versions of TCL. check-in: 8c846311 user: drh tags: trunk
2011-09-26
19:32
Changes to the analyzer script to make it work with zipvfs databases. check-in: d82cffab user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/spaceanal.tcl.

    31     31   
    32     32   # Open the database
    33     33   #
    34     34   sqlite3 db $file_to_analyze
    35     35   register_dbstat_vtab db
    36     36   
    37     37   db eval {SELECT count(*) FROM sqlite_master}
    38         -set pageSize [db one {PRAGMA page_size}]
           38  +set pageSize [expr {wide([db one {PRAGMA page_size}])}]
    39     39   
    40     40   # In-memory database for collecting statistics. This script loops through
    41     41   # the tables and indices in the database being analyzed, adding a row for each
    42     42   # to an in-memory database (for which the schema is shown below). It then
    43     43   # queries the in-memory db to produce the space-analysis report.
    44     44   #
    45     45   sqlite3 mem :memory:
................................................................................
   141    141         $gap_cnt
   142    142       );
   143    143     }
   144    144   }
   145    145   
   146    146   proc integerify {real} {
   147    147     if {[string is double -strict $real]} {
   148         -    return [expr {int($real)}]
          148  +    return [expr {wide($real)}]
   149    149     } else {
   150    150       return 0
   151    151     }
   152    152   }
   153    153   mem function int integerify
   154    154   
   155    155   # Quote a string for use in an SQL query. Examples:
................................................................................
   326    326     # The number of entries on each pointer map page. The layout of the
   327    327     # database file is one pointer-map page, followed by $ptrsPerPage other
   328    328     # pages, followed by a pointer-map page etc. The first pointer-map page
   329    329     # is the second page of the file overall.
   330    330     set ptrsPerPage [expr double($pageSize/5)]
   331    331   
   332    332     # Return the number of pointer map pages in the database.
   333         -  return [expr int(ceil( ($filePages-1.0)/($ptrsPerPage+1.0) ))]
          333  +  return [expr wide(ceil( ($filePages-1.0)/($ptrsPerPage+1.0) ))]
   334    334   }
   335    335   
   336    336   
   337    337   # Calculate the summary statistics for the database and store the results
   338    338   # in TCL variables. They are output below. Variables are as follows:
   339    339   #
   340    340   # pageSize:      Size of each page in bytes.
................................................................................
   361    361   ### on disk, causes this tool to choke on zipvfs databases. So set it based
   362    362   ### on the return of [PRAGMA page_count] instead.
   363    363   if 0 {
   364    364     set file_bytes  [file size $file_to_analyze]
   365    365     set file_pgcnt  [expr {$file_bytes/$pageSize}]
   366    366   }
   367    367   set file_pgcnt  [db one {PRAGMA page_count}]
   368         -set file_bytes  [expr $file_pgcnt * $pageSize]
          368  +set file_bytes  [expr {$file_pgcnt * $pageSize}]
   369    369   
   370    370   set av_pgcnt    [autovacuum_overhead $file_pgcnt $pageSize]
   371    371   set av_percent  [percent $av_pgcnt $file_pgcnt]
   372    372   
   373    373   set sql {SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM space_used}
   374         -set inuse_pgcnt   [expr int([mem eval $sql])]
          374  +set inuse_pgcnt   [expr wide([mem eval $sql])]
   375    375   set inuse_percent [percent $inuse_pgcnt $file_pgcnt]
   376    376   
   377         -set free_pgcnt    [expr $file_pgcnt-$inuse_pgcnt-$av_pgcnt]
          377  +set free_pgcnt    [expr {$file_pgcnt-$inuse_pgcnt-$av_pgcnt}]
   378    378   set free_percent  [percent $free_pgcnt $file_pgcnt]
   379    379   set free_pgcnt2   [db one {PRAGMA freelist_count}]
   380    380   set free_percent2 [percent $free_pgcnt2 $file_pgcnt]
   381    381   
   382    382   set file_pgcnt2 [expr {$inuse_pgcnt+$free_pgcnt2+$av_pgcnt}]
   383    383   
   384    384   set ntable [db eval {SELECT count(*)+1 FROM sqlite_master WHERE type='table'}]