1 /*
2 ** 2014 December 9
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
10 **
11 *************************************************************************
12 **
13 ** create_drop_index_1
14 */
15
16
create_drop_index_thread(int iTid,void * pArg)17 static char *create_drop_index_thread(int iTid, void *pArg){
18 Error err = {0}; /* Error code and message */
19 Sqlite db = {0}; /* SQLite database connection */
20
21 while( !timetostop(&err) ){
22 opendb(&err, &db, "test.db", 0);
23
24 sql_script(&err, &db,
25 "DROP INDEX IF EXISTS i1;"
26 "DROP INDEX IF EXISTS i2;"
27 "DROP INDEX IF EXISTS i3;"
28 "DROP INDEX IF EXISTS i4;"
29
30 "CREATE INDEX IF NOT EXISTS i1 ON t11(a);"
31 "CREATE INDEX IF NOT EXISTS i2 ON t11(b);"
32 "CREATE INDEX IF NOT EXISTS i3 ON t11(c);"
33 "CREATE INDEX IF NOT EXISTS i4 ON t11(d);"
34
35 "SELECT * FROM t11 ORDER BY a;"
36 "SELECT * FROM t11 ORDER BY b;"
37 "SELECT * FROM t11 ORDER BY c;"
38 "SELECT * FROM t11 ORDER BY d;"
39 );
40 clear_error(&err, SQLITE_LOCKED);
41
42 closedb(&err, &db);
43 }
44
45 print_and_free_err(&err);
46 return sqlite3_mprintf("ok");
47 }
48
create_drop_index_1(int nMs)49 static void create_drop_index_1(int nMs){
50 Error err = {0};
51 Sqlite db = {0};
52 Threadset threads = {0};
53
54 opendb(&err, &db, "test.db", 1);
55 sql_script(&err, &db,
56 "CREATE TABLE t11(a, b, c, d);"
57 "WITH data(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM data WHERE x<100) "
58 "INSERT INTO t11 SELECT x,x,x,x FROM data;"
59 );
60 closedb(&err, &db);
61
62 setstoptime(&err, nMs);
63
64 sqlite3_enable_shared_cache(1);
65 launch_thread(&err, &threads, create_drop_index_thread, 0);
66 launch_thread(&err, &threads, create_drop_index_thread, 0);
67 launch_thread(&err, &threads, create_drop_index_thread, 0);
68 launch_thread(&err, &threads, create_drop_index_thread, 0);
69 launch_thread(&err, &threads, create_drop_index_thread, 0);
70
71 join_all_threads(&err, &threads);
72 sqlite3_enable_shared_cache(0);
73 print_and_free_err(&err);
74 }
75