1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
-- source include/have_query_cache.inc
-- source include/have_ndb.inc
-- source include/not_embedded.inc
--result_format 2
--disable_warnings
drop table if exists t1;
--enable_warnings
# Turn on and reset query cache
set GLOBAL query_cache_type=on;
set GLOBAL query_cache_size=1355776;
reset query cache;
flush status;
## Turn off autocommit, instead use COMMIT after each statement
set AUTOCOMMIT=off;
## Create test table in NDB
CREATE TABLE t1 (
pk int not null primary key,
a int,
b int not null,
c varchar(20)
) ENGINE=ndbcluster;
## Add first row
insert into t1 value (1, 2, 3, 'First row');
COMMIT;
## Query should be inserted in qcache
--source include/show_qc_status.inc
select * from t1;
--source include/show_qc_status.inc
COMMIT;
--source include/show_qc_status.inc
## Perform the same query and make sure the query cache is hit
--source include/show_qc_status.inc
select * from t1;
COMMIT;
--source include/show_qc_status.inc
## Update the table, should be no queries in cache afterwards
update t1 set a=3 where pk=1;
COMMIT;
--source include/show_qc_status.inc
## Read row after update, should not hit the cache, but get inserted
select * from t1;
COMMIT;
--source include/show_qc_status.inc
## Read row from cache
select * from t1;
COMMIT;
--source include/show_qc_status.inc
## Insert two new rows, queries in cache should be zero
insert into t1 value (2, 7, 8, 'Second row');
insert into t1 value (4, 5, 6, 'Fourth row');
COMMIT;
--source include/show_qc_status.inc
## Read the three rows, should not hit the cache
select * from t1 order by pk;
COMMIT;
--source include/show_qc_status.inc
## Read the three rows, should now hit the cache!
select * from t1 order by pk;
COMMIT;
--source include/show_qc_status.inc
## Two selects in the same transaction should hit cache
select * from t1 order by pk;
select * from t1 order by pk;
COMMIT;
--source include/show_qc_status.inc
## Perform a "new" query and make sure the query cache is not hit
select * from t1 where b=3;
COMMIT;
--source include/show_qc_status.inc
## Same query again...
select * from t1 where b=3;
COMMIT;
--source include/show_qc_status.inc
## Delete from the table, should clear the cache
delete from t1 where c='Fourth row';
COMMIT;
--source include/show_qc_status.inc
select * from t1 where b=3;
COMMIT;
--source include/show_qc_status.inc
## Start another connection and check that the query cache is hit
connect (con1,localhost,root,,);
connection con1;
set AUTOCOMMIT=off;
use test;
select * from t1 order by pk;
select * from t1 where b=3;
--source include/show_qc_status.inc
## Update the table and switch to other connection
update t1 set a=4 where b=3;
COMMIT;
## Connection 2
connect (con2,localhost,root,,);
connection con2;
set AUTOCOMMIT=off;
use test;
## Should not hit cache, table updated
--source include/show_qc_status.inc
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Should hit cache
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Connection 1, should hit the cache
connection con1;
--source include/show_qc_status.inc
select * from t1 order by pk desc;
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Starting transaction and update t1
begin;
update t1 set a=5 where pk=1;
--source include/show_qc_status.inc
## Connection 2
connection con2;
## Update has flushed the qc for t1, should not hit qc
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Connection 1
connection con1;
commit;
--source include/show_qc_status.inc
## Connection 2
connection con2;
## Update is now committed, should not hit the cache
select * from t1 order by pk desc;
--source include/show_qc_status.inc
COMMIT;
--source include/show_qc_status.inc
## Connection 1
connection con1;
## Should hit the cache
select * from t1 order by pk desc;
--source include/show_qc_status.inc
update t1 set a=6 where pk=1;
## Following query should not be taken from cache, trans is ongoing
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Connection 2 should still see old data and not hit cache
connection con2;
--source include/show_qc_status.inc
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Connection 1
connection con1;
COMMIT;
## Update has just been committed, should not hit cache
--source include/show_qc_status.inc
select * from t1 order by pk desc;
--source include/show_qc_status.inc
## Connection 2
connection con2;
## Should hit cache
--source include/show_qc_status.inc
select * from t1 order by pk desc;
--source include/show_qc_status.inc
drop table t1;
## Finally, there should be no queries in cache
--source include/show_qc_status.inc
SET GLOBAL query_cache_size=0;
|