File: ndb_cache.test

package info (click to toggle)
percona-xtrabackup 2.2.3-2.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 293,260 kB
  • ctags: 146,881
  • sloc: cpp: 1,051,960; ansic: 570,217; java: 54,595; perl: 53,495; pascal: 44,194; sh: 27,826; yacc: 15,314; python: 12,142; xml: 7,848; sql: 4,125; makefile: 1,459; awk: 785; lex: 758
file content (283 lines) | stat: -rw-r--r-- 8,110 bytes parent folder | download
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
-- source include/have_query_cache.inc
-- source include/have_ndb.inc

--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;

# 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;
insert into t1 value (1, 2, 3, 'First row');

# Perform one query which should be inerted in query cache
select * from t1;
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";

# Perform the same query and make sure the query cache is hit
select * from t1;
show status like "Qcache_hits";

# Update the table and make sure the correct data is returned
update t1 set a=3 where pk=1;
select * from t1;
show status like "Qcache_inserts";
show status like "Qcache_hits";

# Insert a new record and make sure the correct data is returned
insert into t1 value (2, 7, 8, 'Second row');
insert into t1 value (4, 5, 6, 'Fourth row');
select * from t1 order by pk;
show status like "Qcache_inserts";
show status like "Qcache_hits";
select * from t1 order by pk;
show status like "Qcache_hits";

# Perform a "new" query and make sure the query cache is not hit
select * from t1 where b=3;
show status like "Qcache_queries_in_cache";
show status like "Qcache_hits";

# Same query again...
select * from t1 where b=3;
show status like "Qcache_hits";

# Delete from the table
delete from t1 where c='Fourth row';
show status like "Qcache_queries_in_cache";
select * from t1 where b=3;
show status like "Qcache_hits";

# Start another connection and check that the query cache is hit
connect (con1,localhost,root,,);
connection con1;
use test;
select * from t1 order by pk;
select * from t1 where b=3;
show status like "Qcache_hits";

# Update the table and switch to other connection 
update t1 set a=4 where b=3;
connect (con2,localhost,root,,);
connection con2;
use test;
show status like "Qcache_queries_in_cache";
select * from t1 order by pk desc;
select * from t1 order by pk desc;
show status like "Qcache_inserts";
show status like "Qcache_hits";
connection con1;
select * from t1 order by pk desc;
select * from t1 order by pk desc;
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";

# Use transactions and make sure the query cache is not updated until
# transaction is commited
begin;
update t1 set a=5 where pk=1;
# Note!! the below test shows that table is invalidated 
# before transaction is committed
# TODO Fix so that cache is not invalidated HERE!
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
connection con2;
select * from t1 order by pk desc;
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
connection con1;
commit;
# TODO Here query is invalidated once again, commit count in NDB has changed
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
connection con2;
select * from t1 order by pk desc;
show status like "Qcache_inserts";
show status like "Qcache_hits";
connection con1;
select * from t1 order by pk desc;
show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";

drop table t1;

show status like "Qcache_queries_in_cache";

# End of 4.1 tests

# Bug#39295 cluster table with TEXT column cannot be cached in query cache
# Disk table scans and Ordered index scans with locks were resulting
# in the table's commit_count being incremented, making the query cache
# ineffective 

reset query cache;
flush status;

create table t1 (a int primary key,
                 b text,
                 c int,
                 key(c))
                 engine=ndb;

insert into t1 values (1,'Alexandra', 1), (2,'Palace', 2);

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# Normal, ACC sourced scan #1, should insert in cache
select * from t1 order by a;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# Normal, ACC sourced scan #2, should hit in cache
select * from t1 order by a;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# TUX sourced scan #1, should insert in cache
select * from t1 force index(c) where c < 2 order by c;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# TUX sourced scan #2, should hit in cache
select * from t1 force index(c) where c < 2 order by c;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

drop table t1;


# Now test with TUP-sourced scan with DD
CREATE LOGFILE GROUP lfg
ADD UNDOFILE 'myundo.log'
INITIAL_SIZE 16M
UNDO_BUFFER_SIZE = 1M
ENGINE=NDB;

CREATE TABLESPACE tbsp
ADD DATAFILE 'mydatafile.fil'
USE LOGFILE GROUP lfg
INITIAL_SIZE 12M
ENGINE=NDB;

create table t1 (a int primary key,
                 b text,
                 c int,
                 key(c))
                 storage disk tablespace tbsp engine ndb;

insert into t1 values (1,'Alexandra', 1), (2,'Palace', 2);

reset query cache;
flush status;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# Normal, TUP sourced scan #1, should insert in cache
select * from t1 order by a;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# Normal, TUP sourced scan #2, should hit in cache
select * from t1 order by a;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# TUX sourced scan #1 should insert in cache
select * from t1 force index (c) where c < 2 order by c;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

# TUX sourced scan #2 should hit in cache
select * from t1 force index (c) where c < 2 order by c;

show status like "Qcache_queries_in_cache";
show status like "Qcache_inserts";
show status like "Qcache_hits";
show status like "Qcache_not_cached";

drop table t1;
alter tablespace tbsp drop datafile 'mydatafile.fil' engine ndb;
drop tablespace tbsp engine ndb;
drop logfile group lfg engine ndb;

# end of tests for bug#39395

# bug#33158
# bug#33158 NDB table name problem(sensitive/insensitive)
# Check that tables with same letters, but different case
# don't conflict in query cache
reset query cache;
flush status;
disable_query_log;
if (`SELECT @@lower_case_table_names = 0`)
{
  CREATE TABLE t1 ( pk int not null primary key,
  a int, b int not null, c varchar(20)) ENGINE=ndbcluster;
  insert into t1 value (1, 2, 3, 'First row');
  select * from t1;
  CREATE TABLE T1 ( pk int not null primary key,
  a int, b int not null, c varchar(20)) ENGINE=ndbcluster;
  insert into T1 value (1, 2, 3, 'First row');
  select * from T1;
  select * from T1;
  drop table t1,T1;
}
if (`SELECT @@lower_case_table_names <> 0`)
{
  CREATE TABLE t1 ( pk int not null primary key,
  a int, b int not null, c varchar(20)) ENGINE=ndbcluster;
  insert into t1 value (1, 2, 3, 'First row');
  select * from t1;
  CREATE TABLE tt1 ( pk int not null primary key,
  a int, b int not null, c varchar(20)) ENGINE=ndbcluster;
  insert into tt1 value (1, 2, 3, 'First row');
  select * from tt1;
  select * from tt1;
  drop table t1,tt1;
}
enable_query_log;
show status like "Qcache_hits";

SET GLOBAL query_cache_size=0;