]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests to file e_reindex.test.
authordan <dan@noemail.net>
Sat, 25 Sep 2010 07:51:58 +0000 (07:51 +0000)
committerdan <dan@noemail.net>
Sat, 25 Sep 2010 07:51:58 +0000 (07:51 +0000)
FossilOrigin-Name: eec7dc9192c635335a4a9acc3669afd4b26f02d3

manifest
manifest.uuid
test/e_reindex.test

index 5da24578538b346b3214f27cc7c0f357dec09e8b..528d9cbf3912572d8e9f2d7d1a44c39a32b23726 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Modify\ssome\sevidence\stags\sto\smatch\supdated\sgifs.
-D 2010-09-24T19:14:43
+C Add\stests\sto\sfile\se_reindex.test.
+D 2010-09-25T07:51:58
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -353,7 +353,7 @@ F test/e_expr.test 164e87c1d7b40ceb47c57c3bffa384c81d009aa7
 F test/e_fkey.test 6721a741c6499b3ab7e5385923233343c8f1ad05
 F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469
 F test/e_insert.test d6af6e4a305afe1efbc8f0be7b68edc46abc17d8
-F test/e_reindex.test f5896a9ab63e5efebd46eb0f89fc41ae259ac2f6
+F test/e_reindex.test a064f0878b8f848fbca38f1f61f82f15a3000c64
 F test/e_select.test 6c0244eacf43bf8406d7ae3363d77265b0d4ff8f
 F test/e_select2.test 5c3d3da19c7b3e90ae444579db2b70098599ab92
 F test/e_update.test 963d6876064e65f318d1c93aaed36a02b9b389bf
@@ -866,7 +866,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 83ecec5d158c48e2fb93b0111ade62f039613540
-R 18ee703f40a84daf5754b84abc7b59a1
+P f44de500be5130d5ad800759acb76377eaa92367
+R a1a3a4e3969cb2b2caea2f24a8289e52
 U dan
-Z 23dabc640af74399ac25d70298845e9d
+Z 9c46bcafe300f163a2067cd0d7ffbcd2
index 8c573bcd6e294cf7e7676937e020a6bde8875a92..019693c2bec77b8a8821934d4a88e8297b56db47 100644 (file)
@@ -1 +1 @@
-f44de500be5130d5ad800759acb76377eaa92367
\ No newline at end of file
+eec7dc9192c635335a4a9acc3669afd4b26f02d3
\ No newline at end of file
index 04bfcdc0239c88b7dc55a80e55a9916e0f9f443c..e9419dff8a4c8986d368900be9923c1da68d0d23 100644 (file)
@@ -38,5 +38,257 @@ do_reindex_tests e_reindex-0.1 {
   5   "REINDEX main.i1"   {}
 }
 
+# EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and
+# recreate indices from scratch.
+#
+#    Test this by corrupting some database indexes, running REINDEX, and
+#    observing that the corruption is gone.
+#
+do_execsql_test e_reindex-1.1 {
+  INSERT INTO t1 VALUES(1, 2);
+  INSERT INTO t1 VALUES(3, 4);
+  INSERT INTO t1 VALUES(5, 6);
+  PRAGMA writable_schema = 1;
+  UPDATE sqlite_master SET sql = '-- ' || sql WHERE type = 'index';
+} {}
+
+db close
+sqlite3 db test.db
+do_execsql_test e_reindex-1.2 {
+  DELETE FROM t1 WHERE a = 3;
+  INSERT INTO t1 VALUES(7, 8);
+  INSERT INTO t1 VALUES(9, 10);
+  PRAGMA writable_schema = 1;
+  UPDATE sqlite_master SET sql = substr(sql, 4) WHERE type = 'index';
+} {}
+
+db close
+sqlite3 db test.db
+do_execsql_test e_reindex-1.3 {
+  PRAGMA integrity_check;
+} [list \
+  {rowid 4 missing from index i2} \
+  {rowid 4 missing from index i1} \
+  {rowid 5 missing from index i2} \
+  {rowid 5 missing from index i1} \
+  {wrong # of entries in index i2} \
+  {wrong # of entries in index i1}
+]
+
+do_execsql_test e_reindex-1.4 {
+  REINDEX;
+  PRAGMA integrity_check;
+} {ok}
+
+#-------------------------------------------------------------------------
+# The remaining tests in this file focus on testing that the REINDEX 
+# command reindexes the correct subset of the indexes in the database.
+# They all use the following dataset.
+#
+db close
+forcedelete test.db2
+forcedelete test.db
+sqlite3 db test.db
+
+proc sort_by_length {lhs rhs} {
+  set res [expr {[string length $lhs] - [string length $rhs]}]
+  if {$res!=0} {return $res}
+  return [string compare $lhs $rhs]
+}
+array set V {one 1 two 2 three 3 four 4 five 5 six 6 seven 7 eight 8}
+proc sort_by_value {lhs rhs} {
+  global V
+  set res [expr {$V($lhs) - $V(rhs)}]
+  if {$res!=0} {return $res}
+  return [string compare $lhs $rhs]
+}
+
+db collate collA sort_by_length
+db collate collB sort_by_value
+
+set BY(length) {one six two five four eight seven three}
+set BY(value)  {one two three four five six seven eight}
+
+do_execsql_test e_reindex-2.0 {
+  ATTACH 'test.db2' AS aux;
+
+  CREATE TABLE t1(x);
+  CREATE INDEX i1_a ON t1(x COLLATE collA);
+  CREATE INDEX i1_b ON t1(x COLLATE collB);
+  INSERT INTO t1 VALUES('one');
+  INSERT INTO t1 VALUES('two');
+  INSERT INTO t1 VALUES('three');
+  INSERT INTO t1 VALUES('four');
+  INSERT INTO t1 VALUES('five');
+  INSERT INTO t1 VALUES('six');
+  INSERT INTO t1 VALUES('seven');
+  INSERT INTO t1 VALUES('eight');
+
+  CREATE TABLE t2(x);
+  CREATE INDEX i2_a ON t2(x COLLATE collA);
+  CREATE INDEX i2_b ON t2(x COLLATE collB);
+  INSERT INTO t2 SELECT x FROM t1;
+
+  CREATE TABLE aux.t1(x);
+  CREATE INDEX aux.i1_a ON t1(x COLLATE collA);
+  CREATE INDEX aux.i1_b ON t1(x COLLATE collB);
+  INSERT INTO aux.t1 SELECT x FROM main.t1;
+
+} {}
+
+proc test_index {tn tbl collation expected} {
+  set sql "SELECT x FROM $tbl ORDER BY x COLLATE $collation"
+  uplevel do_execsql_test e_reindex-2.$tn [list $sql] [list $::BY($expected)]
+}
+
+proc set_collations {a b} {
+  db collate collA "sort_by_$a"
+  db collate collB "sort_by_$b"
+}
+
+test_index 1.1   t1     collA   length
+test_index 1.2   t1     collB   value
+test_index 1.3   t2     collA   length
+test_index 1.4   t2     collB   value
+test_index 1.5   aux.t1 collA   length
+test_index 1.6   aux.t1 collB   value
+
+
+# EVIDENCE-OF: R-47362-07898 If the REINDEX keyword is not followed by a
+# collation-sequence or database object identifier, then all indices in
+# all attached databases are rebuilt.
+#
+set_collations value length
+do_execsql_test e_reindex-2.2.1 "REINDEX" {}
+test_index 2.2   t1     collA   value
+test_index 2.3   t1     collB   length
+test_index 2.4   t2     collA   value
+test_index 2.5   t2     collB   length
+test_index 2.6   aux.t1 collA   value
+test_index 2.7   aux.t1 collB   length
+
+# EVIDENCE-OF: R-45878-07697 If the REINDEX keyword is followed by a
+# collation-sequence name, then all indices in all attached databases
+# that use the named collation sequences are recreated.
+#
+set_collations length value
+do_execsql_test e_reindex-2.3.1 "REINDEX collA" {}
+test_index 3.2   t1     collA   length
+test_index 3.3   t1     collB   length
+test_index 3.4   t2     collA   length
+test_index 3.5   t2     collB   length
+test_index 3.6   aux.t1 collA   length
+test_index 3.7   aux.t1 collB   length
+do_execsql_test e_reindex-2.3.8 "REINDEX collB" {}
+test_index 3.9   t1     collA   length
+test_index 3.10  t1     collB   value
+test_index 3.11  t2     collA   length
+test_index 3.12  t2     collB   value
+test_index 3.13  aux.t1 collA   length
+test_index 3.14  aux.t1 collB   value
+
+# EVIDENCE-OF: R-49616-30196 Or, if the argument attached to the REINDEX
+# identifies a specific database table, then all indices attached to the
+# database table are rebuilt.
+#
+set_collations value length
+do_execsql_test e_reindex-2.4.1 "REINDEX t1" {}
+test_index 4.2   t1     collA   value
+test_index 4.3   t1     collB   length
+test_index 4.4   t2     collA   length
+test_index 4.5   t2     collB   value
+test_index 4.6   aux.t1 collA   length
+test_index 4.7   aux.t1 collB   value
+do_execsql_test e_reindex-2.4.8 "REINDEX aux.t1" {}
+test_index 4.9   t1     collA   value
+test_index 4.10  t1     collB   length
+test_index 4.11  t2     collA   length
+test_index 4.12  t2     collB   value
+test_index 4.13  aux.t1 collA   value
+test_index 4.14  aux.t1 collB   length
+do_execsql_test e_reindex-2.4.15 "REINDEX t2" {}
+test_index 4.16  t1     collA   value
+test_index 4.17  t1     collB   length
+test_index 4.18  t2     collA   value
+test_index 4.19  t2     collB   length
+test_index 4.20  aux.t1 collA   value
+test_index 4.21  aux.t1 collB   length
+
+# EVIDENCE-OF: R-58823-28748 If it identifies a specific database index,
+# then just that index is recreated.
+#
+set_collations length value
+do_execsql_test e_reindex-2.5.1 "REINDEX i1_a" {}
+test_index 5.2   t1     collA   length
+test_index 5.3   t1     collB   length
+test_index 5.4   t2     collA   value
+test_index 5.5   t2     collB   length
+test_index 5.6   aux.t1 collA   value
+test_index 5.7   aux.t1 collB   length
+do_execsql_test e_reindex-2.5.8 "REINDEX i2_b" {}
+test_index 5.9   t1     collA   length
+test_index 5.10  t1     collB   length
+test_index 5.11  t2     collA   value
+test_index 5.12  t2     collB   value
+test_index 5.13  aux.t1 collA   value
+test_index 5.14  aux.t1 collB   length
+do_execsql_test e_reindex-2.5.15 "REINDEX aux.i1_b" {}
+test_index 5.16  t1     collA   length
+test_index 5.17  t1     collB   length
+test_index 5.18  t2     collA   value
+test_index 5.19  t2     collB   value
+test_index 5.20  aux.t1 collA   value
+test_index 5.21  aux.t1 collB   value
+do_execsql_test e_reindex-2.5.22 "REINDEX i1_b" {}
+test_index 5.23  t1     collA   length
+test_index 5.24  t1     collB   value
+test_index 5.25  t2     collA   value
+test_index 5.26  t2     collB   value
+test_index 5.27  aux.t1 collA   value
+test_index 5.28  aux.t1 collB   value
+do_execsql_test e_reindex-2.5.29 "REINDEX i2_a" {}
+test_index 5.30  t1     collA   length
+test_index 5.31  t1     collB   value
+test_index 5.32  t2     collA   length
+test_index 5.33  t2     collB   value
+test_index 5.34  aux.t1 collA   value
+test_index 5.35  aux.t1 collB   value
+do_execsql_test e_reindex-2.5.36 "REINDEX aux.i1_a" {}
+test_index 5.37  t1     collA   length
+test_index 5.38  t1     collB   value
+test_index 5.39  t2     collA   length
+test_index 5.40  t2     collB   value
+test_index 5.41  aux.t1 collA   length
+test_index 5.42  aux.t1 collB   value
+
+# EVIDENCE-OF: R-15639-02023 If no database-name is specified and there
+# exists both a table or index and a collation sequence of the specified
+# name, SQLite interprets this as a request to rebuild the indices that
+# use the named collation sequence.
+#
+set_collations value length
+do_execsql_test e_reindex-2.6.0 {
+  CREATE TABLE collA(x);
+  CREATE INDEX icolla_a ON collA(x COLLATE collA);
+  CREATE INDEX icolla_b ON collA(x COLLATE collB);
+
+  INSERT INTO collA SELECT x FROM t1;
+} {}
+
+test_index 6.1   collA  collA   value
+test_index 6.2   collA  collB   length
+
+set_collations length value
+do_execsql_test e_reindex-2.6.3 "REINDEX collA" {}
+test_index 6.4   collA  collA   length
+test_index 6.5   collA  collB   length
+do_execsql_test e_reindex-2.6.3 "REINDEX main.collA" {}
+test_index 6.4   collA  collA   length
+test_index 6.5   collA  collB   value
+
+set_collations value length
+do_execsql_test e_reindex-2.6.6 "REINDEX main.collA" {}
+test_index 6.7   collA  collA   value
+test_index 6.8   collA  collB   length
 
 finish_test