⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autovacuum.test

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TEST
📖 第 1 页 / 共 2 页
字号:
    INSERT INTO av2 VALUES('av2 a', 'av2 b', 'av2 c');    CREATE TABLE av3(a PRIMARY KEY, b, c);    CREATE INDEX av3_i1 ON av3(b);    INSERT INTO av3 VALUES('av3 a', 'av3 b', 'av3 c');    CREATE TABLE av4(a, b, c);    CREATE INDEX av4_i1 ON av4(a);    CREATE INDEX av4_i2 ON av4(b);    CREATE INDEX av4_i3 ON av4(c);    CREATE INDEX av4_i4 ON av4(a, b, c);    INSERT INTO av4 VALUES('av4 a', 'av4 b', 'av4 c');  }} {}do_test autovacuum-2.5.2 {  execsql {    SELECT name, rootpage FROM sqlite_master;  }} [list av1 3  sqlite_autoindex_av1_1 4 \        av2 5  sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \        av3 9 sqlite_autoindex_av3_1 10 av3_i1 11 \        av4 12 av4_i1 13 av4_i2 14 av4_i3 15 av4_i4 16 \]# The following 4 tests are SELECT queries that use the indices created.# If the root-pages in the internal schema are not updated correctly when# a table or indice is moved, these queries will fail. They are repeated# after each table is dropped (i.e. as test cases 2.5.*.[1..4]).do_test autovacuum-2.5.2.1 {  execsql {    SELECT * FROM av1 WHERE a = 'av1 a';  }} {{av1 a} {av1 b} {av1 c}}do_test autovacuum-2.5.2.2 {  execsql {    SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'  }} {{av2 a} {av2 b} {av2 c}}do_test autovacuum-2.5.2.3 {  execsql {    SELECT * FROM av3 WHERE a = 'av3 a' AND b = 'av3 b';  }} {{av3 a} {av3 b} {av3 c}}do_test autovacuum-2.5.2.4 {  execsql {    SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';  }} {{av4 a} {av4 b} {av4 c}}# Drop table av3. Indices av4_i2, av4_i3 and av4_i4 are moved to fill the two# root pages vacated. The operation proceeds as:# Step 1: Delete av3_i1 (root-page 11). Move root-page of av4_i4 to page 11.# Step 2: Delete av3 (root-page 10). Move root-page of av4_i3 to page 10.# Step 3: Delete sqlite_autoindex_av1_3 (root-page 9). Move av4_i2 to page 9.do_test autovacuum-2.5.3 {  execsql {    DROP TABLE av3;    SELECT name, rootpage FROM sqlite_master;  }} [list av1 3  sqlite_autoindex_av1_1 4 \        av2 5  sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \        av4 12 av4_i1 13 av4_i2 9 av4_i3 10 av4_i4 11 \]do_test autovacuum-2.5.3.1 {  execsql {    SELECT * FROM av1 WHERE a = 'av1 a';  }} {{av1 a} {av1 b} {av1 c}}do_test autovacuum-2.5.3.2 {  execsql {    SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'  }} {{av2 a} {av2 b} {av2 c}}do_test autovacuum-2.5.3.3 {  execsql {    SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';  }} {{av4 a} {av4 b} {av4 c}}# Drop table av1:# Step 1: Delete av1 (root page 4). Root-page of av4_i1 fills the gap.# Step 2: Delete sqlite_autoindex_av1_1 (root page 3). Move av4 to the gap.do_test autovacuum-2.5.4 {  execsql {    DROP TABLE av1;    SELECT name, rootpage FROM sqlite_master;  }} [list av2 5  sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \        av4 3 av4_i1 4 av4_i2 9 av4_i3 10 av4_i4 11 \]do_test autovacuum-2.5.4.2 {  execsql {    SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'  }} {{av2 a} {av2 b} {av2 c}}do_test autovacuum-2.5.4.4 {  execsql {    SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';  }} {{av4 a} {av4 b} {av4 c}}# Drop table av4:# Step 1: Delete av4_i4.# Step 2: Delete av4_i3.# Step 3: Delete av4_i2.# Step 4: Delete av4_i1. av2_i2 replaces it.# Step 5: Delete av4. av2_i1 replaces it.do_test autovacuum-2.5.5 {  execsql {    DROP TABLE av4;    SELECT name, rootpage FROM sqlite_master;  }} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 3 av2_i2 4]do_test autovacuum-2.5.5.2 {  execsql {    SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'  }} {{av2 a} {av2 b} {av2 c}}#--------------------------------------------------------------------------# Test cases autovacuum-3.* test the operation of the "PRAGMA auto_vacuum"# command.#do_test autovacuum-3.1 {  execsql {    PRAGMA auto_vacuum;  }} {1}do_test autovacuum-3.2 {  db close  sqlite3 db test.db  execsql {    PRAGMA auto_vacuum;  }} {1}do_test autovacuum-3.3 {  execsql {    PRAGMA auto_vacuum = 0;    PRAGMA auto_vacuum;  }} {1}do_test autovacuum-3.4 {  db close  file delete -force test.db  sqlite3 db test.db  execsql {    PRAGMA auto_vacuum;  }} $AUTOVACUUMdo_test autovacuum-3.5 {  execsql {    CREATE TABLE av1(x);    PRAGMA auto_vacuum;  }} $AUTOVACUUMdo_test autovacuum-3.6 {  execsql {    PRAGMA auto_vacuum = 1;    PRAGMA auto_vacuum;  }} $AUTOVACUUMdo_test autovacuum-3.7 {  execsql {    DROP TABLE av1;  }  file_pages} [expr $AUTOVACUUM?1:2]#-----------------------------------------------------------------------# Test that if a statement transaction around a CREATE INDEX statement is# rolled back no corruption occurs.#do_test autovacuum-4.0 {  # The last round of tests may have left the db in non-autovacuum mode.  # Reset everything just in case.  #  db close  file delete -force test.db test.db-journal  sqlite3 db test.db  execsql {    PRAGMA auto_vacuum = 1;    PRAGMA auto_vacuum;  }} {1}do_test autovacuum-4.1 {  execsql {    CREATE TABLE av1(a, b);    BEGIN;  }  for {set i 0} {$i<100} {incr i} {    execsql "INSERT INTO av1 VALUES($i, '[string repeat X 200]');"  }  execsql "INSERT INTO av1 VALUES(99, '[string repeat X 200]');"  execsql {    SELECT sum(a) FROM av1;  }} {5049}do_test autovacuum-4.2 {  catchsql {    CREATE UNIQUE INDEX av1_i ON av1(a);  }} {1 {indexed columns are not unique}}do_test autovacuum-4.3 {  execsql {    SELECT sum(a) FROM av1;  }} {5049}do_test autovacuum-4.4 {  execsql {    COMMIT;  }} {}ifcapable integrityck {# Ticket #1727do_test autovacuum-5.1 {  db close  sqlite3 db :memory:  db eval {    PRAGMA auto_vacuum=1;    CREATE TABLE t1(a);    CREATE TABLE t2(a);    DROP TABLE t1;    PRAGMA integrity_check;  }} ok}# Ticket #1728.## In autovacuum mode, when tables or indices are deleted, the rootpage# values in the symbol table have to be updated.  There was a bug in this# logic so that if an index/table was moved twice, the second move might# not occur.  This would leave the internal symbol table in an inconsistent# state causing subsequent statements to fail.## The problem is difficult to reproduce.  The sequence of statements in# the following test are carefully designed make it occur and thus to# verify that this very obscure bug has been resolved.# ifcapable integrityck&&memorydb {do_test autovacuum-6.1 {  db close  sqlite3 db :memory:  db eval {    PRAGMA auto_vacuum=1;    CREATE TABLE t1(a, b);    CREATE INDEX i1 ON t1(a);    CREATE TABLE t2(a);    CREATE INDEX i2 ON t2(a);    CREATE TABLE t3(a);    CREATE INDEX i3 ON t2(a);    CREATE INDEX x ON t1(b);    DROP TABLE t3;    PRAGMA integrity_check;    DROP TABLE t2;    PRAGMA integrity_check;    DROP TABLE t1;    PRAGMA integrity_check;  }} {ok ok ok}}#---------------------------------------------------------------------# Test cases autovacuum-7.X test the case where a page must be moved# and the destination location collides with at least one other# entry in the page hash-table (internal to the pager.c module. #do_test autovacuum-7.1 {  db close  file delete -force test.db  file delete -force test.db-journal  sqlite3 db test.db  execsql {    PRAGMA auto_vacuum=1;    CREATE TABLE t1(a, b, PRIMARY KEY(a, b));    INSERT INTO t1 VALUES(randstr(400,400),randstr(400,400));    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 4    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 8    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 16    INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 32  }  expr {[file size test.db] / 1024}} {73}do_test autovacuum-7.2 {  execsql {    CREATE TABLE t2(a, b, PRIMARY KEY(a, b));    INSERT INTO t2 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2    CREATE TABLE t3(a, b, PRIMARY KEY(a, b));    INSERT INTO t3 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2    CREATE TABLE t4(a, b, PRIMARY KEY(a, b));    INSERT INTO t4 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2    CREATE TABLE t5(a, b, PRIMARY KEY(a, b));    INSERT INTO t5 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2  }  expr {[file size test.db] / 1024}} {354}do_test autovacuum-7.3 {  db close  sqlite3 db test.db  execsql {    BEGIN;    DELETE FROM t4;    COMMIT;    SELECT count(*) FROM t1;  }  expr {[file size test.db] / 1024}} {286}finish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -