xref: /sqlite-3.40.0/test/index5.test (revision 7b96f2fa)
1# 2012 August 6
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
6#    May you do good and not evil.
7#    May you find forgiveness for yourself and forgive others.
8#    May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16set ::testprefix index5
17
18do_test 1.1 {
19  if {[permutation]=="memsubsys1"} {
20    execsql { PRAGMA auto_vacuum = 0; }
21  }
22  execsql {
23    PRAGMA page_size = 1024;
24    CREATE TABLE t1(x);
25    BEGIN;
26  }
27  for {set i 0} {$i < 100000} {incr i} {
28    execsql { INSERT INTO t1 VALUES(randstr(100,100)) }
29  }
30  execsql COMMIT
31  execsql {
32    CREATE INDEX i1 ON t1(x);
33    DROP INDEX I1;
34    PRAGMA main.page_size;
35  }
36} {1024}
37
38db close
39testvfs tvfs
40tvfs filter xWrite
41tvfs script write_cb
42proc write_cb {xCall file handle iOfst args} {
43  if {[file tail $file]=="test.db"} {
44    lappend ::write_list [expr $iOfst/1024 + 1]
45  }
46}
47
48do_test 1.2 {
49  sqlite3 db test.db -vfs tvfs
50  set ::write_list [list]
51  execsql { CREATE INDEX i1 ON t1(x) }
52} {}
53
54do_test 1.3 {
55  set nForward 0
56  set nBackward 0
57  set nNoncont 0
58  set iPrev [lindex $::write_list 0]
59  for {set i 1} {$i < [llength $::write_list]} {incr i} {
60    set iNext [lindex $::write_list $i]
61    if {$iNext==($iPrev+1)} {
62      incr nForward
63    } elseif {$iNext==($iPrev-1)} {
64      incr nBackward
65    } else {
66      incr nNoncont
67    }
68    set iPrev $iNext
69  }
70  if {0} {
71    puts -nonewline \
72        " (forward=$nForward, back=$nBackward, noncontiguous=$nNoncont)"
73  }
74
75  expr {$nForward > 2*($nBackward + $nNoncont)}
76} {1}
77db close
78tvfs delete
79
80finish_test
81