xref: /sqlite-3.40.0/test/index4.test (revision f9c8ce3c)
1a20fde64Sdan# 2011 July 9
2a20fde64Sdan#
3a20fde64Sdan# The author disclaims copyright to this source code.  In place of
4a20fde64Sdan# a legal notice, here is a blessing:
5a20fde64Sdan#
6a20fde64Sdan#    May you do good and not evil.
7a20fde64Sdan#    May you find forgiveness for yourself and forgive others.
8a20fde64Sdan#    May you share freely, never taking more than you give.
9a20fde64Sdan#
10a20fde64Sdan#***********************************************************************
11a20fde64Sdan# This file implements regression tests for SQLite library.  The
12a20fde64Sdan# focus of this file is testing the CREATE INDEX statement.
13a20fde64Sdan#
14a20fde64Sdan
15a20fde64Sdanset testdir [file dirname $argv0]
16a20fde64Sdansource $testdir/tester.tcl
17a20fde64Sdan
18a20fde64Sdanset testprefix index4
19a20fde64Sdan
20a20fde64Sdando_execsql_test 1.1 {
21a20fde64Sdan  BEGIN;
22a20fde64Sdan    CREATE TABLE t1(x);
23a20fde64Sdan    INSERT INTO t1 VALUES(randomblob(102));
24a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --     2
25a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --     4
26a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --     8
27a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --    16
28a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --    32
29a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --    64
30a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --   128
31a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --   256
32a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --   512
33a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --  1024
34a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --  2048
35a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --  4096
36a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     --  8192
37a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     -- 16384
38a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     -- 32768
39a20fde64Sdan    INSERT INTO t1 SELECT randomblob(102) FROM t1;     -- 65536
40a20fde64Sdan  COMMIT;
41a20fde64Sdan}
42a20fde64Sdan
43a20fde64Sdando_execsql_test 1.2 {
44a20fde64Sdan  CREATE INDEX i1 ON t1(x);
45a20fde64Sdan}
46a20fde64Sdando_execsql_test 1.3 {
47a20fde64Sdan  PRAGMA integrity_check
48a20fde64Sdan} {ok}
49a20fde64Sdan
50a20fde64Sdan# The same test again - this time with limited memory.
51a20fde64Sdan#
52a20fde64Sdanifcapable memorymanage {
53a20fde64Sdan  set soft_limit [sqlite3_soft_heap_limit 50000]
54a20fde64Sdan
55a20fde64Sdan  db close
56a20fde64Sdan  sqlite3 db test.db
57a20fde64Sdan
58a20fde64Sdan  do_execsql_test 1.4 {
59a20fde64Sdan    PRAGMA cache_size = 10;
60a20fde64Sdan    CREATE INDEX i2 ON t1(x);
61a20fde64Sdan  }
62a20fde64Sdan  do_execsql_test 1.5 {
63a20fde64Sdan    PRAGMA integrity_check
64a20fde64Sdan  } {ok}
65a20fde64Sdan
66a20fde64Sdan  sqlite3_soft_heap_limit $soft_limit
67a20fde64Sdan}
68a20fde64Sdan
69a20fde64Sdan
705279112eSdando_execsql_test 1.6 {
715279112eSdan  BEGIN;
725279112eSdan    DROP TABLE t1;
735279112eSdan    CREATE TABLE t1(x);
745279112eSdan    INSERT INTO t1 VALUES('a');
755279112eSdan    INSERT INTO t1 VALUES('b');
765279112eSdan    INSERT INTO t1 VALUES('c');
775279112eSdan    INSERT INTO t1 VALUES('d');
785279112eSdan    INSERT INTO t1 VALUES('e');
795279112eSdan    INSERT INTO t1 VALUES('f');
805279112eSdan    INSERT INTO t1 VALUES('g');
815279112eSdan    INSERT INTO t1 VALUES(NULL);
825279112eSdan    INSERT INTO t1 SELECT randomblob(1202) FROM t1;     --    16
835279112eSdan    INSERT INTO t1 SELECT randomblob(2202) FROM t1;     --    32
845279112eSdan    INSERT INTO t1 SELECT randomblob(3202) FROM t1;     --    64
855279112eSdan    INSERT INTO t1 SELECT randomblob(4202) FROM t1;     --   128
865279112eSdan    INSERT INTO t1 SELECT randomblob(5202) FROM t1;     --   256
875279112eSdan  COMMIT;
885279112eSdan  CREATE INDEX i1 ON t1(x);
895279112eSdan  PRAGMA integrity_check
905279112eSdan} {ok}
915279112eSdan
925279112eSdando_execsql_test 1.7 {
935279112eSdan  BEGIN;
945279112eSdan    DROP TABLE t1;
955279112eSdan    CREATE TABLE t1(x);
965279112eSdan    INSERT INTO t1 VALUES('a');
975279112eSdan  COMMIT;
985279112eSdan  CREATE INDEX i1 ON t1(x);
995279112eSdan  PRAGMA integrity_check
1005279112eSdan} {ok}
1015279112eSdan
1025279112eSdando_execsql_test 1.8 {
1035279112eSdan  BEGIN;
1045279112eSdan    DROP TABLE t1;
1055279112eSdan    CREATE TABLE t1(x);
1065279112eSdan  COMMIT;
1075279112eSdan  CREATE INDEX i1 ON t1(x);
1085279112eSdan  PRAGMA integrity_check
1095279112eSdan} {ok}
1105279112eSdan
1115134d135Sdando_execsql_test 2.1 {
1125134d135Sdan  BEGIN;
1135134d135Sdan    CREATE TABLE t2(x);
1145134d135Sdan    INSERT INTO t2 VALUES(14);
1155134d135Sdan    INSERT INTO t2 VALUES(35);
1165134d135Sdan    INSERT INTO t2 VALUES(15);
1175134d135Sdan    INSERT INTO t2 VALUES(35);
1185134d135Sdan    INSERT INTO t2 VALUES(16);
1195134d135Sdan  COMMIT;
1205134d135Sdan}
1215134d135Sdando_catchsql_test 2.2 {
1225134d135Sdan  CREATE UNIQUE INDEX i3 ON t2(x);
123*f9c8ce3cSdrh} {1 {UNIQUE constraint failed: t2.x}}
1245134d135Sdan
1255279112eSdan
126a20fde64Sdanfinish_test
127