| OLD | NEW |
| 1 # 2014 Dec 20 | 1 # 2014 Dec 20 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 DROP TABLE IF EXISTS x8; | 38 DROP TABLE IF EXISTS x8; |
| 39 CREATE VIRTUAL TABLE x8 USING fts5(i); | 39 CREATE VIRTUAL TABLE x8 USING fts5(i); |
| 40 INSERT INTO x8(x8, rank) VALUES('pgsz', 32); | 40 INSERT INTO x8(x8, rank) VALUES('pgsz', 32); |
| 41 | 41 |
| 42 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<$::nRowPerSeg) | 42 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<$::nRowPerSeg) |
| 43 INSERT INTO x8 SELECT repeat('x y ', i % 16) FROM ii; | 43 INSERT INTO x8 SELECT repeat('x y ', i % 16) FROM ii; |
| 44 | 44 |
| 45 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<$::nRowPerSeg) | 45 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<$::nRowPerSeg) |
| 46 INSERT INTO x8 SELECT repeat('x y ', i % 16) FROM ii; | 46 INSERT INTO x8 SELECT repeat('x y ', i % 16) FROM ii; |
| 47 | 47 |
| 48 INSERT INTO x8(x8, rank) VALUES('automerge', 2); | 48 INSERT INTO x8(x8, rank) VALUES('usermerge', 2); |
| 49 } | 49 } |
| 50 | 50 |
| 51 for {set tn 1} {[lindex [fts5_level_segs x8] 0]>0} {incr tn} { | 51 for {set tn 1} {[lindex [fts5_level_segs x8] 0]>0} {incr tn} { |
| 52 do_execsql_test $testname.$tn { | 52 do_execsql_test $testname.$tn { |
| 53 INSERT INTO x8(x8, rank) VALUES('merge', 1); | 53 INSERT INTO x8(x8, rank) VALUES('merge', 1); |
| 54 INSERT INTO x8(x8) VALUES('integrity-check'); | 54 INSERT INTO x8(x8) VALUES('integrity-check'); |
| 55 } | 55 } |
| 56 if {$tn>5} break | 56 if {$tn>5} break |
| 57 } | 57 } |
| 58 | 58 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 CREATE VIRTUAL TABLE x8 USING fts5(i); | 77 CREATE VIRTUAL TABLE x8 USING fts5(i); |
| 78 INSERT INTO x8(x8, rank) VALUES('pgsz', 32); | 78 INSERT INTO x8(x8, rank) VALUES('pgsz', 32); |
| 79 } | 79 } |
| 80 | 80 |
| 81 set ::nRow $nRow | 81 set ::nRow $nRow |
| 82 do_test $testname.1 { | 82 do_test $testname.1 { |
| 83 for {set i 0} {$i < $::nRow} {incr i} { | 83 for {set i 0} {$i < $::nRow} {incr i} { |
| 84 execsql { INSERT INTO x8 VALUES( rnddoc(($i%16) + 5) ) } | 84 execsql { INSERT INTO x8 VALUES( rnddoc(($i%16) + 5) ) } |
| 85 while {[not_merged x8]} { | 85 while {[not_merged x8]} { |
| 86 execsql { | 86 execsql { |
| 87 INSERT INTO x8(x8, rank) VALUES('automerge', 2); | 87 INSERT INTO x8(x8, rank) VALUES('usermerge', 2); |
| 88 INSERT INTO x8(x8, rank) VALUES('merge', 1); | 88 INSERT INTO x8(x8, rank) VALUES('merge', 1); |
| 89 INSERT INTO x8(x8, rank) VALUES('automerge', 16); | 89 INSERT INTO x8(x8, rank) VALUES('usermerge', 16); |
| 90 INSERT INTO x8(x8) VALUES('integrity-check'); | 90 INSERT INTO x8(x8) VALUES('integrity-check'); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } {} | 94 } {} |
| 95 } | 95 } |
| 96 proc not_merged {tbl} { | 96 proc not_merged {tbl} { |
| 97 set segs [fts5_level_segs $tbl] | 97 set segs [fts5_level_segs $tbl] |
| 98 foreach s $segs { if {$s>1} { return 1 } } | 98 foreach s $segs { if {$s>1} { return 1 } } |
| 99 return 0 | 99 return 0 |
| 100 } | 100 } |
| 101 | 101 |
| 102 do_merge2_test 2.1 5 | 102 do_merge2_test 2.1 5 |
| 103 do_merge2_test 2.2 10 | 103 do_merge2_test 2.2 10 |
| 104 do_merge2_test 2.3 20 | 104 do_merge2_test 2.3 20 |
| 105 | 105 |
| 106 #------------------------------------------------------------------------- | 106 #------------------------------------------------------------------------- |
| 107 # Test that an auto-merge will complete any merge that has already been | 107 # Test that a merge will complete any merge that has already been |
| 108 # started, even if the number of input segments is less than the current | 108 # started, even if the number of input segments is less than the current |
| 109 # value of the 'automerge' configuration parameter. | 109 # value of the 'usermerge' configuration parameter. |
| 110 # | 110 # |
| 111 db func rnddoc fts5_rnddoc | 111 db func rnddoc fts5_rnddoc |
| 112 | 112 |
| 113 do_execsql_test 3.1 { | 113 do_execsql_test 3.1 { |
| 114 DROP TABLE IF EXISTS x8; | 114 DROP TABLE IF EXISTS x8; |
| 115 CREATE VIRTUAL TABLE x8 USING fts5(i); | 115 CREATE VIRTUAL TABLE x8 USING fts5(i); |
| 116 INSERT INTO x8(x8, rank) VALUES('pgsz', 32); | 116 INSERT INTO x8(x8, rank) VALUES('pgsz', 32); |
| 117 INSERT INTO x8 VALUES(rnddoc(100)); | 117 INSERT INTO x8 VALUES(rnddoc(100)); |
| 118 INSERT INTO x8 VALUES(rnddoc(100)); | 118 INSERT INTO x8 VALUES(rnddoc(100)); |
| 119 } | 119 } |
| 120 do_test 3.2 { | 120 do_test 3.2 { |
| 121 execsql { | 121 execsql { |
| 122 INSERT INTO x8(x8, rank) VALUES('automerge', 4); | 122 INSERT INTO x8(x8, rank) VALUES('usermerge', 4); |
| 123 INSERT INTO x8(x8, rank) VALUES('merge', 1); | 123 INSERT INTO x8(x8, rank) VALUES('merge', 1); |
| 124 } | 124 } |
| 125 fts5_level_segs x8 | 125 fts5_level_segs x8 |
| 126 } {2} | 126 } {2} |
| 127 | 127 |
| 128 do_test 3.3 { | 128 do_test 3.3 { |
| 129 execsql { | 129 execsql { |
| 130 INSERT INTO x8(x8, rank) VALUES('automerge', 2); | 130 INSERT INTO x8(x8, rank) VALUES('usermerge', 2); |
| 131 INSERT INTO x8(x8, rank) VALUES('merge', 1); | 131 INSERT INTO x8(x8, rank) VALUES('merge', 1); |
| 132 } | 132 } |
| 133 fts5_level_segs x8 | 133 fts5_level_segs x8 |
| 134 } {2 1} | 134 } {2 1} |
| 135 | 135 |
| 136 do_test 3.4 { | 136 do_test 3.4 { |
| 137 execsql { INSERT INTO x8(x8, rank) VALUES('automerge', 4) } | 137 execsql { INSERT INTO x8(x8, rank) VALUES('usermerge', 4) } |
| 138 while {[not_merged x8]} { | 138 while {[not_merged x8]} { |
| 139 execsql { INSERT INTO x8(x8, rank) VALUES('merge', 1) } | 139 execsql { INSERT INTO x8(x8, rank) VALUES('merge', 1) } |
| 140 } | 140 } |
| 141 fts5_level_segs x8 | 141 fts5_level_segs x8 |
| 142 } {0 1} | 142 } {0 1} |
| 143 | 143 |
| 144 #------------------------------------------------------------------------- | 144 #------------------------------------------------------------------------- |
| 145 # | 145 # |
| 146 proc mydoc {} { | 146 proc mydoc {} { |
| 147 set x [lindex {a b c d e f g h i j} [expr int(rand()*10)]] | 147 set x [lindex {a b c d e f g h i j} [expr int(rand()*10)]] |
| (...skipping 21 matching lines...) Expand all Loading... |
| 169 | 169 |
| 170 do_execsql_test 4.$tn.2 { | 170 do_execsql_test 4.$tn.2 { |
| 171 INSERT INTO x8(x8, rank) VALUES('merge', 1); | 171 INSERT INTO x8(x8, rank) VALUES('merge', 1); |
| 172 } | 172 } |
| 173 | 173 |
| 174 do_execsql_test 4.$tn.3 { | 174 do_execsql_test 4.$tn.3 { |
| 175 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) | 175 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) |
| 176 INSERT INTO x8 SELECT mydoc() FROM ii; | 176 INSERT INTO x8 SELECT mydoc() FROM ii; |
| 177 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) | 177 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) |
| 178 INSERT INTO x8 SELECT mydoc() FROM ii; | 178 INSERT INTO x8 SELECT mydoc() FROM ii; |
| 179 INSERT INTO x8(x8, rank) VALUES('automerge', 2); | 179 INSERT INTO x8(x8, rank) VALUES('usermerge', 2); |
| 180 } | 180 } |
| 181 | 181 |
| 182 set expect [mycount] | 182 set expect [mycount] |
| 183 for {set i 0} {$i < 20} {incr i} { | 183 for {set i 0} {$i < 20} {incr i} { |
| 184 do_test 4.$tn.4.$i { | 184 do_test 4.$tn.4.$i { |
| 185 execsql { INSERT INTO x8(x8, rank) VALUES('merge', 1); } | 185 execsql { INSERT INTO x8(x8, rank) VALUES('merge', 1); } |
| 186 mycount | 186 mycount |
| 187 } $expect | 187 } $expect |
| 188 break | 188 break |
| 189 } | 189 } |
| 190 # db eval {SELECT fts5_decode(rowid, block) AS r FROM x8_data} { puts $r } | 190 # db eval {SELECT fts5_decode(rowid, block) AS r FROM x8_data} { puts $r } |
| 191 } | 191 } |
| 192 | 192 |
| 193 #------------------------------------------------------------------------- |
| 194 # Test that the 'merge' command does not modify the database if there is |
| 195 # no work to do. |
| 196 |
| 197 do_execsql_test 5.1 { |
| 198 CREATE VIRTUAL TABLE x9 USING fts5(one, two); |
| 199 INSERT INTO x9(x9, rank) VALUES('pgsz', 32); |
| 200 INSERT INTO x9(x9, rank) VALUES('automerge', 2); |
| 201 INSERT INTO x9(x9, rank) VALUES('usermerge', 2); |
| 202 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 203 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 204 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 205 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 206 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 207 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 208 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 209 INSERT INTO x9 VALUES(rnddoc(100), rnddoc(100)); |
| 210 } |
| 211 |
| 212 do_test 5.2 { |
| 213 while 1 { |
| 214 set nChange [db total_changes] |
| 215 execsql { INSERT INTO x9(x9, rank) VALUES('merge', 1); } |
| 216 set nChange [expr [db total_changes] - $nChange] |
| 217 #puts $nChange |
| 218 if {$nChange<2} break |
| 219 } |
| 220 } {} |
| 221 |
| 222 |
| 223 #-------------------------------------------------------------------------- |
| 224 # Test that running 'merge' on an empty database does not cause a |
| 225 # problem. |
| 226 # |
| 227 reset_db |
| 228 do_execsql_test 6.0 { |
| 229 CREATE VIRTUAL TABLE g1 USING fts5(a, b); |
| 230 } |
| 231 do_execsql_test 6.1 { |
| 232 INSERT INTO g1(g1, rank) VALUES('merge', 10); |
| 233 } |
| 234 do_execsql_test 6.2 { |
| 235 INSERT INTO g1(g1, rank) VALUES('merge', -10); |
| 236 } |
| 237 do_execsql_test 6.3 { |
| 238 INSERT INTO g1(g1) VALUES('integrity-check'); |
| 239 } |
| 240 |
| 241 |
| 242 |
| 193 finish_test | 243 finish_test |
| 194 | 244 |
| OLD | NEW |