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