1
# query cache is local to each mysqld, so counting hits
2
# will not be the same when using one and several mysqld's
3
# hence disable test for embedded
4
-- source include/not_embedded.inc
5
-- source include/have_query_cache.inc
6
-- source include/have_multi_ndb.inc
9
drop table if exists t1, t2;
13
# Turn on and reset query cache on server1
15
echo == Connected to server1 ==;
16
set GLOBAL query_cache_type=on;
17
set GLOBAL query_cache_size=1355776;
18
set GLOBAL ndb_cache_check_time=1;
22
# Turn on and reset query cache on server2
24
echo == Connected to server2 ==;
25
set GLOBAL query_cache_type=on;
26
set GLOBAL query_cache_size=1355776;
27
set GLOBAL ndb_cache_check_time=1;
31
# Create test tables in NDB and load them into cache
34
echo == Connected to server1 ==;
35
create table t1 (a int) engine=ndbcluster;
36
create table t2 (a int) engine=ndbcluster;
37
insert into t1 value (2);
38
insert into t2 value (3);
40
# Run the check query once to load it into qc on server1
41
# See at the end of this test why we need to disable ps-protocol for
44
select a != 3 from t1;
47
show status like "Qcache_queries_in_cache";
48
show status like "Qcache_inserts";
49
show status like "Qcache_hits";
52
# Connect server2, load table in to cache, then update the table
54
echo == Connected to server2 ==;
55
show status like "Qcache_queries_in_cache";
56
show status like "Qcache_inserts";
57
show status like "Qcache_hits";
59
show status like "Qcache_queries_in_cache";
60
show status like "Qcache_inserts";
61
show status like "Qcache_hits";
62
update t1 set a=3 where a=2;
64
# Connect to server1 and check that cache is invalidated
65
# and correct data is returned
67
echo == Connected to server1 ==;
69
# Loop and wait for max 10 seconds until query cache thread
70
# has invalidated the cache and the column a in t1 is equal to 3
72
while (`select a != 3 from t1`)
77
The query_cache thread failed to invalidate query_cache in 10 seconds;
82
# Select from t1 one last time for the result file
83
# Column a should be 3
86
# There should now be three queries in the cache
87
show status like "Qcache_queries_in_cache";
91
# Turn off and reset query cache on server1 and server2
93
set GLOBAL query_cache_size=0;
94
set GLOBAL ndb_cache_check_time=0;
98
set GLOBAL query_cache_size=0;
99
set GLOBAL ndb_cache_check_time=0;
103
# (*) Why we need to execute the query in non-ps mode.
104
# The principle of this test is: two mysqlds connected to one cluster,
105
# both using their query cache. Queries are cached in server1
106
# ("select a!=3 from t1", "select * from t1"),
107
# table t1 is modified in server2, we want to see that this invalidates
108
# the query cache of server1. Invalidation with NDB works like this:
109
# when a query is found in the query cache, NDB is asked if the tables
110
# have changed. In this test, ha_ndbcluster calls NDB every millisecond
111
# to collect change information about tables.
112
# Due to this millisecond delay, there is need for a loop ("while...")
113
# in this test, which waits until a query1 ("select a!=3 from t1") is
114
# invalidated (which is equivalent to it returning
115
# up-to-date results), and then expects query2 ("select * from t1")
116
# to have been invalidated (see up-to-date results).
117
# But when enabling --ps-protocol in this test, the logic breaks,
118
# because query1 is still done via mysql_real_query() (see mysqltest.c:
119
# eval_expr() always uses mysql_real_query()). So, query1 returning
120
# up-to-date results is not a sign of it being invalidated in the cache,
121
# because it was NOT in the cache ("select a!=3 from t1" on line 39
122
# was done with prep stmts, while `select a!=3 from t1` is not,
123
# thus the second does not see the first in the cache). Thus, we may run
124
# query2 when cache still has not been invalidated.
125
# The solution is to make the initial "select a!=3 from t1" run
126
# as a normal query, this repairs the broken logic.
127
# But note, "select * from t1" is still using prepared statements
128
# which was the goal of this test with --ps-protocol.