1
0

io.test 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. # 2007 August 21
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # The focus of this file is testing some specific characteristics of the
  13. # IO traffic generated by SQLite (making sure SQLite is not writing out
  14. # more database pages than it has to, stuff like that).
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. set ::testprefix io
  19. db close
  20. sqlite3_simulate_device
  21. sqlite3 db test.db -vfs devsym
  22. # Test summary:
  23. #
  24. # io-1.* - Test that quick-balance does not journal pages unnecessarily.
  25. #
  26. # io-2.* - Test the "atomic-write optimization".
  27. #
  28. # io-3.* - Test the IO traffic enhancements triggered when the
  29. # IOCAP_SEQUENTIAL device capability flag is set (no
  30. # fsync() calls on the journal file).
  31. #
  32. # io-4.* - Test the IO traffic enhancements triggered when the
  33. # IOCAP_SAFE_APPEND device capability flag is set (fewer
  34. # fsync() calls on the journal file, no need to set nRec
  35. # field in the single journal header).
  36. #
  37. # io-5.* - Test that the default page size is selected and used
  38. # correctly.
  39. #
  40. # io-6.* - Test that the pager-cache is not being flushed unnecessarily
  41. # after a transaction that uses the special atomic-write path
  42. # is committed.
  43. #
  44. set ::nWrite 0
  45. proc nWrite {db} {
  46. set bt [btree_from_db $db]
  47. db_enter $db
  48. array set stats [btree_pager_stats $bt]
  49. db_leave $db
  50. set res [expr $stats(write) - $::nWrite]
  51. set ::nWrite $stats(write)
  52. set res
  53. }
  54. set ::nSync 0
  55. proc nSync {} {
  56. set res [expr {$::sqlite_sync_count - $::nSync}]
  57. set ::nSync $::sqlite_sync_count
  58. set res
  59. }
  60. do_test io-1.1 {
  61. execsql {
  62. PRAGMA auto_vacuum = OFF;
  63. PRAGMA page_size = 1024;
  64. CREATE TABLE abc(a,b);
  65. }
  66. nWrite db
  67. } {2}
  68. # Insert into the table 4 records of aproximately 240 bytes each.
  69. # This should completely fill the root-page of the table. Each
  70. # INSERT causes 2 db pages to be written - the root-page of "abc"
  71. # and page 1 (db change-counter page).
  72. do_test io-1.2 {
  73. set ret [list]
  74. execsql { INSERT INTO abc VALUES(1,randstr(230,230)); }
  75. lappend ret [nWrite db]
  76. execsql { INSERT INTO abc VALUES(2,randstr(230,230)); }
  77. lappend ret [nWrite db]
  78. execsql { INSERT INTO abc VALUES(3,randstr(230,230)); }
  79. lappend ret [nWrite db]
  80. execsql { INSERT INTO abc VALUES(4,randstr(230,230)); }
  81. lappend ret [nWrite db]
  82. } {2 2 2 2}
  83. # Insert another 240 byte record. This causes two leaf pages
  84. # to be added to the root page of abc. 4 pages in total
  85. # are written to the db file - the two leaf pages, the root
  86. # of abc and the change-counter page.
  87. do_test io-1.3 {
  88. execsql { INSERT INTO abc VALUES(5,randstr(230,230)); }
  89. nWrite db
  90. } {4}
  91. # Insert another 3 240 byte records. After this, the tree consists of
  92. # the root-node, which is close to empty, and two leaf pages, both of
  93. # which are full.
  94. do_test io-1.4 {
  95. set ret [list]
  96. execsql { INSERT INTO abc VALUES(6,randstr(230,230)); }
  97. lappend ret [nWrite db]
  98. execsql { INSERT INTO abc VALUES(7,randstr(230,230)); }
  99. lappend ret [nWrite db]
  100. execsql { INSERT INTO abc VALUES(8,randstr(230,230)); }
  101. lappend ret [nWrite db]
  102. } {2 2 2}
  103. # This insert should use the quick-balance trick to add a third leaf
  104. # to the b-tree used to store table abc. It should only be necessary to
  105. # write to 3 pages to do this: the change-counter, the root-page and
  106. # the new leaf page.
  107. do_test io-1.5 {
  108. execsql { INSERT INTO abc VALUES(9,randstr(230,230)); }
  109. nWrite db
  110. } {3}
  111. ifcapable atomicwrite {
  112. #----------------------------------------------------------------------
  113. # Test cases io-2.* test the atomic-write optimization.
  114. #
  115. do_test io-2.1 {
  116. execsql { DELETE FROM abc; VACUUM; }
  117. } {}
  118. # Clear the write and sync counts.
  119. nWrite db ; nSync
  120. # The following INSERT updates 2 pages and requires 4 calls to fsync():
  121. #
  122. # 1) The directory in which the journal file is created,
  123. # 2) The journal file (to sync the page data),
  124. # 3) The journal file (to sync the journal file header),
  125. # 4) The database file.
  126. #
  127. do_test io-2.2 {
  128. execsql { INSERT INTO abc VALUES(1, 2) }
  129. list [nWrite db] [nSync]
  130. } {2 4}
  131. # Set the device-characteristic mask to include the SQLITE_IOCAP_ATOMIC,
  132. # then do another INSERT similar to the one in io-2.2. This should
  133. # only write 1 page and require a single fsync().
  134. #
  135. # The single fsync() is the database file. Only one page is reported as
  136. # written because page 1 - the change-counter page - is written using
  137. # an out-of-band method that bypasses the write counter.
  138. #
  139. # UPDATE: As of [05f98d4eec] (adding SQLITE_DBSTATUS_CACHE_WRITE), the
  140. # second write is also counted. So this now reports two writes and a
  141. # single fsync.
  142. #
  143. sqlite3_simulate_device -char atomic
  144. do_test io-2.3 {
  145. execsql { INSERT INTO abc VALUES(3, 4) }
  146. list [nWrite db] [nSync]
  147. } {2 1}
  148. # Test that the journal file is not created and the change-counter is
  149. # updated when the atomic-write optimization is used.
  150. #
  151. do_test io-2.4.1 {
  152. execsql {
  153. BEGIN;
  154. INSERT INTO abc VALUES(5, 6);
  155. }
  156. sqlite3 db2 test.db -vfs devsym
  157. execsql { SELECT * FROM abc } db2
  158. } {1 2 3 4}
  159. do_test io-2.4.2 {
  160. file exists test.db-journal
  161. } {0}
  162. do_test io-2.4.3 {
  163. execsql { COMMIT }
  164. execsql { SELECT * FROM abc } db2
  165. } {1 2 3 4 5 6}
  166. db2 close
  167. # Test that the journal file is created and sync()d if the transaction
  168. # modifies more than one database page, even if the IOCAP_ATOMIC flag
  169. # is set.
  170. #
  171. do_test io-2.5.1 {
  172. execsql { CREATE TABLE def(d, e) }
  173. nWrite db ; nSync
  174. execsql {
  175. BEGIN;
  176. INSERT INTO abc VALUES(7, 8);
  177. }
  178. file exists test.db-journal
  179. } {0}
  180. do_test io-2.5.2 {
  181. execsql { INSERT INTO def VALUES('a', 'b'); }
  182. file exists test.db-journal
  183. } {1}
  184. do_test io-2.5.3 {
  185. execsql { COMMIT }
  186. list [nWrite db] [nSync]
  187. } {3 4}
  188. # Test that the journal file is created and sync()d if the transaction
  189. # modifies a single database page and also appends a page to the file.
  190. # Internally, this case is handled differently to the one above. The
  191. # journal file is not actually created until the 'COMMIT' statement
  192. # is executed.
  193. #
  194. # Changed 2010-03-27: The size of the database is now stored in
  195. # bytes 28..31 and so when a page is added to the database, page 1
  196. # is immediately modified and the journal file immediately comes into
  197. # existence. To fix this test, the BEGIN is changed into a a
  198. # BEGIN IMMEDIATE and the INSERT is omitted.
  199. #
  200. do_test io-2.6.1 {
  201. execsql {
  202. BEGIN IMMEDIATE;
  203. -- INSERT INTO abc VALUES(9, randstr(1000,1000));
  204. }
  205. file exists test.db-journal
  206. } {0}
  207. do_test io-2.6.2 {
  208. # Create a file at "test.db-journal". This will prevent SQLite from
  209. # opening the journal for exclusive access. As a result, the COMMIT
  210. # should fail with SQLITE_CANTOPEN and the transaction rolled back.
  211. #
  212. file mkdir test.db-journal
  213. catchsql {
  214. INSERT INTO abc VALUES(9, randstr(1000,1000));
  215. COMMIT
  216. }
  217. } {1 {unable to open database file}}
  218. do_test io-2.6.3 {
  219. forcedelete test.db-journal
  220. catchsql { COMMIT }
  221. } {0 {}}
  222. do_test io-2.6.4 {
  223. execsql { SELECT * FROM abc }
  224. } {1 2 3 4 5 6 7 8}
  225. # Test that if the database modification is part of multi-file commit,
  226. # the journal file is always created. In this case, the journal file
  227. # is created during execution of the COMMIT statement, so we have to
  228. # use the same technique to check that it is created as in the above
  229. # block.
  230. forcedelete test2.db test2.db-journal
  231. ifcapable attach {
  232. do_test io-2.7.1 {
  233. execsql {
  234. ATTACH 'test2.db' AS aux;
  235. PRAGMA aux.page_size = 1024;
  236. CREATE TABLE aux.abc2(a, b);
  237. BEGIN;
  238. INSERT INTO abc VALUES(9, 10);
  239. }
  240. file exists test.db-journal
  241. } {0}
  242. do_test io-2.7.2 {
  243. execsql { INSERT INTO abc2 SELECT * FROM abc }
  244. file exists test2.db-journal
  245. } {0}
  246. do_test io-2.7.3 {
  247. execsql { SELECT * FROM abc UNION ALL SELECT * FROM abc2 }
  248. } {1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10}
  249. do_test io-2.7.4 {
  250. file mkdir test2.db-journal
  251. catchsql { COMMIT }
  252. } {1 {unable to open database file}}
  253. do_test io-2.7.5 {
  254. forcedelete test2.db-journal
  255. catchsql { COMMIT }
  256. } {1 {cannot commit - no transaction is active}}
  257. do_test io-2.7.6 {
  258. execsql { SELECT * FROM abc UNION ALL SELECT * FROM abc2 }
  259. } {1 2 3 4 5 6 7 8}
  260. }
  261. # Try an explicit ROLLBACK before the journal file is created.
  262. #
  263. do_test io-2.8.1 {
  264. execsql {
  265. BEGIN;
  266. DELETE FROM abc;
  267. }
  268. file exists test.db-journal
  269. } {0}
  270. do_test io-2.8.2 {
  271. execsql { SELECT * FROM abc }
  272. } {}
  273. do_test io-2.8.3 {
  274. execsql {
  275. ROLLBACK;
  276. SELECT * FROM abc;
  277. }
  278. } {1 2 3 4 5 6 7 8}
  279. # Test that the atomic write optimisation is not enabled if the sector
  280. # size is larger than the page-size.
  281. #
  282. do_test io-2.9.1 {
  283. db close
  284. sqlite3 db test.db
  285. sqlite3_simulate_device -char atomic -sectorsize 2048
  286. execsql {
  287. BEGIN;
  288. INSERT INTO abc VALUES(9, 10);
  289. }
  290. file exists test.db-journal
  291. } {1}
  292. do_test io-2.9.2 {
  293. execsql { ROLLBACK; }
  294. db close
  295. forcedelete test.db test.db-journal
  296. sqlite3 db test.db -vfs devsym
  297. execsql {
  298. PRAGMA auto_vacuum = OFF;
  299. PRAGMA page_size = 2048;
  300. CREATE TABLE abc(a, b);
  301. }
  302. execsql {
  303. BEGIN;
  304. INSERT INTO abc VALUES(9, 10);
  305. }
  306. file exists test.db-journal
  307. } {0}
  308. do_test io-2.9.3 {
  309. execsql { COMMIT }
  310. } {}
  311. # Test a couple of the more specific IOCAP_ATOMIC flags
  312. # (i.e IOCAP_ATOMIC2K etc.).
  313. #
  314. do_test io-2.10.1 {
  315. sqlite3_simulate_device -char atomic1k
  316. execsql {
  317. BEGIN;
  318. INSERT INTO abc VALUES(11, 12);
  319. }
  320. file exists test.db-journal
  321. } {1}
  322. do_test io-2.10.2 {
  323. execsql { ROLLBACK }
  324. sqlite3_simulate_device -char atomic2k
  325. execsql {
  326. BEGIN;
  327. INSERT INTO abc VALUES(11, 12);
  328. }
  329. file exists test.db-journal
  330. } {0}
  331. do_test io-2.10.3 {
  332. execsql { ROLLBACK }
  333. } {}
  334. do_test io-2.11.0 {
  335. execsql {
  336. PRAGMA locking_mode = exclusive;
  337. PRAGMA locking_mode;
  338. }
  339. } {exclusive exclusive}
  340. do_test io-2.11.1 {
  341. execsql {
  342. INSERT INTO abc VALUES(11, 12);
  343. }
  344. file exists test.db-journal
  345. } {0}
  346. do_test io-2.11.2 {
  347. execsql {
  348. PRAGMA locking_mode = normal;
  349. INSERT INTO abc VALUES(13, 14);
  350. }
  351. file exists test.db-journal
  352. } {0}
  353. } ;# /* ifcapable atomicwrite */
  354. #----------------------------------------------------------------------
  355. # Test cases io-3.* test the IOCAP_SEQUENTIAL optimization.
  356. #
  357. sqlite3_simulate_device -char sequential -sectorsize 0
  358. ifcapable pager_pragmas {
  359. do_test io-3.1 {
  360. db close
  361. forcedelete test.db test.db-journal
  362. sqlite3 db test.db -vfs devsym
  363. db eval {
  364. PRAGMA auto_vacuum=OFF;
  365. }
  366. # File size might be 1 due to the hack to work around ticket #3260.
  367. # Search for #3260 in os_unix.c for additional information.
  368. expr {[file size test.db]>1}
  369. } {0}
  370. do_test io-3.2 {
  371. execsql { CREATE TABLE abc(a, b) }
  372. nSync
  373. execsql {
  374. PRAGMA temp_store = memory;
  375. PRAGMA cache_size = 10;
  376. BEGIN;
  377. INSERT INTO abc VALUES('hello', 'world');
  378. INSERT INTO abc SELECT * FROM abc;
  379. INSERT INTO abc SELECT * FROM abc;
  380. INSERT INTO abc SELECT * FROM abc;
  381. INSERT INTO abc SELECT * FROM abc;
  382. INSERT INTO abc SELECT * FROM abc;
  383. INSERT INTO abc SELECT * FROM abc;
  384. INSERT INTO abc SELECT * FROM abc;
  385. INSERT INTO abc SELECT * FROM abc;
  386. INSERT INTO abc SELECT * FROM abc;
  387. INSERT INTO abc SELECT * FROM abc;
  388. INSERT INTO abc SELECT * FROM abc;
  389. }
  390. # File has grown - showing there was a cache-spill - but there
  391. # have been no calls to fsync(). The file is probably about 30KB.
  392. # But some VFS implementations (symbian) buffer writes so the actual
  393. # size may be a little less than that. So this test case just tests
  394. # that the file is now greater than 20000 bytes in size.
  395. list [expr [file size test.db]>20000] [nSync]
  396. } {1 0}
  397. do_test io-3.3 {
  398. # The COMMIT requires a single fsync() - to the database file.
  399. execsql { COMMIT }
  400. list [file size test.db] [nSync]
  401. } {39936 1}
  402. }
  403. #----------------------------------------------------------------------
  404. # Test cases io-4.* test the IOCAP_SAFE_APPEND optimization.
  405. #
  406. sqlite3_simulate_device -char safe_append
  407. # With the SAFE_APPEND flag set, simple transactions require 3, rather
  408. # than 4, calls to fsync(). The fsync() calls are on:
  409. #
  410. # 1) The directory in which the journal file is created, (unix only)
  411. # 2) The journal file (to sync the page data),
  412. # 3) The database file.
  413. #
  414. # Normally, when the SAFE_APPEND flag is not set, there is another fsync()
  415. # on the journal file between steps (2) and (3) above.
  416. #
  417. set expected_sync_count 2
  418. if {$::tcl_platform(platform)=="unix"} {
  419. ifcapable dirsync {
  420. incr expected_sync_count
  421. }
  422. }
  423. do_test io-4.1 {
  424. execsql { DELETE FROM abc }
  425. nSync
  426. execsql { INSERT INTO abc VALUES('a', 'b') }
  427. nSync
  428. } $expected_sync_count
  429. # With SAFE_APPEND set, the nRec field of the journal file header should
  430. # be set to 0xFFFFFFFF before the first journal sync. The nRec field
  431. # occupies bytes 8-11 of the journal file.
  432. #
  433. do_test io-4.2.1 {
  434. execsql { BEGIN }
  435. execsql { INSERT INTO abc VALUES('c', 'd') }
  436. file exists test.db-journal
  437. } {1}
  438. if {$::tcl_platform(platform)=="unix"} {
  439. do_test io-4.2.2 {
  440. hexio_read test.db-journal 8 4
  441. } {FFFFFFFF}
  442. }
  443. do_test io-4.2.3 {
  444. execsql { COMMIT }
  445. nSync
  446. } $expected_sync_count
  447. sqlite3_simulate_device -char safe_append
  448. # With SAFE_APPEND set, there should only ever be one journal-header
  449. # written to the database, even though the sync-mode is "full".
  450. #
  451. do_test io-4.3.1 {
  452. execsql {
  453. INSERT INTO abc SELECT * FROM abc;
  454. INSERT INTO abc SELECT * FROM abc;
  455. INSERT INTO abc SELECT * FROM abc;
  456. INSERT INTO abc SELECT * FROM abc;
  457. INSERT INTO abc SELECT * FROM abc;
  458. INSERT INTO abc SELECT * FROM abc;
  459. INSERT INTO abc SELECT * FROM abc;
  460. INSERT INTO abc SELECT * FROM abc;
  461. INSERT INTO abc SELECT * FROM abc;
  462. INSERT INTO abc SELECT * FROM abc;
  463. INSERT INTO abc SELECT * FROM abc;
  464. }
  465. expr {[file size test.db]/1024}
  466. } {43}
  467. ifcapable pager_pragmas {
  468. do_test io-4.3.2 {
  469. execsql {
  470. PRAGMA synchronous = full;
  471. PRAGMA cache_size = 10;
  472. PRAGMA synchronous;
  473. }
  474. } {2}
  475. }
  476. do_test io-4.3.3 {
  477. execsql {
  478. BEGIN;
  479. UPDATE abc SET a = 'x';
  480. }
  481. file exists test.db-journal
  482. } {1}
  483. if {$tcl_platform(platform) != "symbian"} {
  484. # This test is not run on symbian because the file-buffer makes it
  485. # difficult to predict the exact size of the file as reported by
  486. # [file size].
  487. do_test io-4.3.4 {
  488. # The UPDATE statement in the statement above modifies 41 pages
  489. # (all pages in the database except page 1 and the root page of
  490. # abc). Because the cache_size is set to 10, this must have required
  491. # at least 4 cache-spills. If there were no journal headers written
  492. # to the journal file after the cache-spill, then the size of the
  493. # journal file is give by:
  494. #
  495. # <jrnl file size> = <jrnl header size> + nPage * (<page-size> + 8)
  496. #
  497. # If the journal file contains additional headers, this formula
  498. # will not predict the size of the journal file.
  499. #
  500. file size test.db-journal
  501. } [expr 512 + (1024+8)*41]
  502. }
  503. #----------------------------------------------------------------------
  504. # Test cases io-5.* test that the default page size is selected and
  505. # used correctly.
  506. #
  507. set tn 0
  508. foreach {char sectorsize pgsize} {
  509. {} 512 1024
  510. {} 1024 1024
  511. {} 2048 2048
  512. {} 8192 8192
  513. {} 16384 8192
  514. {atomic} 512 8192
  515. {atomic512} 512 1024
  516. {atomic2K} 512 2048
  517. {atomic2K} 4096 4096
  518. {atomic2K atomic} 512 8192
  519. {atomic64K} 512 1024
  520. } {
  521. incr tn
  522. if {$pgsize>$::SQLITE_MAX_PAGE_SIZE} continue
  523. db close
  524. forcedelete test.db test.db-journal
  525. sqlite3_simulate_device -char $char -sectorsize $sectorsize
  526. sqlite3 db test.db -vfs devsym
  527. db eval {
  528. PRAGMA auto_vacuum=OFF;
  529. }
  530. ifcapable !atomicwrite {
  531. if {[regexp {^atomic} $char]} continue
  532. }
  533. do_test io-5.$tn {
  534. execsql {
  535. CREATE TABLE abc(a, b, c);
  536. }
  537. expr {[file size test.db]/2}
  538. } $pgsize
  539. }
  540. #----------------------------------------------------------------------
  541. #
  542. do_test io-6.1 {
  543. db close
  544. sqlite3_simulate_device -char atomic
  545. forcedelete test.db
  546. sqlite3 db test.db -vfs devsym
  547. execsql {
  548. PRAGMA mmap_size = 0;
  549. PRAGMA page_size = 1024;
  550. PRAGMA cache_size = 2000;
  551. CREATE TABLE t1(x);
  552. CREATE TABLE t2(x);
  553. CREATE TABLE t3(x);
  554. CREATE INDEX i3 ON t3(x);
  555. INSERT INTO t3 VALUES(randomblob(100));
  556. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  557. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  558. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  559. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  560. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  561. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  562. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  563. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  564. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  565. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  566. INSERT INTO t3 SELECT randomblob(100) FROM t3;
  567. }
  568. db_save_and_close
  569. } {}
  570. foreach {tn sql} {
  571. 1 { BEGIN;
  572. INSERT INTO t1 VALUES('123');
  573. INSERT INTO t2 VALUES('456');
  574. COMMIT;
  575. }
  576. 2 { BEGIN;
  577. INSERT INTO t1 VALUES('123');
  578. COMMIT;
  579. }
  580. } {
  581. # These tests don't work with memsubsys1, as it causes the effective page
  582. # cache size to become too small to hold the entire db in memory.
  583. if {[permutation] == "memsubsys1"} continue
  584. db_restore
  585. sqlite3 db test.db -vfs devsym
  586. execsql {
  587. PRAGMA cache_size = 2000;
  588. PRAGMA mmap_size = 0;
  589. SELECT x FROM t3 ORDER BY rowid;
  590. SELECT x FROM t3 ORDER BY x;
  591. }
  592. do_execsql_test 6.2.$tn.1 { PRAGMA integrity_check } {ok}
  593. do_execsql_test 6.2.$tn.2 $sql
  594. # Corrupt the database file on disk. This should not matter for the
  595. # purposes of the following "PRAGMA integrity_check", as the entire
  596. # database should be cached in the pager-cache. If corruption is
  597. # reported, it indicates that executing $sql caused the pager cache
  598. # to be flushed. Which is a bug.
  599. hexio_write test.db [expr 1024 * 5] [string repeat 00 2048]
  600. do_execsql_test 6.2.$tn.3 { PRAGMA integrity_check } {ok}
  601. db close
  602. }
  603. sqlite3_simulate_device -char {} -sectorsize 0
  604. finish_test