1 # include/query_cache.inc
4 # $engine_type -- storage engine to be tested
5 # $test_foreign_keys -- 0, skip foreign key tests
6 # -- 1, do not skip foreign key tests
7 # $partitions_a -- partition by column 'a'
8 # $partitions_id -- partition by column 'id'
9 # $partitions_s1 -- partition by column 's1'
10 # have to be set before sourcing this script.
13 # 2006-08-02 ML test refactored
14 # old name was innodb_cache.test
15 # main code went into include/query_cache.inc
18 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
22 drop
table if exists t1,t2,t3;
25 set @save_query_cache_size = @@global.query_cache_size;
26 set GLOBAL query_cache_size = 1355776;
29 # Without auto_commit.
33 eval create
table t1 (a
int not null)$partitions_a;
34 insert into t1 values (1),(2),(3);
37 show status like
"Qcache_queries_in_cache";
42 eval create
table t1 (a
int not null)$partitions_a;
43 insert into t1 values (1),(2),(3);
46 show status like
"Qcache_queries_in_cache";
49 eval create
table t1 (a
int not null)$partitions_a;
50 eval create
table t2 (a
int not null)$partitions_a;
51 eval create
table t3 (a
int not null)$partitions_a;
52 insert into t1 values (1),(2);
53 insert into t2 values (1),(2);
54 insert into t3 values (1),(2);
61 show status like
"Qcache_queries_in_cache";
62 show status like
"Qcache_hits";
70 show status like
"Qcache_queries_in_cache";
71 show status like
"Qcache_hits";
72 insert into t1 values (3);
73 insert into t2 values (3);
74 insert into t1 values (4);
81 show status like
"Qcache_queries_in_cache";
82 show status like
"Qcache_hits";
84 show status like
"Qcache_queries_in_cache";
87 eval CREATE
TABLE t1 (
id int(11) NOT NULL auto_increment, PRIMARY
KEY (
id))$partitions_id;
88 select count(*) from t1;
89 insert into t1 (
id) values (0);
90 select count(*) from t1;
93 if ($test_foreign_keys)
96 # one statement roll back inside transation
98 CREATE
TABLE t1 (
id int(10) NOT NULL auto_increment, a varchar(25)
default NULL, PRIMARY
KEY (
id), UNIQUE
KEY a (a));
99 CREATE
TABLE t2 (
id int(10) NOT NULL auto_increment, b varchar(25)
default NULL, PRIMARY
KEY (
id), UNIQUE
KEY b (b));
100 CREATE
TABLE t3 (
id int(10) NOT NULL auto_increment, t1_id
int(10) NOT NULL
default '0', t2_id
int(10) NOT NULL
default '0', state
int(11)
default NULL, PRIMARY
KEY (
id), UNIQUE
KEY t1_id (t1_id,t2_id),
KEY t2_id (t2_id,t1_id), CONSTRAINT `t3_ibfk_1` FOREIGN
KEY (`t1_id`) REFERENCES `t1` (`
id`), CONSTRAINT `t3_ibfk_2` FOREIGN
KEY (`t2_id`) REFERENCES `t2` (`
id`));
101 INSERT INTO t1 VALUES (1,
'me');
102 INSERT INTO t2 VALUES (1,
'you');
103 INSERT INTO t3 VALUES (2,1,1,2);
104 delete from t3 where t1_id = 1 and t2_id = 1;
105 select t1.* from t1, t2, t3 where t3.state & 1 = 0 and t3.t1_id = t1.id and t3.t2_id = t2.id and t1.id = 1 order by t1.a asc;
107 insert into t3 VALUES ( NULL, 1, 1, 2 );
108 -- error ER_DUP_ENTRY
109 insert into t3 VALUES ( NULL, 1, 1, 2 );
111 select t1.* from t1, t2, t3 where t3.state & 1 = 0 and t3.t1_id = t1.id and t3.t2_id = t2.id and t1.id = 1 order by t1.a asc;
116 # Test query cache with two interleaving transactions
119 # Establish connection1
120 connect (connection1,localhost,root,,);
121 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
125 --echo connection
default
126 # This should be 'YES'.
127 SHOW VARIABLES LIKE
'have_query_cache';
129 SET GLOBAL query_cache_size = 204800;
132 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
133 eval CREATE
TABLE t2 (s1
int, s2 varchar(1000), key(s1))$partitions_s1;
134 INSERT INTO t2 VALUES (1,repeat('a',10)),(2,repeat('a',10)),(3,repeat('a',10)),(4,repeat('a',10));
137 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
138 UPDATE t2 SET s2 = 'w' WHERE s1 = 3;
139 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
140 show status like "Qcache_queries_in_cache";
142 connection connection1;
143 --echo connection connection1
145 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
146 INSERT INTO t2 VALUES (5,'w');
147 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
149 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
151 show status like "Qcache_queries_in_cache";
154 --echo connection default
155 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
158 show status like "Qcache_queries_in_cache";
160 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
161 show status like "Qcache_queries_in_cache";
163 connection connection1;
164 --echo connection connection1
165 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
168 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
169 INSERT INTO t2 VALUES (6,'w');
170 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
173 --echo connection default
174 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
176 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
177 DELETE from t2 WHERE s1=3;
178 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
181 connection connection1;
182 --echo connection connection1
185 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
187 show status like "Qcache_queries_in_cache";
188 show status like "Qcache_hits";
191 disconnect connection1;
192 --source include/wait_until_disconnected.inc
194 set @@global.query_cache_size = @save_query_cache_size;