1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 2001-2002
4
# Sleepycat Software. All rights reserved.
8
# Secondary index test driver and maintenance routines.
10
# Breaking from the usual convention, we put the driver function
11
# for the secondary index tests here, in its own file. The reason
12
# for this is that it's something which compartmentalizes nicely,
13
# has little in common with other driver functions, and
14
# is likely to be run on its own from time to time.
16
# The secondary index tests themselves live in si0*.tcl.
18
# Standard number of secondary indices to create if a single-element
19
# list of methods is passed into the secondary index tests.
23
# Run the secondary index tests.
24
proc sindex { {verbose 0} args } {
25
global verbose_check_secondaries
26
set verbose_check_secondaries $verbose
28
# Run basic tests with a single secondary index and a small number
29
# of keys, then again with a larger number of keys. (Note that
30
# we can't go above 5000, since we use two items from our
31
# 10K-word list for each key/data pair.)
32
foreach n { 200 5000 } {
33
foreach pm { btree hash recno frecno queue queueext } {
34
foreach sm { dbtree dhash ddbtree ddhash btree hash } {
35
sindex001 [list $pm $sm $sm] $n
36
sindex002 [list $pm $sm $sm] $n
37
# Skip tests 3 & 4 for large lists;
38
# they're not that interesting.
40
sindex003 [list $pm $sm $sm] $n
41
sindex004 [list $pm $sm $sm] $n
44
sindex006 [list $pm $sm $sm] $n
49
# Run secondary index join test. (There's no point in running
50
# this with both lengths, the primary is unhappy for now with fixed-
51
# length records (XXX), and we need unsorted dups in the secondaries.)
52
foreach pm { btree hash recno } {
53
foreach sm { btree hash } {
54
sindex005 [list $pm $sm $sm] 1000
56
sindex005 [list $pm btree hash] 1000
57
sindex005 [list $pm hash btree] 1000
61
# Run test with 50 secondaries.
62
foreach pm { btree hash } {
63
set methlist [list $pm]
64
for { set i 0 } { $i < 50 } { incr i } {
65
# XXX this should incorporate hash after #3726
67
lappend methlist "dbtree"
69
lappend methlist "ddbtree"
72
sindex001 $methlist 500
73
sindex002 $methlist 500
74
sindex003 $methlist 500
75
sindex004 $methlist 500
79
# The callback function we use for each given secondary in most tests
80
# is a simple function of its place in the list of secondaries (0-based)
81
# and the access method (since recnos may need different callbacks).
84
# Note that callbacks 0-3 return unique secondary keys if the input data
85
# are unique; callbacks 4 and higher may not, so don't use them with
86
# the normal wordlist and secondaries that don't support dups.
87
# The callbacks that incorporate a key don't work properly with recno
88
# access methods, at least not in the current test framework (the
89
# error_check_good lines test for e.g. 1foo, when the database has
90
# e.g. 0x010x000x000x00foo).
91
proc callback_n { n } {
93
0 { return _s_reversedata }
95
2 { return _s_concatkeydata }
96
3 { return _s_concatdatakey }
97
4 { return _s_reverseconcat }
98
5 { return _s_truncdata }
99
6 { return _s_alwayscocacola }
104
proc _s_reversedata { a b } { return [reverse $b] }
105
proc _s_truncdata { a b } { return [string range $b 1 end] }
106
proc _s_concatkeydata { a b } { return $a$b }
107
proc _s_concatdatakey { a b } { return $b$a }
108
proc _s_reverseconcat { a b } { return [reverse $a$b] }
109
proc _s_alwayscocacola { a b } { return "Coca-Cola" }
110
proc _s_noop { a b } { return $b }
112
# Should the check_secondary routines print lots of output?
113
set verbose_check_secondaries 0
115
# Given a primary database handle, a list of secondary handles, a
116
# number of entries, and arrays of keys and data, verify that all
117
# databases have what they ought to.
118
proc check_secondaries { pdb sdbs nentries keyarr dataarr {pref "Check"} } {
121
global verbose_check_secondaries
123
# Make sure each key/data pair is in the primary.
124
if { $verbose_check_secondaries } {
125
puts "\t\t$pref.1: Each key/data pair is in the primary"
127
for { set i 0 } { $i < $nentries } { incr i } {
128
error_check_good pdb_get($i) [$pdb get $keys($i)] \
129
[list [list $keys($i) $data($i)]]
132
for { set j 0 } { $j < [llength $sdbs] } { incr j } {
133
# Make sure each key/data pair is in this secondary.
134
if { $verbose_check_secondaries } {
136
Each skey/key/data tuple is in secondary #$j"
138
for { set i 0 } { $i < $nentries } { incr i } {
139
set sdb [lindex $sdbs $j]
140
set skey [[callback_n $j] $keys($i) $data($i)]
141
error_check_good sdb($j)_pget($i) \
142
[$sdb pget -get_both $skey $keys($i)] \
143
[list [list $skey $keys($i) $data($i)]]
146
# Make sure this secondary contains only $nentries
148
if { $verbose_check_secondaries } {
149
puts "\t\t$pref.3: Secondary #$j has $nentries items"
151
set dbc [$sdb cursor]
152
error_check_good dbc($i) \
153
[is_valid_cursor $dbc $sdb] TRUE
154
for { set k 0 } { [llength [$dbc get -next]] > 0 } \
156
error_check_good numitems($i) $k $nentries
157
error_check_good dbc($i)_close [$dbc close] 0
160
if { $verbose_check_secondaries } {
161
puts "\t\t$pref.4: Primary has $nentries items"
163
set dbc [$pdb cursor]
164
error_check_good pdbc [is_valid_cursor $dbc $pdb] TRUE
165
for { set k 0 } { [llength [$dbc get -next]] > 0 } { incr k } { }
166
error_check_good numitems $k $nentries
167
error_check_good pdbc_close [$dbc close] 0
170
# Given a primary database handle and a list of secondary handles, walk
171
# through the primary and make sure all the secondaries are correct,
172
# then walk through the secondaries and make sure the primary is correct.
174
# This is slightly less rigorous than the normal check_secondaries--we
175
# use it whenever we don't have up-to-date "keys" and "data" arrays.
176
proc cursor_check_secondaries { pdb sdbs nentries { pref "Check" } } {
177
global verbose_check_secondaries
179
# Make sure each key/data pair in the primary is in each secondary.
180
set pdbc [$pdb cursor]
181
error_check_good ccs_pdbc [is_valid_cursor $pdbc $pdb] TRUE
183
if { $verbose_check_secondaries } {
185
Key/data in primary => key/data in secondaries"
188
for { set dbt [$pdbc get -first] } { [llength $dbt] > 0 } \
189
{ set dbt [$pdbc get -next] } {
191
set pkey [lindex [lindex $dbt 0] 0]
192
set pdata [lindex [lindex $dbt 0] 1]
193
for { set j 0 } { $j < [llength $sdbs] } { incr j } {
194
set sdb [lindex $sdbs $j]
195
set sdbt [$sdb pget -get_both \
196
[[callback_n $j] $pkey $pdata] $pkey]
197
error_check_good pkey($pkey,$j) \
198
[lindex [lindex $sdbt 0] 1] $pkey
199
error_check_good pdata($pdata,$j) \
200
[lindex [lindex $sdbt 0] 2] $pdata
203
error_check_good ccs_pdbc_close [$pdbc close] 0
204
error_check_good primary_has_nentries $i $nentries
206
for { set j 0 } { $j < [llength $sdbs] } { incr j } {
207
if { $verbose_check_secondaries } {
209
Key/data in secondary #$j => key/data in primary"
211
set sdb [lindex $sdbs $j]
212
set sdbc [$sdb cursor]
213
error_check_good ccs_sdbc($j) [is_valid_cursor $sdbc $sdb] TRUE
215
for { set dbt [$sdbc pget -first] } { [llength $dbt] > 0 } \
216
{ set dbt [$sdbc pget -next] } {
218
set pkey [lindex [lindex $dbt 0] 1]
219
set pdata [lindex [lindex $dbt 0] 2]
220
error_check_good pdb_get($pkey/$pdata,$j) \
221
[$pdb get -get_both $pkey $pdata] \
222
[list [list $pkey $pdata]]
224
error_check_good secondary($j)_has_nentries $i $nentries
226
# To exercise pget -last/pget -prev, we do it backwards too.
228
for { set dbt [$sdbc pget -last] } { [llength $dbt] > 0 } \
229
{ set dbt [$sdbc pget -prev] } {
231
set pkey [lindex [lindex $dbt 0] 1]
232
set pdata [lindex [lindex $dbt 0] 2]
233
error_check_good pdb_get_bkwds($pkey/$pdata,$j) \
234
[$pdb get -get_both $pkey $pdata] \
235
[list [list $pkey $pdata]]
237
error_check_good secondary($j)_has_nentries_bkwds $i $nentries
239
error_check_good ccs_sdbc_close($j) [$sdbc close] 0
243
# The secondary index tests take a list of the access methods that
244
# each array ought to use. Convert at one blow into a list of converted
245
# argses and omethods for each method in the list.
246
proc convert_argses { methods largs } {
249
lappend ret [convert_args $m $largs]
253
proc convert_methods { methods } {
256
lappend ret [convert_method $m]