mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Implement a B+tree option (all data stored on leaves). (CVS 1365)
FossilOrigin-Name: b8f70d17f06531269caa0a127efb2d25ad0f3e1c
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# $Id: btree5.test,v 1.2 2004/05/11 00:58:56 drh Exp $
|
||||
# $Id: btree5.test,v 1.3 2004/05/12 19:18:17 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -123,7 +123,6 @@ proc check_table {N} {
|
||||
set fdata1 [btree_fetch_data $c1 $n]
|
||||
set fdata2 [btree_fetch_data $c1 -1]
|
||||
if {$fdata1 ne "" && $fdata1 ne $data} {
|
||||
puts "fdata1=[list $fdata1] data=[list $data]"
|
||||
return "DataFetch returned the wrong value with amt=$n"
|
||||
}
|
||||
if {$fdata1 ne $fdata2} {
|
||||
@ -154,20 +153,20 @@ set btree_trace 0
|
||||
#
|
||||
set cnt 0
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
do_test test5-2.$i.1 {
|
||||
do_test btree5-2.$i.1 {
|
||||
random_inserts 200
|
||||
incr cnt 200
|
||||
check_table $cnt
|
||||
} {}
|
||||
do_test test5-2.$i.2 {
|
||||
do_test btree5-2.$i.2 {
|
||||
btree_integrity_check $b1 1
|
||||
} {}
|
||||
do_test test5-2.$i.3 {
|
||||
do_test btree5-2.$i.3 {
|
||||
random_deletes 190
|
||||
incr cnt -190
|
||||
check_table $cnt
|
||||
} {}
|
||||
do_test test5-2.$i.4 {
|
||||
do_test btree5-2.$i.4 {
|
||||
btree_integrity_check $b1 1
|
||||
} {}
|
||||
}
|
||||
|
127
test/btree6.test
Normal file
127
test/btree6.test
Normal file
@ -0,0 +1,127 @@
|
||||
# 2004 May 10
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend - specifically
|
||||
# the B+tree tables. B+trees store all data on the leaves rather
|
||||
# that storing data with keys on interior nodes.
|
||||
#
|
||||
# $Id: btree6.test,v 1.1 2004/05/12 19:18:17 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
# Insert many entries into the table that cursor $cur points to.
|
||||
# The table should be an INTKEY table.
|
||||
#
|
||||
# Stagger the inserts. After the inserts complete, go back and do
|
||||
# deletes. Stagger the deletes too. Repeat this several times.
|
||||
#
|
||||
|
||||
# Do N inserts into table $tab using random keys between 0 and 1000000
|
||||
#
|
||||
proc random_inserts {cur N} {
|
||||
global inscnt
|
||||
while {$N>0} {
|
||||
set k [expr {int(rand()*1000000)}]
|
||||
if {[btree_move_to $cur $k]==0} {
|
||||
continue; # entry already exists
|
||||
}
|
||||
incr inscnt
|
||||
btree_insert $cur $k data-for-$k
|
||||
incr N -1
|
||||
}
|
||||
}
|
||||
set inscnt 0
|
||||
|
||||
# Do N delete from the table that $cur points to.
|
||||
#
|
||||
proc random_deletes {cur N} {
|
||||
while {$N>0} {
|
||||
set k [expr {int(rand()*1000000)}]
|
||||
btree_move_to $cur $k
|
||||
btree_delete $cur
|
||||
incr N -1
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure the table that $cur points to has exactly N entries.
|
||||
# Make sure the data for each entry agrees with its key.
|
||||
#
|
||||
proc check_table {cur N} {
|
||||
btree_first $cur
|
||||
set cnt 0
|
||||
while {![btree_eof $cur]} {
|
||||
if {[set data [btree_data $cur]] ne "data-for-[btree_key $cur]"} {
|
||||
return "wrong data for entry $cnt"
|
||||
}
|
||||
set n [string length $data]
|
||||
set fdata1 [btree_fetch_data $cur $n]
|
||||
set fdata2 [btree_fetch_data $cur -1]
|
||||
if {$fdata1 ne "" && $fdata1 ne $data} {
|
||||
return "DataFetch returned the wrong value with amt=$n"
|
||||
}
|
||||
if {$fdata1 ne $fdata2} {
|
||||
return "DataFetch returned the wrong value when amt=-1"
|
||||
}
|
||||
if {$n>10} {
|
||||
set fdata3 [btree_fetch_data $cur 10]
|
||||
if {$fdata3 ne [string range $data 0 9]} {
|
||||
return "DataFetch returned the wrong value when amt=10"
|
||||
}
|
||||
}
|
||||
incr cnt
|
||||
btree_next $cur
|
||||
}
|
||||
if {$cnt!=$N} {
|
||||
return "wrong number of entries. Got $cnt. Looking for $N"
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
# Initialize the database
|
||||
#
|
||||
file delete -force test1.bt
|
||||
file delete -force test1.bt-journal
|
||||
set b1 [btree_open test1.bt 2000 0]
|
||||
btree_begin_transaction $b1
|
||||
set tab [btree_create_table $b1 5]
|
||||
set cur [btree_cursor $b1 $tab 1]
|
||||
set btree_trace 0
|
||||
expr srand(1)
|
||||
|
||||
# Do the tests.
|
||||
#
|
||||
set cnt 0
|
||||
for {set i 1} {$i<=100} {incr i} {
|
||||
do_test btree6-1.$i.1 {
|
||||
random_inserts $cur 200
|
||||
incr cnt 200
|
||||
check_table $cur $cnt
|
||||
} {}
|
||||
do_test btree6-1.$i.2 {
|
||||
btree_integrity_check $b1 1 $tab
|
||||
} {}
|
||||
do_test btree6-1.$i.3 {
|
||||
random_deletes $cur 190
|
||||
incr cnt -190
|
||||
check_table $cur $cnt
|
||||
} {}
|
||||
do_test btree6-1.$i.4 {
|
||||
btree_integrity_check $b1 1 $tab
|
||||
} {}
|
||||
}
|
||||
|
||||
btree_close_cursor $cur
|
||||
btree_commit $b1
|
||||
|
||||
finish_test
|
Reference in New Issue
Block a user