1 ### t/query_cache_28249.test ###
4 # Bug#28249 Query Cache returns wrong result with concurrent insert / certain lock
7 # 2008-11-27 mleich - Move this test out of query_cache.test
8 # - Fix Bug#40179 Test main.query_cache failing randomly on Pushbuild,
10 # - Minor improvements (comments,formatting etc.)
13 --source include/have_query_cache.inc
14 --source include/not_embedded.inc
16 SET @query_cache_type= @@global.query_cache_type;
17 SET @query_cache_limit= @@global.query_cache_limit;
18 SET @query_cache_min_res_unit= @@global.query_cache_min_res_unit;
19 SET @query_cache_size= @@global.query_cache_size;
21 --echo # Bug#28249 Query Cache returns wrong result with concurrent insert/ certain lock
22 --echo # Establish connections user1,user2,user3 (user=root)
23 connect (user1,localhost,root,,test,,);
24 connect (user2,localhost,root,,test,,);
25 connect (user3,localhost,root,,test,,);
27 --echo # Switch to connection user1
30 SET GLOBAL query_cache_type=1;
31 SET GLOBAL query_cache_limit=10000;
32 SET GLOBAL query_cache_min_res_unit=0;
33 SET GLOBAL query_cache_size= 100000;
37 DROP TABLE IF EXISTS t1, t2;
39 CREATE TABLE t1 (a INT);
40 CREATE TABLE t2 (a INT);
41 INSERT INTO t1 VALUES (1),(2),(3);
43 --echo # Switch to connection user2
47 --echo # Switch to connection user1
49 --echo # "send" the next select, "reap" the result later.
50 --echo # The select will be blocked by the write lock on the t1.
52 SELECT *, (SELECT COUNT(*) FROM t2) FROM t1;
56 --echo # Switch to connection user3
58 # Typical information_schema.processlist content after sufficient sleep time
59 # ID USER COMMAND TIME STATE INFO
61 # 2 root Query 5 Locked SELECT *, (SELECT COUNT(*) FROM t2) FROM t1
63 # XXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
64 # The values marked with 'X' must be reached.
65 --echo # Poll till the select of connection user1 is blocked by the write lock on t1.
66 let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist
67 WHERE state = 'Locked'
68 AND info = '$select_for_qc';
69 --source include/wait_condition.inc
71 SELECT user,command,state,info FROM information_schema.processlist
72 WHERE state = 'Locked'
73 AND info = '$select_for_qc';
74 INSERT INTO t1 VALUES (4);
76 --echo # Switch to connection user2
80 --echo # Switch to connection user1
83 # Since the lock ordering rule in thr_multi_lock depends on
84 # pointer values, from execution to execution we might have
85 # different lock order, and therefore, sometimes lock t1 and block
86 # on t2, and sometimes block on t2 right away. In the second case,
87 # the following insert succeeds, and only then this select can
88 # proceed, and we actually test nothing, as the very first select
89 # returns 4 rows right away.
90 # It's fine to have a test case that covers the problematic area
91 # at least once in a while.
92 --echo # Collecting ("reap") the result from the previously blocked select.
93 --echo # The printing of the result (varies between 3 and 4 rows) set has to be suppressed.
98 --echo # Switch to connection user3
100 --echo # The next select enforces that effects of "concurrent_inserts" like the
101 --echo # record with a = 4 is missing in result sets can no more happen.
102 SELECT 1 FROM t1 WHERE a = 4;
104 --echo # Switch to connection user1
106 --echo # The next result set must contain 4 rows.
107 # If not, we have a regression of Bug#28249
114 --echo # Switch to connection default + close connections user1,user2,user3
120 SET GLOBAL query_cache_type= @query_cache_type;
121 SET GLOBAL query_cache_limit= @query_cache_limit;
122 SET GLOBAL query_cache_min_res_unit= @query_cache_min_res_unit;
123 SET GLOBAL query_cache_size= @query_cache_size;