~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/blitzdb/tests/t/blitzdb-index.test

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Test Routine for Indexing in BlitzDB
 
2
 
 
3
--disable_warnings
 
4
drop table if exists t1, t2;
 
5
--enable_warnings
 
6
 
 
7
# +------------------+
 
8
# | PRIMARY KEY: INT |
 
9
# +------------------+ 
 
10
create table t1 (id int primary key, a int, b int) engine = blitzdb;
 
11
select * from t1;
 
12
insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4);
 
13
insert into t1 values (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8);
 
14
insert into t1 values (9, 9, 9), (10, 10, 10), (11, 11, 11), (12, 12, 12);
 
15
insert into t1 values (13, 13, 13), (14, 14, 14), (15, 15, 15), (16, 16, 16);
 
16
 
 
17
# this statement should be 'optimized away'.
 
18
explain select count (*) from t1;
 
19
 
 
20
# overflow
 
21
--error ER_WARN_DATA_OUT_OF_RANGE
 
22
insert into t1 values (2147483648, 1, 1);
 
23
 
 
24
# duplicates 
 
25
--error ER_DUP_ENTRY
 
26
insert into t1 values (1, 0, 0);
 
27
--error ER_DUP_ENTRY
 
28
insert into t1 values (2, 0, 0);
 
29
--error ER_DUP_ENTRY
 
30
insert into t1 values (3, 0, 0);
 
31
--error ER_DUP_ENTRY
 
32
insert into t1 values (4, 0, 0);
 
33
 
 
34
# needle in a haystack 
 
35
select * from t1 where id = 2;
 
36
select * from t1 where id = 4;
 
37
select * from t1 where id = 6;
 
38
 
 
39
# update value by key
 
40
update t1 set a = 70 where id = 7;
 
41
update t1 set a = 80 where id = 8;
 
42
select * from t1 order by id;
 
43
 
 
44
# update the key
 
45
--error ER_DUP_ENTRY
 
46
update t1 set id = 2 where id = 1;
 
47
 
 
48
update t1 set id = 17 where id = 1;
 
49
update t1 set id = 18 where id = 2;
 
50
update t1 set id = 19 where id = 3;
 
51
update t1 set id = 20 where id = 4;
 
52
update t1 set id = 21 where id = 5;
 
53
update t1 set id = 22 where id = 6;
 
54
update t1 set id = 23 where id = 7;
 
55
 
 
56
--error ER_DUP_ENTRY
 
57
update t1 set id = 20 where id = 8;
 
58
 
 
59
# TODO: This is using filesort. Investigate why.
 
60
select * from t1 order by id;
 
61
 
 
62
# delete by pk
 
63
select count (*) from t1;
 
64
delete from t1 where id = 8;
 
65
select count (*) from t1;
 
66
delete from t1 where id = 9;
 
67
select count (*) from t1;
 
68
delete from t1 where id = 18;
 
69
select count (*) from t1;
 
70
delete from t1 where id = 19;
 
71
select count (*) from t1;
 
72
select count (id) from t1;
 
73
select count (a) from t1;
 
74
select count (b) from t1;
 
75
select * from t1 order by id;
 
76
 
 
77
# delete by pk range
 
78
delete from t1 where id > 10 and id < 14;
 
79
select * from t1 order by id;
 
80
select count (*) from t1;
 
81
delete from t1 where id >= 20 and id <= 23;
 
82
select * from t1 order by id;
 
83
select count (*) from t1;
 
84
 
 
85
# impossible range
 
86
delete from t1 where a > 20;
 
87
select count(*) from t1;
 
88
 
 
89
drop table t1;
 
90
 
 
91
# +---------------------+
 
92
# | PRIMARY KEY: BIGINT |
 
93
# +---------------------+
 
94
create table t1 (id bigint primary key, a int) engine = blitzdb;
 
95
 
 
96
# 32bit max
 
97
insert into t1 values (2147483647, 1);
 
98
 
 
99
# 64bit max
 
100
insert into t1 values (1.8e+18, 2);
 
101
 
 
102
# overflow
 
103
--error ER_WARN_DATA_OUT_OF_RANGE
 
104
insert into t1 values (1.8e+19, 3);
 
105
 
 
106
insert into t1 values (1,1), (2,2), (3,3), (4,4);
 
107
 
 
108
--error ER_DUP_ENTRY
 
109
update t1 set id = 4 where id = 1;
 
110
 
 
111
update t1 set id = 10 where id = 1;
 
112
update t1 set id = 20 where id = 2;
 
113
update t1 set id = 30 where id = 3;
 
114
update t1 set id = 40 where id = 4;
 
115
 
 
116
select count(*) from t1 where id < 10;
 
117
explain select id from t1 where id in (10, 20, 30, 40);
 
118
select id from t1 where id in (10, 20, 30, 40);
 
119
select * from t1;
 
120
 
 
121
delete from t1 where id = 10;
 
122
delete from t1 where id = 20;
 
123
delete from t1 where id in (30, 40);
 
124
select * from t1;
 
125
drop table t1;
 
126
 
 
127
# +--------------------------------------+
 
128
# | PRIMARY KEY: INT with Auto Increment |
 
129
# +--------------------------------------+
 
130
create table t1 (id int primary key auto_increment, num int) engine = blitzdb;
 
131
insert into t1 (num) values (1);
 
132
select * from t1;
 
133
insert into t1 (num) values (1);
 
134
insert into t1 (num) values (1);
 
135
insert into t1 (num) values (1);
 
136
select count(*) from t1;
 
137
flush table t1;
 
138
select count(*) from t1;
 
139
insert into t1 (num) values (1);
 
140
insert into t1 (num) values (1);
 
141
insert into t1 (num) values (1);
 
142
insert into t1 (num) values (1);
 
143
select count(*) from t1;
 
144
select count(num) from t1;
 
145
select * from t1;
 
146
drop table t1;
 
147
 
 
148
create table t1 (id int primary key auto_increment) engine = blitzdb;
 
149
insert into t1 values (1), (2), (3), (4);
 
150
insert into t1 values (8), (9), (10), (11);
 
151
insert into t1 values (5), (7);
 
152
select * from t1;
 
153
insert into t1 values (), (), (); # 12, 13, 14
 
154
select * from t1;
 
155
drop table t1;
 
156
 
 
157
# COUNT on a single auto column table
 
158
create table t1 (id int primary key auto_increment) engine = blitzdb;
 
159
insert into t1 values ();
 
160
insert into t1 values ();
 
161
insert into t1 values ();
 
162
insert into t1 values ();
 
163
select count(*) from t1;
 
164
delete from t1 where id = 1;
 
165
delete from t1 where id = 2;
 
166
select count(*) from t1;
 
167
insert into t1 values ();
 
168
insert into t1 values ();
 
169
select count(*) from t1;
 
170
drop table t1;
 
171
 
 
172
# +---------------------+
 
173
# | PRIMARY KEY: DOUBLE |
 
174
# +---------------------+
 
175
create table t1 (id double primary key, a int) engine = blitzdb;
 
176
insert into t1 values (1.1, 1);
 
177
insert into t1 values (1.11, 2);
 
178
insert into t1 values (1.111, 3);
 
179
insert into t1 values (1.1111, 4);
 
180
insert into t1 values (2.2, 5);
 
181
insert into t1 values (2.22, 6);
 
182
insert into t1 values (2.222, 7);
 
183
insert into t1 values (2.2222, 8);
 
184
select * from t1;
 
185
 
 
186
--error ER_DUP_ENTRY
 
187
update t1 set id = 1.11 where id = 1.1;
 
188
--error ER_DUP_ENTRY
 
189
update t1 set id = 2.22 where id = 2.2;
 
190
 
 
191
update t1 set id = 3.3 where id = 1.1;
 
192
update t1 set id = 3.33 where id = 1.11;
 
193
update t1 set id = 3.333 where id = 1.111;
 
194
update t1 set id = 3.3333 where id = 1.1111;
 
195
select * from t1 order by id;
 
196
 
 
197
--error ER_DUP_ENTRY
 
198
update t1 set id = 2.2 where id = 3.3;
 
199
 
 
200
delete from t1 where id = 3.3;
 
201
delete from t1 where id = 3.33;
 
202
select * from t1 order by id;
 
203
drop table t1;
 
204
 
 
205
# +----------------------+
 
206
# | PRIMARY KEY: VARCHAR |
 
207
# +----------------------+
 
208
create table t1 (id varchar(64) primary key, country varchar(64)) engine = blitzdb;
 
209
insert into t1 values ('amsterdam', 'netherlands');
 
210
insert into t1 values ('budapest', 'hungary');
 
211
insert into t1 values ('copenhagen', 'denmark');
 
212
insert into t1 values ('dublin', 'ireland');
 
213
insert into t1 values ('edinburgh', 'scotland');
 
214
insert into t1 values ('fukuoka', 'japan');
 
215
insert into t1 values ('geneva', 'switzerland');
 
216
 
 
217
select * from t1 order by id;
 
218
select country from t1 where id = 'dublin';
 
219
select country from t1 where id = 'geneva';
 
220
select country from t1 where id = 'amsterdam';
 
221
select country from t1 where id = 'non existent key';
 
222
select country from t1 where id = 'edinburgh';
 
223
select country from t1 where id = 'copenhagen';
 
224
select country from t1 where id = 'fukuoka';
 
225
select country from t1 where id = 'budapest';
 
226
select count (id) from t1;
 
227
 
 
228
--error ER_DUP_ENTRY
 
229
update t1 set id = 'dublin' where id = 'geneva';
 
230
update t1 set id = 'berlin', country = 'germany' where id = 'budapest';
 
231
update t1 set id = 'london', country = 'england' where id = 'copenhagen';
 
232
update t1 set id = 'paris', country = 'france' where id = 'dublin';
 
233
 
 
234
explain select * from t1 where id = 'berlin';
 
235
select * from t1 where id = 'berlin';
 
236
select * from t1 where id = 'london';
 
237
select * from t1 where id = 'paris';
 
238
 
 
239
delete from t1 where id = 'geneva';
 
240
delete from t1 where id = 'fukuoka';
 
241
select count (id) from t1;
 
242
select count (*) from t1;
 
243
select * from t1 order by id;
 
244
 
 
245
# Delete by Range
 
246
delete from t1 where id < 'london';
 
247
select count (*) from t1;
 
248
select * from t1 order by id;
 
249
drop table t1;
 
250
 
 
251
# Test HA_KEYTYPE_VARTEXT1 as a PRIMARY KEY
 
252
create table t1 (a varchar(10) primary key, b int) engine = blitzdb;
 
253
insert into t1 values ('aaa', 1), ('bbb', 2), ('ccc', 3), ('ddd', 4);
 
254
insert into t1 values ('eee', 5), ('fff', 6), ('ggg', 7), ('hhh', 8);
 
255
 
 
256
select * from t1 where a = 'aaa';
 
257
select * from t1 where a = 'bbb';
 
258
select * from t1 where a = 'ccc';
 
259
select * from t1 where a = 'ddd';
 
260
select * from t1;
 
261
 
 
262
delete from t1 where a = 'ggg';
 
263
delete from t1 where a = 'hhh';
 
264
select * from t1;
 
265
 
 
266
--error ER_DUP_ENTRY
 
267
update t1 set a = 'ddd' where a = 'aaa';
 
268
--error ER_DUP_ENTRY
 
269
update t1 set a = 'ccc' where a = 'bbb';
 
270
 
 
271
update t1 set a = 'zzz' where a = 'fff';
 
272
select count(*) from t1 where a = 'fff';
 
273
select * from t1 where a = 'zzz';
 
274
select * from t1;
 
275
drop table t1;
 
276
 
 
277
# +------------------+
 
278
# |PRIMARY KEY: DATE |
 
279
# +------------------+
 
280
create table t1 (a date primary key, b int, c varchar(32)) engine = blitzdb;
 
281
insert into t1 values ('1984-09-22', 22, 'twenty two');
 
282
insert into t1 values ('1984-09-23', 23, 'twenty three');
 
283
insert into t1 values ('1984-09-24', 24, 'twenty four');
 
284
insert into t1 values ('1984-09-25', 23, 'twenty five');
 
285
select * from t1;
 
286
explain select * from t1 where a = '1984-09-22';
 
287
select * from t1 where a = '1984-09-22';
 
288
select * from t1 where a = '1984-09-23';
 
289
select * from t1 where a = '1984-09-24';
 
290
select * from t1 where a = '1984-09-25';
 
291
 
 
292
--error ER_DUP_ENTRY
 
293
update t1 set a = '1984-09-22' where a = '1984-09-25';
 
294
--error ER_DUP_ENTRY
 
295
update t1 set a = '19840922' where a = '1984-09-25';
 
296
 
 
297
update t1 set a = '2010-03-10' where a = '1984-09-22';
 
298
update t1 set a = '2010-03-11', b = 777, c = 'triple seven' where a = '1984-09-23';
 
299
select * from t1 order by a;
 
300
drop table t1;
 
301
 
 
302
# Test basic index scan on INT primary keys.
 
303
create table t1 (a int primary key) engine = blitzdb;
 
304
insert into t1 values (1), (2), (3), (4), (5), (6);
 
305
 
 
306
# forward scan
 
307
explain select * from t1 order by a desc;
 
308
select * from t1;
 
309
 
 
310
# reverse scan
 
311
explain select * from t1 order by a desc;
 
312
select * from t1 order by a desc;
 
313
 
 
314
# write in random order
 
315
delete from t1;
 
316
insert into t1 values (6), (1), (5), (3), (2), (4);
 
317
 
 
318
# forward scan
 
319
explain select * from t1;
 
320
--sorted_result
 
321
select * from t1;
 
322
 
 
323
# reverse scan
 
324
explain select * from t1 order by a desc;
 
325
select * from t1 order by a desc;
 
326
 
 
327
# test aggregate functions
 
328
explain select max(a) from t1;
 
329
select max(a) from t1;
 
330
explain select min(a) from t1;
 
331
select min(a) from t1;
 
332
explain select sum(a) from t1;
 
333
select sum(a) from t1;
 
334
 
 
335
drop table t1;
 
336
 
 
337
# Test basic forward index scan on BIGINT primary keys.
 
338
create table t1 (a bigint primary key) engine = blitzdb;
 
339
insert into t1 values (10), (20), (30), (40), (50), (60);
 
340
 
 
341
explain select * from t1;
 
342
select * from t1;
 
343
select * from t1 order by a desc;
 
344
delete from t1;
 
345
 
 
346
insert into t1 values (60), (10), (50), (30), (20), (40);
 
347
select * from t1;
 
348
select * from t1 order by a desc;
 
349
drop table t1;
 
350
 
 
351
# Test basic index scan on VARTEXT1 primary keys.
 
352
create table t1 (a varchar(10) primary key) engine = blitzdb;
 
353
insert into t1 values ('a'), ('b'), ('c'), ('d'), ('e');
 
354
select * from t1;
 
355
explain select * from t1 order by a desc;
 
356
select * from t1 order by a desc;
 
357
delete from t1;
 
358
insert into t1 values ('c'), ('a'), ('e'), ('b'), ('d');
 
359
select * from t1;
 
360
delete from t1;
 
361
 
 
362
# Test it with multi byte characters (Japanese).
 
363
insert into t1 values ('う'), ('お'), ('い'), ('あ'), ('え');
 
364
insert into t1 values ('こ'), ('け'), ('か'), ('く'), ('き');
 
365
explain select * from t1;
 
366
select * from t1;
 
367
explain select * from t1 order by a desc;
 
368
select * from t1 order by a desc;
 
369
drop table t1;
 
370
 
 
371
# Test basic index scan on VARTEXT2 primary keys.
 
372
create table t1 (a varchar(255) primary key) engine = blitzdb;
 
373
insert into t1 values ('a'), ('b'), ('c'), ('d'), ('e');
 
374
explain select * from t1;
 
375
select * from t1;
 
376
select * from t1 order by a desc;
 
377
delete from t1;
 
378
insert into t1 values ('c'), ('a'), ('e'), ('b'), ('d');
 
379
select * from t1;
 
380
delete from t1;
 
381
drop table t1;
 
382
 
 
383
# Test UNIQUE index insertion 
 
384
create table t1 (a int, unique index(a)) engine = blitzdb;
 
385
insert into t1 values (1), (2);
 
386
 
 
387
--error ER_DUP_ENTRY
 
388
insert into t1 values (1);
 
389
--error ER_DUP_ENTRY
 
390
insert into t1 values (2);
 
391
 
 
392
insert into t1 values (NULL);
 
393
insert into t1 values (3);
 
394
insert into t1 values (4);
 
395
 
 
396
select * from t1;
 
397
select * from t1 where a = 1;
 
398
select * from t1 where a = 2;
 
399
select * from t1 where a = 3;
 
400
select * from t1 where a = 4;
 
401
select * from t1 where a is NULL;
 
402
drop table t1;
 
403
 
 
404
create table t1 (a varchar(32), unique index(a)) engine = blitzdb;
 
405
insert into t1 values ('a'), ('b'), ('c');
 
406
 
 
407
--error ER_DUP_ENTRY
 
408
insert into t1 values ('a');
 
409
--error ER_DUP_ENTRY
 
410
insert into t1 values ('b');
 
411
--error ER_DUP_ENTRY
 
412
insert into t1 values ('c');
 
413
 
 
414
insert into t1 values ('f'), ('e'), ('d');
 
415
--sorted_result
 
416
select * from t1;
 
417
select count(*) from t1;
 
418
explain select * from t1 where a = 'a';
 
419
select * from t1 where a = 'a';
 
420
select * from t1 where a = 'b';
 
421
select * from t1 where a = 'c';
 
422
select * from t1 where a = 'd';
 
423
select * from t1 where a = 'e';
 
424
select * from t1 where a = 'f';
 
425
 
 
426
# deletion test
 
427
delete from t1 where a = 'a';
 
428
delete from t1 where a = 'b';
 
429
select count(*) from t1;
 
430
select * from t1;
 
431
delete from t1 where a = 'c';
 
432
delete from t1 where a = 'd';
 
433
delete from t1 where a = 'e';
 
434
delete from t1 where a = 'f';
 
435
select count(*) from t1;
 
436
select * from t1;
 
437
drop table t1;
 
438
 
 
439
# +------------+
 
440
# | INDEX: INT |
 
441
# +------------+
 
442
create table t1 (a int, index(a)) engine = blitzdb;
 
443
insert into t1 values (1), (2), (3), (4);
 
444
insert into t1 values (1), (2), (3), (4);
 
445
 
 
446
--sorted_result
 
447
select * from t1;
 
448
 
 
449
insert into t1 values (NULL), (NULL);
 
450
insert into t1 values (NULL), (NULL);
 
451
 
 
452
select * from t1;
 
453
select count(*) from t1 where a is NULL;
 
454
select * from t1 where a is NULL;
 
455
select * from t1 where a is not NULL;
 
456
 
 
457
# indexed needle in a haystack query
 
458
explain select * from t1 where a = 1;
 
459
select * from t1 where a = 1;
 
460
select * from t1 where a = 2;
 
461
select * from t1 where a = 3;
 
462
select * from t1 where a = 4;
 
463
 
 
464
# index based deletion
 
465
delete from t1 where a = 3;
 
466
select * from t1 where a = 3;
 
467
delete from t1 where a = 1;
 
468
select * from t1 where a = 1;
 
469
select * from t1;
 
470
delete from t1 where a is NULL;
 
471
select * from t1 where a is NULL;
 
472
delete from t1 where a = 2;
 
473
select * from t1 where a = 2;
 
474
delete from t1 where a = 4;
 
475
select * from t1 where a = 4;
 
476
select count(*) from t1;
 
477
drop table t1;
 
478
 
 
479
# +------------------------------+
 
480
# | UNIQUE INDEX: DUPLICATE NULL |
 
481
# +------------------------------+
 
482
create table t1 (a int, b int, unique index(a)) engine = blitzdb;
 
483
insert into t1 values (NULL, 1), (NULL, 2), (NULL, 3), (NULL, 4);
 
484
select * from t1;
 
485
select * from t1 where a is NULL;
 
486
insert into t1 values (1, 5), (2, 6);
 
487
--error ER_DUP_ENTRY
 
488
insert into t1 values (1, 7), (1, 8);
 
489
select * from t1 where a is not NULL;
 
490
delete from t1 where a is NULL;
 
491
select * from t1;
 
492
select count(*) from t1;
 
493
drop table t1;
 
494
 
 
495
# +-----------------+
 
496
# | INDEX: GROUP BY |
 
497
# +-----------------+
 
498
create table t1 (
 
499
  id int primary key,
 
500
  lastname varchar(64),
 
501
  description varchar(255), 
 
502
  price int,
 
503
  INDEX(price)
 
504
) engine = blitzdb;
 
505
 
 
506
insert into t1 values (1, "Schwartz", "Flight", 1500);
 
507
insert into t1 values (2, "Hayes", "Computer Equipment", 400);
 
508
insert into t1 values (3, "Lawrence", "Text Books", 220);
 
509
insert into t1 values (4, "Smith", "Weaponry", 45500);
 
510
insert into t1 values (5, "Yamada", "Dinner", 120);
 
511
insert into t1 values (6, "Smith", "Lunch", 30);
 
512
insert into t1 values (7, "Hayes", "Lunch", 30);
 
513
insert into t1 values (8, "Kinoshita", "Computer Equipment", 3740);
 
514
 
 
515
select * from t1;
 
516
select sum(price) from t1;
 
517
select lastname, sum(price) from t1 group by lastname;
 
518
 
 
519
drop table t1;
 
520
 
 
521
# +-----------------------+
 
522
# | COMPOSITE INDEX CHECK |
 
523
# +-----------------------+
 
524
 
 
525
--error ER_CANT_CREATE_TABLE
 
526
create table t1 (a int, b int, c int, d int, primary key(a, b)) engine = blitzdb;
 
527
--error ER_CANT_CREATE_TABLE
 
528
create table t1 (a int, b int, c int, d int, primary key(a, b, c)) engine = blitzdb;
 
529
--error ER_CANT_CREATE_TABLE
 
530
create table t1 (a int, b int, c int, d int, index(a, b)) engine = blitzdb;
 
531
--error ER_CANT_CREATE_TABLE
 
532
create table t1 (a int, b int, c int, d int, index(a, b, c)) engine = blitzdb;
 
533
--error ER_CANT_CREATE_TABLE
 
534
create table t1 (a int, b int, c int, d int, unique(a, b)) engine = blitzdb;
 
535
--error ER_CANT_CREATE_TABLE
 
536
create table t1 (a int, b int, c int, d int, unique(a, b, c)) engine = blitzdb;
 
537
 
 
538
# +------------------------------------------+
 
539
# | LARGE KEYS : Testcase from Patrick Crews |
 
540
# +------------------------------------------+
 
541
 
 
542
create table `t1` (
 
543
  `col_varchar_10_key` varchar(10),
 
544
  `col_int_key` int,
 
545
  `col_varchar_1024_key` varchar(1024),
 
546
  pk integer auto_increment,
 
547
  `col_varchar_10` varchar(10),
 
548
  `col_int` int,
 
549
  `col_varchar_1024` varchar(1024),
 
550
  key (`col_varchar_10_key`),
 
551
  key (`col_int_key`),
 
552
  key (`col_varchar_1024_key`),
 
553
  primary key (pk)
 
554
) engine = blitzdb;
 
555
 
 
556
insert /*! IGNORE */ into t1 values ('x', NULL, 'keyone', NULL, 'could', 1322188800, 'I\'m');
 
557
insert /*! IGNORE */ into t1 values ('y', NULL, 'keytwo', NULL, 'could', 1322188800, 'I\'m');
 
558
insert /*! IGNORE */ into t1 values ('z', NULL, 'keythree', NULL, 'could', 1322188800, 'I\'m');
 
559
select * from t1;
 
560
 
 
561
drop table t1;