1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999,2008 Oracle. All rights reserved. 4# 5# $Id: sdb018.tcl,v 12.9 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST sdb018 8# TEST Tests join of in-memory named databases. 9# TEST 10# TEST We'll test 2-way, 3-way, and 4-way joins and figure that if those work, 11# TEST everything else does as well. We'll create test databases called 12# TEST sub1.db, sub2.db, sub3.db, and sub4.db. The number on the database 13# TEST describes the duplication -- duplicates are of the form 0, N, 2N, 3N, 14# TEST ... where N is the number of the database. Primary.db is the primary 15# TEST database, and sub0.db is the database that has no matching duplicates. 16# TEST All of these are within a single database. 17# 18# We should test this on all btrees, all hash, and a combination thereof 19proc sdb018 {method {nentries 100} args } { 20 source ./include.tcl 21 global rand_init 22 23 set args [convert_args $method $args] 24 set omethod [convert_method $method] 25 26 if { [is_record_based $method] == 1 || [is_rbtree $method] } { 27 puts "\tSubdb018 skipping for method $method." 28 return 29 } 30 31 set eindex [lsearch -exact $args "-env"] 32 # 33 # If we are given an env, then skip this test. It needs its own. 34 if { $eindex != -1 } { 35 incr eindex 36 set env [lindex $args $eindex] 37 puts "Subdb016 skipping for env $env" 38 return 39 } 40 41 # In-memory dbs never go to disk, so we can't do checksumming. 42 # If the test module sent in the -chksum arg, get rid of it. 43 set chkindex [lsearch -exact $args "-chksum"] 44 if { $chkindex != -1 } { 45 set args [lreplace $args $chkindex $chkindex] 46 } 47 48 set testfile "" 49 berkdb srand $rand_init 50 51 foreach opt {" -dup" " -dupsort"} { 52 env_cleanup $testdir 53 54 set cache [expr 1024 * 1024 * 10] 55 set env [berkdb_env -create -home $testdir \ 56 -cachesize "0 $cache 1" ] 57 append args $opt 58 set oargs $args 59 append oargs " -env $env" 60 61 62 puts "Subdb018: $method ( $args ) Intra-subdb join" 63 set txn "" 64 # 65 # Get a cursor in each subdb and move past the end of each 66 # subdb. Make sure we don't end up in another subdb. 67 # 68 puts "\tSubdb018.a: Intra-subdb join" 69 70 set psize 8192 71 set duplist {0 50 25 16 12} 72 set numdb [llength $duplist] 73 build_all_subdb $testfile [list $method] $psize \ 74 $duplist $nentries $oargs 75 76 # Build the primary 77 puts "Subdb018: Building the primary database $method" 78 set oflags "-create -mode 0644 [conv $omethod \ 79 [berkdb random_int 1 2]]" 80 set db [eval {berkdb_open} $oflags $oargs {$testfile} primary.db] 81 error_check_good dbopen [is_valid_db $db] TRUE 82 for { set i 0 } { $i < 1000 } { incr i } { 83 set key [format "%04d" $i] 84 set ret [eval {$db put} $txn {$key stub}] 85 error_check_good "primary put" $ret 0 86 } 87 error_check_good "primary close" [$db close] 0 88 set did [open $dict] 89 gets $did str 90 do_join_subdb $testfile primary.db "1 0" $str $oargs 91 gets $did str 92 do_join_subdb $testfile primary.db "2 0" $str $oargs 93 gets $did str 94 do_join_subdb $testfile primary.db "3 0" $str $oargs 95 gets $did str 96 do_join_subdb $testfile primary.db "4 0" $str $oargs 97 gets $did str 98 do_join_subdb $testfile primary.db "1" $str $oargs 99 gets $did str 100 do_join_subdb $testfile primary.db "2" $str $oargs 101 gets $did str 102 do_join_subdb $testfile primary.db "3" $str $oargs 103 gets $did str 104 do_join_subdb $testfile primary.db "4" $str $oargs 105 gets $did str 106 do_join_subdb $testfile primary.db "1 2" $str $oargs 107 gets $did str 108 do_join_subdb $testfile primary.db "1 2 3" $str $oargs 109 gets $did str 110 do_join_subdb $testfile primary.db "1 2 3 4" $str $oargs 111 gets $did str 112 do_join_subdb $testfile primary.db "2 1" $str $oargs 113 gets $did str 114 do_join_subdb $testfile primary.db "3 2 1" $str $oargs 115 gets $did str 116 do_join_subdb $testfile primary.db "4 3 2 1" $str $oargs 117 gets $did str 118 do_join_subdb $testfile primary.db "1 3" $str $oargs 119 gets $did str 120 do_join_subdb $testfile primary.db "3 1" $str $oargs 121 gets $did str 122 do_join_subdb $testfile primary.db "1 4" $str $oargs 123 gets $did str 124 do_join_subdb $testfile primary.db "4 1" $str $oargs 125 gets $did str 126 do_join_subdb $testfile primary.db "2 3" $str $oargs 127 gets $did str 128 do_join_subdb $testfile primary.db "3 2" $str $oargs 129 gets $did str 130 do_join_subdb $testfile primary.db "2 4" $str $oargs 131 gets $did str 132 do_join_subdb $testfile primary.db "4 2" $str $oargs 133 gets $did str 134 do_join_subdb $testfile primary.db "3 4" $str $oargs 135 gets $did str 136 do_join_subdb $testfile primary.db "4 3" $str $oargs 137 gets $did str 138 do_join_subdb $testfile primary.db "2 3 4" $str $oargs 139 gets $did str 140 do_join_subdb $testfile primary.db "3 4 1" $str $oargs 141 gets $did str 142 do_join_subdb $testfile primary.db "4 2 1" $str $oargs 143 gets $did str 144 do_join_subdb $testfile primary.db "0 2 1" $str $oargs 145 gets $did str 146 do_join_subdb $testfile primary.db "3 2 0" $str $oargs 147 gets $did str 148 do_join_subdb $testfile primary.db "4 3 2 1" $str $oargs 149 gets $did str 150 do_join_subdb $testfile primary.db "4 3 0 1" $str $oargs 151 152 close $did 153 error_check_good env_close [$env close] 0 154 } 155} 156 157