| OLD | NEW |
| 1 # 2005 November 30 | 1 # 2005 November 30 |
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 # | 198 # |
| 199 set ::soft_limit [sqlite3_soft_heap_limit -1] | 199 set ::soft_limit [sqlite3_soft_heap_limit -1] |
| 200 execsql {PRAGMA cache_size=2000} | 200 execsql {PRAGMA cache_size=2000} |
| 201 do_test malloc5-4.1 { | 201 do_test malloc5-4.1 { |
| 202 execsql {BEGIN;} | 202 execsql {BEGIN;} |
| 203 execsql {DELETE FROM abc;} | 203 execsql {DELETE FROM abc;} |
| 204 for {set i 0} {$i < 10000} {incr i} { | 204 for {set i 0} {$i < 10000} {incr i} { |
| 205 execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');" | 205 execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');" |
| 206 } | 206 } |
| 207 execsql {COMMIT;} | 207 execsql {COMMIT;} |
| 208 db cache flush |
| 208 sqlite3_release_memory | 209 sqlite3_release_memory |
| 209 sqlite3_memory_highwater 1 | 210 sqlite3_memory_highwater 1 |
| 210 execsql {SELECT * FROM abc} | 211 execsql {SELECT * FROM abc} |
| 211 set nMaxBytes [sqlite3_memory_highwater 1] | 212 set nMaxBytes [sqlite3_memory_highwater 1] |
| 212 puts -nonewline " (Highwater mark: $nMaxBytes) " | 213 puts -nonewline " (Highwater mark: $nMaxBytes) " |
| 213 expr $nMaxBytes > 1000000 | 214 expr $nMaxBytes > 1000000 |
| 214 } {1} | 215 } {1} |
| 215 do_test malloc5-4.2 { | 216 do_test malloc5-4.2 { |
| 217 db cache flush |
| 216 sqlite3_release_memory | 218 sqlite3_release_memory |
| 217 sqlite3_soft_heap_limit 100000 | 219 sqlite3_soft_heap_limit 100000 |
| 218 sqlite3_memory_highwater 1 | 220 sqlite3_memory_highwater 1 |
| 219 execsql {SELECT * FROM abc} | 221 execsql {SELECT * FROM abc} |
| 220 set nMaxBytes [sqlite3_memory_highwater 1] | 222 set nMaxBytes [sqlite3_memory_highwater 1] |
| 221 puts -nonewline " (Highwater mark: $nMaxBytes) " | 223 puts -nonewline " (Highwater mark: $nMaxBytes) " |
| 222 expr $nMaxBytes <= 100000 | 224 expr $nMaxBytes <= 110000 |
| 223 } {1} | 225 } {1} |
| 224 do_test malloc5-4.3 { | 226 do_test malloc5-4.3 { |
| 225 # Check that the content of table abc is at least roughly as expected. | 227 # Check that the content of table abc is at least roughly as expected. |
| 226 execsql { | 228 execsql { |
| 227 SELECT count(*), sum(a), sum(b) FROM abc; | 229 SELECT count(*), sum(a), sum(b) FROM abc; |
| 228 } | 230 } |
| 229 } [list 10000 [expr int(10000.0 * 4999.5)] [expr int(10000.0 * 4999.5)]] | 231 } [list 10000 [expr int(10000.0 * 4999.5)] [expr int(10000.0 * 4999.5)]] |
| 230 | 232 |
| 231 # Restore the soft heap limit. | 233 # Restore the soft heap limit. |
| 232 sqlite3_soft_heap_limit $::soft_limit | 234 sqlite3_soft_heap_limit $::soft_limit |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 # The following test cases (malloc5-6.*) test the new global LRU list | 270 # The following test cases (malloc5-6.*) test the new global LRU list |
| 269 # used to determine the pages to recycle when sqlite3_release_memory is | 271 # used to determine the pages to recycle when sqlite3_release_memory is |
| 270 # called and there is more than one pager open. | 272 # called and there is more than one pager open. |
| 271 # | 273 # |
| 272 proc nPage {db} { | 274 proc nPage {db} { |
| 273 set bt [btree_from_db $db] | 275 set bt [btree_from_db $db] |
| 274 array set stats [btree_pager_stats $bt] | 276 array set stats [btree_pager_stats $bt] |
| 275 set stats(page) | 277 set stats(page) |
| 276 } | 278 } |
| 277 db close | 279 db close |
| 278 file delete -force test.db test.db-journal test2.db test2.db-journal | 280 forcedelete test.db test.db-journal test2.db test2.db-journal |
| 279 | 281 |
| 280 # This block of test-cases (malloc5-6.1.*) prepares two database files | 282 # This block of test-cases (malloc5-6.1.*) prepares two database files |
| 281 # for the subsequent tests. | 283 # for the subsequent tests. |
| 282 do_test malloc5-6.1.1 { | 284 do_test malloc5-6.1.1 { |
| 283 sqlite3 db test.db | 285 sqlite3 db test.db |
| 284 execsql { | 286 execsql { |
| 285 PRAGMA page_size=1024; | 287 PRAGMA page_size=1024; |
| 286 PRAGMA default_cache_size=10; | 288 PRAGMA default_cache_size=10; |
| 287 } | 289 } |
| 288 execsql { | 290 execsql { |
| 289 PRAGMA temp_store = memory; | 291 PRAGMA temp_store = memory; |
| 290 BEGIN; | 292 BEGIN; |
| 291 CREATE TABLE abc(a PRIMARY KEY, b, c); | 293 CREATE TABLE abc(a PRIMARY KEY, b, c); |
| 292 INSERT INTO abc VALUES(randstr(50,50), randstr(75,75), randstr(100,100)); | 294 INSERT INTO abc VALUES(randstr(50,50), randstr(75,75), randstr(100,100)); |
| 293 INSERT INTO abc | 295 INSERT INTO abc |
| 294 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; | 296 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 295 INSERT INTO abc | 297 INSERT INTO abc |
| 296 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; | 298 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 297 INSERT INTO abc | 299 INSERT INTO abc |
| 298 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; | 300 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 299 INSERT INTO abc | 301 INSERT INTO abc |
| 300 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; | 302 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 301 INSERT INTO abc | 303 INSERT INTO abc |
| 302 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; | 304 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 303 INSERT INTO abc | 305 INSERT INTO abc |
| 304 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; | 306 SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 305 COMMIT; | 307 COMMIT; |
| 306 } | 308 } |
| 307 copy_file test.db test2.db | 309 forcecopy test.db test2.db |
| 308 sqlite3 db2 test2.db | 310 sqlite3 db2 test2.db |
| 309 list \ | 311 list \ |
| 310 [expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20] | 312 [expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20] |
| 311 } {1 1} | 313 } {1 1} |
| 312 do_test malloc5-6.1.2 { | 314 do_test malloc5-6.1.2 { |
| 313 list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2] | 315 list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2] |
| 314 } {10 10} | 316 } {10 10} |
| 315 | 317 |
| 316 do_test malloc5-6.2.1 { | 318 do_test malloc5-6.2.1 { |
| 317 execsql {SELECT * FROM abc} db2 | 319 execsql {SELECT * FROM abc} db2 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 345 BEGIN; | 347 BEGIN; |
| 346 UPDATE abc SET c = randstr(100,100) | 348 UPDATE abc SET c = randstr(100,100) |
| 347 WHERE rowid = 1 OR rowid = (SELECT max(rowid) FROM abc); | 349 WHERE rowid = 1 OR rowid = (SELECT max(rowid) FROM abc); |
| 348 } db2 | 350 } db2 |
| 349 execsql { SELECT * FROM abc } db | 351 execsql { SELECT * FROM abc } db |
| 350 expr [nPage db] + [nPage db2] | 352 expr [nPage db] + [nPage db2] |
| 351 } {20} | 353 } {20} |
| 352 do_test malloc5-6.3.2 { | 354 do_test malloc5-6.3.2 { |
| 353 # Try to release 7700 bytes. This should release all the | 355 # Try to release 7700 bytes. This should release all the |
| 354 # non-dirty pages held by db2. | 356 # non-dirty pages held by db2. |
| 355 sqlite3_release_memory [expr 7*1100] | 357 sqlite3_release_memory [expr 7*1132] |
| 356 list [nPage db] [nPage db2] | 358 list [nPage db] [nPage db2] |
| 357 } {10 3} | 359 } {10 3} |
| 358 do_test malloc5-6.3.3 { | 360 do_test malloc5-6.3.3 { |
| 359 # Try to release another 1000 bytes. This should come fromt the db | 361 # Try to release another 1000 bytes. This should come fromt the db |
| 360 # cache, since all three pages held by db2 are either in-use or diry. | 362 # cache, since all three pages held by db2 are either in-use or diry. |
| 361 sqlite3_release_memory 1000 | 363 sqlite3_release_memory 1000 |
| 362 list [nPage db] [nPage db2] | 364 list [nPage db] [nPage db2] |
| 363 } {9 3} | 365 } {9 3} |
| 364 do_test malloc5-6.3.4 { | 366 do_test malloc5-6.3.4 { |
| 365 # Now release 9900 more (about 9 pages worth). This should expunge | 367 # Now release 9900 more (about 9 pages worth). This should expunge |
| 366 # the rest of the db cache. But the db2 cache remains intact, because | 368 # the rest of the db cache. But the db2 cache remains intact, because |
| 367 # SQLite tries to avoid calling sync(). | 369 # SQLite tries to avoid calling sync(). |
| 368 if {$::tcl_platform(wordSize)==8} { | 370 if {$::tcl_platform(wordSize)==8} { |
| 369 sqlite3_release_memory 10177 | 371 sqlite3_release_memory 10500 |
| 370 } else { | 372 } else { |
| 371 sqlite3_release_memory 9900 | 373 sqlite3_release_memory 9900 |
| 372 } | 374 } |
| 373 list [nPage db] [nPage db2] | 375 list [nPage db] [nPage db2] |
| 374 } {0 3} | 376 } {0 3} |
| 375 do_test malloc5-6.3.5 { | 377 do_test malloc5-6.3.5 { |
| 376 # But if we are really insistent, SQLite will consent to call sync() | 378 # But if we are really insistent, SQLite will consent to call sync() |
| 377 # if there is no other option. UPDATE: As of 3.6.2, SQLite will not | 379 # if there is no other option. UPDATE: As of 3.6.2, SQLite will not |
| 378 # call sync() in this scenario. So no further memory can be reclaimed. | 380 # call sync() in this scenario. So no further memory can be reclaimed. |
| 379 sqlite3_release_memory 1000 | 381 sqlite3_release_memory 1000 |
| 380 list [nPage db] [nPage db2] | 382 list [nPage db] [nPage db2] |
| 381 } {0 3} | 383 } {0 3} |
| 382 do_test malloc5-6.3.6 { | 384 do_test malloc5-6.3.6 { |
| 383 # The referenced page (page 1 of the db2 cache) will not be freed no | 385 # The referenced page (page 1 of the db2 cache) will not be freed no |
| 384 # matter how much memory we ask for: | 386 # matter how much memory we ask for: |
| 385 sqlite3_release_memory 31459 | 387 sqlite3_release_memory 31459 |
| 386 list [nPage db] [nPage db2] | 388 list [nPage db] [nPage db2] |
| 387 } {0 3} | 389 } {0 3} |
| 388 | 390 |
| 389 db2 close | 391 db2 close |
| 390 | 392 |
| 391 sqlite3_soft_heap_limit $::soft_limit | 393 sqlite3_soft_heap_limit $::soft_limit |
| 392 finish_test | 394 finish_test |
| 393 catch {db close} | 395 catch {db close} |
| OLD | NEW |