~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/suite/ndb/t/ndb_read_multi_range.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- source include/have_ndb.inc
 
2
-- source include/not_embedded.inc
 
3
 
 
4
--disable_warnings
 
5
DROP TABLE IF EXISTS t1, t2, r1;
 
6
--enable_warnings
 
7
 
 
8
#
 
9
# Basic test to see that batching is working
 
10
#
 
11
 
 
12
create table t1 (
 
13
  a int primary key,
 
14
  b int not null,
 
15
  c int not null,
 
16
  index(b), unique index using hash(c)
 
17
) engine = ndb;
 
18
insert into t1 values
 
19
  (1,2,1),(2,3,2),(3,4,3),(4,5,4),
 
20
  (5,2,12),(6,3,11),(7,4,10),(8,5,9),
 
21
  (9,2,8),(10,3,7),(11,4,6),(12,5,5);
 
22
 
 
23
# batch on primary key
 
24
create table r1 as select * from t1 where a in (2,8,12);
 
25
select * from r1 order by a;
 
26
drop table r1;
 
27
 
 
28
# batch on ordered index
 
29
create table r1 as select * from t1 where b in (1,2,5);
 
30
select * from r1 order by a;
 
31
drop table r1;
 
32
 
 
33
# batch on unique hash index
 
34
create table r1 as select * from t1 where c in (2,8,12);
 
35
select * from r1 order by a;
 
36
drop table r1;
 
37
 
 
38
# batch mixed
 
39
create table r1 as select * from t1 where a in (2,8) or (a > 11) or (a <= 1);
 
40
select * from r1 order by a;
 
41
drop table r1;
 
42
 
 
43
# batch on primary key, missing values
 
44
create table r1 as select * from t1 where a in (33,8,12);
 
45
select * from r1 order by a;
 
46
drop table r1;
 
47
create table r1 as select * from t1 where a in (2,33,8,12,34);
 
48
select * from r1 order by a;
 
49
drop table r1;
 
50
 
 
51
# batch on ordered index, missing values
 
52
create table r1 as select * from t1 where b in (1,33,5);
 
53
select * from r1 order by a;
 
54
drop table r1;
 
55
select * from t1 where b in (1,33,5) order by a;
 
56
create table r1 as select * from t1 where b in (45,1,33,5,44);
 
57
select * from r1 order by a;
 
58
drop table r1;
 
59
select * from t1 where b in (45,22) order by a;
 
60
 
 
61
# batch on unique hash index, missing values
 
62
create table r1 as select * from t1 where c in (2,8,33);
 
63
select * from r1 order by a;
 
64
drop table r1;
 
65
create table r1 as select * from t1 where c in (13,2,8,33,12);
 
66
select * from r1 order by a;
 
67
drop table r1;
 
68
 
 
69
select * from t1 where a in (33,8,12) order by a;
 
70
select * from t1 where a in (33,34,35) order by a;
 
71
select * from t1 where a in (2,8) or (a > 11) or (a <= 1) order by a;
 
72
select * from t1 where b in (6,7) or (b <= 5) or (b >= 10) order by b,a;
 
73
select * from t1 where c in (13,2,8,33,12) order by c,a;
 
74
drop table t1;
 
75
 
 
76
#
 
77
# Somewhat more complicated
 
78
#
 
79
 
 
80
create table t1 (
 
81
  a int not null,
 
82
  b int not null,
 
83
  c int not null,
 
84
  d int not null,
 
85
  e int not null,
 
86
  primary key (a,b,c,d), index (d)
 
87
) engine = ndb;
 
88
 
 
89
insert into t1 values
 
90
  (1,2,1,1,1),(2,3,2,3,1),(3,4,3,1,1),(4,5,4,7,1),
 
91
  (5,2,12,12,1),(6,3,11,1,1),(7,4,10,3,1),(8,5,9,5,1),
 
92
  (9,2,8,6,1),(10,3,7,5,1),(11,4,6,3,1),(12,5,5,2,1),
 
93
  (1,2,1,2,1),
 
94
  (1,2,1,3,1),
 
95
  (1,2,1,4,1),
 
96
  (1,2,1,5,1);
 
97
 
 
98
# batch on primary key
 
99
create table r1 as select * from t1
 
100
  where a=1 and b=2 and c=1 and d in (1,4,3,2);
 
101
select * from r1 order by a,b,c,d;
 
102
drop table r1;
 
103
 
 
104
# batched update ordered index, one value for all
 
105
update t1 set e = 100
 
106
  where d in (12,6,7);
 
107
select * from t1 where d in (12,6,7) order by a,b,c,d;
 
108
select * from t1 where d not in (12,6,7) and e = 100;
 
109
 
 
110
# batched update primary key, one value for all
 
111
update t1 
 
112
  set e = 101
 
113
  where a=1 and 
 
114
        b=2 and 
 
115
        c=1 and 
 
116
        d in (1,4,3,2);
 
117
select * 
 
118
  from t1
 
119
  where a=1 and b=2 and c=1 and d in (1,4,3,2)
 
120
  order by a,b,c,d;
 
121
select * 
 
122
  from t1 
 
123
  where not (a=1 and b=2 and c=1 and d in (1,4,3,2))
 
124
        and e=101;
 
125
 
 
126
 
 
127
# batched update ordered index, different values
 
128
update t1 
 
129
  set e = 
 
130
    (case d
 
131
      when 12 then 112
 
132
      when 6  then 106
 
133
      when 7  then 107
 
134
    end)
 
135
  where d in (12,6,7);
 
136
select * from t1 where d in (12,6,7) order by a,b,c,d;
 
137
 
 
138
# batched update primary key, different values
 
139
update t1 
 
140
  set e = 
 
141
    (case d
 
142
      when 1 then 111
 
143
      when 4 then 444
 
144
      when 3 then 333
 
145
      when 2 then 222
 
146
    end)
 
147
  where a=1 and 
 
148
        b=2 and 
 
149
        c=1 and 
 
150
        d in (1,4,3,2);
 
151
select * 
 
152
  from t1
 
153
  where a=1 and b=2 and c=1 and d in (1,4,3,2)
 
154
  order by a,b,c,d;
 
155
 
 
156
# batched delete
 
157
delete from t1 where d in (12,6,7);
 
158
select * from t1 where d in (12,6,7);
 
159
 
 
160
drop table t1;
 
161
 
 
162
# null handling
 
163
create table t1 (
 
164
  a int not null primary key,
 
165
  b int,
 
166
  c int,
 
167
  d int,
 
168
  unique index (b),
 
169
  index(c)
 
170
) engine = ndb;
 
171
 
 
172
insert into t1 values
 
173
  (1,null,1,1),
 
174
  (2,2,2,2),
 
175
  (3,null,null,3),
 
176
  (4,4,null,4),
 
177
  (5,null,5,null),
 
178
  (6,6,6,null),
 
179
  (7,null,null,null),
 
180
  (8,8,null,null),
 
181
  (9,null,9,9),
 
182
  (10,10,10,10),
 
183
  (11,null,null,11),
 
184
  (12,12,null,12),
 
185
  (13,null,13,null),
 
186
  (14,14,14,null),
 
187
  (15,null,null,null),
 
188
  (16,16,null,null);
 
189
 
 
190
create table t2 as select * from t1 where a in (5,6,7,8,9,10);
 
191
select * from t2 order by a;
 
192
drop table t2;
 
193
 
 
194
create table t2 as select * from t1 where b in (5,6,7,8,9,10);
 
195
select * from t2 order by a;
 
196
drop table t2;
 
197
 
 
198
create table t2 as select * from t1 where c in (5,6,7,8,9,10);
 
199
select * from t2 order by a;
 
200
drop table t2;
 
201
 
 
202
drop table t1;
 
203
 
 
204
# bug17729
 
205
 
 
206
CREATE TABLE t1 (
 
207
  a int(11) NOT NULL,
 
208
  b int(11) NOT NULL,
 
209
  c datetime default NULL,
 
210
  PRIMARY KEY  (a),
 
211
  KEY idx_bc (b,c)
 
212
) ENGINE=ndbcluster;
 
213
 
 
214
INSERT INTO t1 VALUES 
 
215
(406989,67,'2006-02-23 17:08:46'), (150078,67,'2005-10-26 11:17:45'),
 
216
(406993,67,'2006-02-27 11:20:57'), (245655,67,'2005-12-08 15:59:08'),
 
217
(406994,67,'2006-02-27 11:26:46'), (256,67,NULL),
 
218
(398341,67,'2006-02-20 04:48:44'), (254,67,NULL),(1120,67,NULL),
 
219
(406988,67,'2006-02-23 17:07:22'), (255,67,NULL),
 
220
(398340,67,'2006-02-20 04:38:53'),(406631,67,'2006-02-23 10:49:42'),
 
221
(245653,67,'2005-12-08 15:59:07'),(406992,67,'2006-02-24 16:47:18'),
 
222
(245654,67,'2005-12-08 15:59:08'),(406995,67,'2006-02-28 11:55:00'),
 
223
(127261,67,'2005-10-13 12:17:58'),(406991,67,'2006-02-24 16:42:32'),
 
224
(245652,67,'2005-12-08 15:58:27'),(398545,67,'2006-02-20 04:53:13'),
 
225
(154504,67,'2005-10-28 11:53:01'),(9199,67,NULL),(1,67,'2006-02-23 15:01:35'),
 
226
(223456,67,NULL),(4101,67,NULL),(1133,67,NULL),
 
227
(406990,67,'2006-02-23 18:01:45'),(148815,67,'2005-10-25 15:34:17'),
 
228
(148812,67,'2005-10-25 15:30:01'),(245651,67,'2005-12-08 15:58:27'),
 
229
(154503,67,'2005-10-28 11:52:38');
 
230
 
 
231
create table t11 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
 
232
create table t12 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
 
233
create table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc;
 
234
create table t22 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
 
235
 
 
236
select * from t11 order by 1,2,3;
 
237
select * from t12 order by 1,2,3;
 
238
select * from t21 order by 1,2,3;
 
239
select * from t22 order by 1,2,3;
 
240
 
 
241
# join tests
 
242
select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null order by t12.a;
 
243
 
 
244
update t22 set c = '2005-12-08 15:58:27' where a = 255;
 
245
select * from t22 order by 1,2,3;
 
246
select t21.* from t21,t22 where t21.a = t22.a and 
 
247
t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;
 
248
 
 
249
delete from t22 where a > 245651;
 
250
update t22 set b = a + 1;
 
251
select * from t22 order by 1,2,3;
 
252
select t21.c, count(*)
 
253
from t21 
 
254
inner join t22 using (a)
 
255
where t22.b in (2,256,257,1121,1134,4102,9200,223457,245652)
 
256
group by t21.c
 
257
order by t21.c;
 
258
 
 
259
DROP TABLE t1, t11, t12, t21, t22;
 
260
 
 
261
# bug#19956
 
262
CREATE TABLE t1 (id varchar(255) NOT NULL,
 
263
                 tag int(11) NOT NULL,
 
264
                 doc text NOT NULL,
 
265
                 type varchar(150) NOT NULL,
 
266
                 modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
 
267
                 PRIMARY KEY (id)
 
268
                ) ENGINE=ndbcluster;
 
269
 
 
270
INSERT INTO t1 VALUES ('sakila',1,'Some text goes here','text',CURRENT_TIMESTAMP);
 
271
SELECT id, tag, doc, type FROM t1 WHERE id IN ('flipper','orka');
 
272
SELECT id, tag, doc, type FROM t1 WHERE id IN ('flipper','sakila');
 
273
 
 
274
DROP TABLE t1;
 
275
 
 
276
#bug#25522
 
277
CREATE TABLE t1 (
 
278
       var1 int(2) NOT NULL,
 
279
       var2 int(2) NOT NULL,
 
280
       PRIMARY KEY  (var1)
 
281
     ) ENGINE=ndbcluster DEFAULT CHARSET=ascii CHECKSUM=1;
 
282
 
 
283
 
 
284
CREATE TABLE t2 (
 
285
       var1 int(2) NOT NULL,
 
286
       var2 int(2) NOT NULL,
 
287
       PRIMARY KEY  (var1)
 
288
     ) ENGINE=ndbcluster DEFAULT CHARSET=ascii CHECKSUM=1;
 
289
 
 
290
 
 
291
DELIMITER |;
 
292
CREATE TRIGGER testtrigger
 
293
     AFTER UPDATE ON t1 FOR EACH ROW BEGIN
 
294
     REPLACE INTO t2 SELECT * FROM t1 WHERE t1.var1 = NEW.var1;END|
 
295
DELIMITER ;|
 
296
 
 
297
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
 
298
 
 
299
UPDATE t1 SET var2 = 9 WHERE var1 IN(1,2,3);
 
300
 
 
301
DROP TRIGGER testtrigger;
 
302
 
 
303
DROP TABLE t1, t2;
 
304
 
 
305
#bug#25821
 
306
create table t1 (a int, b int, primary key (a), key ab (a,b)) engine=ndbcluster;
 
307
 
 
308
insert into t1 values (1,1), (10,10);
 
309
 
 
310
select * from t1 use index (ab) where a in(1,10) order by a;
 
311
 
 
312
create table t2 (a int, b int, primary key (a,b)) engine=ndbcluster
 
313
partition by key(a);
 
314
 
 
315
insert into t2 values (1,1), (10,10);
 
316
 
 
317
select * from t2 where a in (1,10) order by a;
 
318
drop table t1, t2;
 
319
 
 
320
#bug#30337
 
321
 
 
322
create table t1 (id int primary key) engine ndb;
 
323
insert into t1 values (1), (2), (3);
 
324
 
 
325
create table t2 (id int primary key) engine ndb;
 
326
insert into t2 select id from t1;
 
327
 
 
328
delimiter |;
 
329
create trigger kaboom after delete on t1
 
330
for each row begin
 
331
  delete from t2 where id=old.id;
 
332
end|
 
333
delimiter ;|
 
334
 
 
335
select * from t1 order by id;
 
336
delete from t1 where id in (1,2);
 
337
select * from t2 order by id;
 
338
 
 
339
drop trigger kaboom;
 
340
drop table t1, t2;