MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
query_cache.inc
1 # include/query_cache.inc
2 #
3 # The variables
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.
11 #
12 # Last update:
13 # 2006-08-02 ML test refactored
14 # old name was innodb_cache.test
15 # main code went into include/query_cache.inc
16 #
17 
18 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
19 
20 # Initialise
21 --disable_warnings
22 drop table if exists t1,t2,t3;
23 --enable_warnings
24 
25 set @save_query_cache_size = @@global.query_cache_size;
26 set GLOBAL query_cache_size = 1355776;
27 
28 #
29 # Without auto_commit.
30 #
31 flush status;
32 set autocommit=0;
33 eval create table t1 (a int not null)$partitions_a;
34 insert into t1 values (1),(2),(3);
35 --sorted_result
36 select * from t1;
37 show status like "Qcache_queries_in_cache";
38 drop table t1;
39 commit;
40 set autocommit=1;
41 begin;
42 eval create table t1 (a int not null)$partitions_a;
43 insert into t1 values (1),(2),(3);
44 --sorted_result
45 select * from t1;
46 show status like "Qcache_queries_in_cache";
47 drop table t1;
48 commit;
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);
55 --sorted_result
56 select * from t1;
57 --sorted_result
58 select * from t2;
59 --sorted_result
60 select * from t3;
61 show status like "Qcache_queries_in_cache";
62 show status like "Qcache_hits";
63 begin;
64 --sorted_result
65 select * from t1;
66 --sorted_result
67 select * from t2;
68 --sorted_result
69 select * from t3;
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);
75 --sorted_result
76 select * from t1;
77 --sorted_result
78 select * from t2;
79 --sorted_result
80 select * from t3;
81 show status like "Qcache_queries_in_cache";
82 show status like "Qcache_hits";
83 commit;
84 show status like "Qcache_queries_in_cache";
85 drop table t3,t2,t1;
86 
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;
91 drop table t1;
92 
93 if ($test_foreign_keys)
94 {
95 #
96 # one statement roll back inside transation
97 #
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;
106 begin;
107 insert into t3 VALUES ( NULL, 1, 1, 2 );
108 -- error ER_DUP_ENTRY
109 insert into t3 VALUES ( NULL, 1, 1, 2 );
110 commit;
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;
112 drop table t3,t2,t1;
113 }
114 
115 #
116 # Test query cache with two interleaving transactions
117 #
118 
119 # Establish connection1
120 connect (connection1,localhost,root,,);
121 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
122 SET @@autocommit=1;
123 
124 connection default;
125 --echo connection default
126 # This should be 'YES'.
127 SHOW VARIABLES LIKE 'have_query_cache';
128 
129 SET GLOBAL query_cache_size = 204800;
130 flush status;
131 SET @@autocommit=1;
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));
135 COMMIT;
136 START TRANSACTION;
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";
141 
142 connection connection1;
143 --echo connection connection1
144 START TRANSACTION;
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';
148 COMMIT;
149 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
150 
151 show status like "Qcache_queries_in_cache";
152 
153 connection default;
154 --echo connection default
155 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
156 COMMIT;
157 
158 show status like "Qcache_queries_in_cache";
159 
160 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
161 show status like "Qcache_queries_in_cache";
162 
163 connection connection1;
164 --echo connection connection1
165 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
166 
167 START TRANSACTION;
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';
171 
172 connection default;
173 --echo connection default
174 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
175 START TRANSACTION;
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';
179 COMMIT;
180 
181 connection connection1;
182 --echo connection connection1
183 
184 COMMIT;
185 SELECT sql_cache count(*) FROM t2 WHERE s2 = 'w';
186 
187 show status like "Qcache_queries_in_cache";
188 show status like "Qcache_hits";
189 
190 # Final cleanup
191 disconnect connection1;
192 --source include/wait_until_disconnected.inc
193 connection default;
194 set @@global.query_cache_size = @save_query_cache_size;
195 drop table t2;