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

« back to all changes in this revision

Viewing changes to mysql-test/suite/ndb/t/ndb_basic.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,t3,t4,t5,t6,t7;
 
6
drop database if exists mysqltest;
 
7
--enable_warnings
 
8
 
 
9
# workaround for bug#16445
 
10
# remove to reproduce bug and run tests from ndb start
 
11
# and with ndb_autodiscover disabled. Fails on Linux 50 % of the times
 
12
CREATE TABLE t1 (
 
13
  pk1 INT NOT NULL PRIMARY KEY,
 
14
  attr1 INT NOT NULL,
 
15
  attr2 INT,
 
16
  attr3 VARCHAR(10)
 
17
) ENGINE=ndbcluster;
 
18
drop table t1;
 
19
 
 
20
#
 
21
# Basic test to show that the NDB 
 
22
# table handler is working
 
23
#
 
24
 
 
25
#
 
26
# Show status and variables
 
27
#
 
28
--replace_column 2 #
 
29
SHOW GLOBAL STATUS LIKE 'ndb%';
 
30
--replace_column 2 #
 
31
SHOW GLOBAL VARIABLES LIKE 'ndb%';
 
32
 
 
33
#
 
34
# Create a normal table with primary key
 
35
#
 
36
CREATE TABLE t1 (
 
37
  pk1 INT NOT NULL PRIMARY KEY,
 
38
  attr1 INT NOT NULL,
 
39
  attr2 INT,
 
40
  attr3 VARCHAR(10)
 
41
) ENGINE=ndbcluster;
 
42
 
 
43
SHOW INDEX FROM t1;  
 
44
INSERT INTO t1 VALUES (9410,9412, NULL, '9412'), (9411,9413, 17, '9413');
 
45
SHOW INDEX FROM t1;  
 
46
SELECT pk1 FROM t1 ORDER BY pk1;
 
47
SELECT * FROM t1 ORDER BY pk1;
 
48
SELECT t1.* FROM t1 ORDER BY pk1;
 
49
 
 
50
# Update on record by primary key
 
51
UPDATE t1 SET attr1=1 WHERE pk1=9410;
 
52
SELECT * FROM t1 ORDER BY pk1;
 
53
 
 
54
# Update primary key
 
55
UPDATE t1 SET pk1=2 WHERE attr1=1;
 
56
SELECT * FROM t1 ORDER BY pk1;
 
57
UPDATE t1 SET pk1=pk1 + 1;
 
58
SELECT * FROM t1 ORDER BY pk1;
 
59
UPDATE t1 SET pk1=4 WHERE pk1 = 3;
 
60
SELECT * FROM t1 ORDER BY pk1;
 
61
 
 
62
# Delete the record
 
63
DELETE FROM t1;
 
64
SELECT * FROM t1;
 
65
 
 
66
# Insert more records and update them all at once
 
67
INSERT INTO t1 VALUES (9410,9412, NULL, '9412'), (9408, 8765, NULL, '8765'),
 
68
(7,8, NULL, NULL), (8,9, NULL, NULL), (9,10, NULL, NULL), (10,11, NULL, NULL), (11,12, NULL, NULL), (12,13, NULL, NULL), (13,14, NULL, NULL);
 
69
UPDATE t1 SET attr1 = 9999;
 
70
SELECT * FROM t1 ORDER BY pk1;
 
71
 
 
72
UPDATE t1 SET attr1 = 9998 WHERE pk1 < 1000;
 
73
SELECT * FROM t1 ORDER BY pk1;
 
74
 
 
75
UPDATE t1 SET attr1 = 9997 WHERE attr1 = 9999;
 
76
SELECT * FROM t1 ORDER BY pk1;
 
77
 
 
78
# Delete one record by specifying pk
 
79
DELETE FROM t1 WHERE pk1 = 9410;
 
80
SELECT * FROM t1 ORDER BY pk1;
 
81
 
 
82
# Delete all from table
 
83
DELETE FROM t1;
 
84
SELECT * FROM t1;
 
85
 
 
86
# Insert three records with attr1=4 and two with attr1=5
 
87
# Delete all with attr1=4
 
88
INSERT INTO t1 values (1, 4, NULL, NULL), (2, 4, NULL, NULL), (3, 5, NULL, NULL), (4, 4, NULL, NULL), (5, 5, NULL, NULL);
 
89
DELETE FROM t1 WHERE attr1=4;
 
90
SELECT * FROM t1 order by pk1;
 
91
DELETE FROM t1;
 
92
 
 
93
# Insert two records and delete one
 
94
INSERT INTO t1 VALUES (9410,9412, NULL, NULL), (9411, 9413, NULL, NULL);
 
95
DELETE FROM t1 WHERE pk1 = 9410;
 
96
SELECT * FROM t1;
 
97
DROP TABLE t1;
 
98
 
 
99
#
 
100
# Create table without primary key
 
101
# a hidden primary key column is created by handler
 
102
#
 
103
CREATE TABLE t1 (id INT, id2 int) engine=ndbcluster;
 
104
INSERT INTO t1 values(3456, 7890);
 
105
SELECT * FROM t1;
 
106
UPDATE t1 SET id=2 WHERE id2=12;
 
107
SELECT * FROM t1;
 
108
UPDATE t1 SET id=1234 WHERE id2=7890;
 
109
SELECT * FROM t1;
 
110
DELETE FROM t1;
 
111
 
 
112
INSERT INTO t1 values(3456, 7890), (3456, 7890), (3456, 7890), (3454, 7890);
 
113
SELECT * FROM t1 ORDER BY id;
 
114
DELETE FROM t1 WHERE id = 3456;
 
115
SELECT * FROM t1 ORDER BY id;
 
116
 
 
117
DROP TABLE t1;
 
118
 
 
119
# test create with the keyword "engine=NDBCLUSTER"
 
120
CREATE TABLE t1 (
 
121
  pk1 INT NOT NULL PRIMARY KEY,
 
122
  attr1 INT NOT NULL
 
123
) ENGINE=NDBCLUSTER;
 
124
 
 
125
INSERT INTO t1 values(1, 9999);
 
126
 
 
127
DROP TABLE t1;
 
128
 
 
129
# test create with the keyword "engine=NDB"
 
130
CREATE TABLE t1 (
 
131
  pk1 INT NOT NULL PRIMARY KEY,
 
132
  attr1 INT NOT NULL
 
133
) ENGINE=NDB;
 
134
 
 
135
INSERT INTO t1 values(1, 9999);
 
136
 
 
137
DROP TABLE t1;
 
138
 
 
139
 
 
140
#
 
141
# A more extensive test with a lot more records
 
142
#
 
143
 
 
144
CREATE TABLE t2 (
 
145
  a bigint unsigned NOT NULL PRIMARY KEY,
 
146
  b int unsigned not null,
 
147
  c int unsigned
 
148
) engine=ndbcluster;
 
149
 
 
150
CREATE TABLE t3 (
 
151
  a bigint unsigned NOT NULL,
 
152
  b bigint unsigned not null,
 
153
  c bigint unsigned,
 
154
  PRIMARY KEY(a)
 
155
) engine=ndbcluster;
 
156
 
 
157
CREATE TABLE t4 (
 
158
  a bigint unsigned NOT NULL,
 
159
  b bigint unsigned not null,
 
160
  c bigint unsigned NOT NULL,
 
161
  d int unsigned,
 
162
  PRIMARY KEY(a, b, c)
 
163
) engine=ndbcluster;
 
164
 
 
165
 
 
166
#
 
167
# insert more records into tables
 
168
#
 
169
let $1=1000;
 
170
disable_query_log;
 
171
while ($1)
 
172
{
 
173
 eval insert into t2 values($1, $1+9, 5);
 
174
 eval insert into t3 values($1, $1+9, 5);
 
175
 eval insert into t4 values($1, $1+9, 5, $1+26000);
 
176
 dec $1;
 
177
}
 
178
enable_query_log;
 
179
 
 
180
 
 
181
#
 
182
# delete every other record in the tables
 
183
#
 
184
let $1=1000;
 
185
disable_query_log;
 
186
while ($1)
 
187
{
 
188
 eval delete from t2 where a=$1;
 
189
 eval delete from t3 where a=$1;
 
190
 eval delete from t4 where a=$1 and b=$1+9 and c=5;
 
191
 dec $1;
 
192
 dec $1;
 
193
}
 
194
enable_query_log;
 
195
 
 
196
 
 
197
select * from t2 where a = 7 order by b;
 
198
select * from t2 where a = 7 order by a;
 
199
select * from t2 where a = 7 order by 2;
 
200
select * from t2 where a = 7 order by c;
 
201
 
 
202
select * from t2 where a = 7 and b = 16 order by b;
 
203
select * from t2 where a = 7 and b = 16 order by a;
 
204
select * from t2 where a = 7 and b = 17 order by a;
 
205
select * from t2 where a = 7 and b != 16 order by b;
 
206
 
 
207
select * from t2 where a = 7 and b = 16 and c = 5 order by b;
 
208
select * from t2 where a = 7 and b = 16 and c = 5 order by a;
 
209
select * from t2 where a = 7 and b = 16 and c = 6 order by a;
 
210
select * from t2 where a = 7 and b != 16 and c = 5 order by b;
 
211
 
 
212
select * from t3 where a = 7 order by b;
 
213
select * from t3 where a = 7 order by a;
 
214
select * from t3 where a = 7 order by 2;
 
215
select * from t3 where a = 7 order by c;
 
216
 
 
217
select * from t3 where a = 7 and b = 16 order by b;
 
218
select * from t3 where a = 7 and b = 16 order by a;
 
219
select * from t3 where a = 7 and b = 17 order by a;
 
220
select * from t3 where a = 7 and b != 16 order by b;
 
221
 
 
222
select * from t4 where a = 7 order by b;
 
223
select * from t4 where a = 7 order by a;
 
224
select * from t4 where a = 7 order by 2;
 
225
select * from t4 where a = 7 order by c;
 
226
 
 
227
select * from t4 where a = 7 and b = 16 order by b;
 
228
select * from t4 where a = 7 and b = 16 order by a;
 
229
select * from t4 where a = 7 and b = 17 order by a;
 
230
select * from t4 where a = 7 and b != 16 order by b;
 
231
 
 
232
#
 
233
# update records
 
234
#
 
235
let $1=1000;
 
236
disable_query_log;
 
237
while ($1)
 
238
{
 
239
 eval update t2 set c=$1 where a=$1;
 
240
 eval update t3 set c=7 where a=$1 and b=$1+9 and c=5;
 
241
 eval update t4 set d=$1+21987 where a=$1 and b=$1+9 and c=5;
 
242
 dec $1;
 
243
 dec $1;
 
244
}
 
245
enable_query_log;
 
246
 
 
247
delete from t2 where a > 5;
 
248
select x1.a, x1.b from t2 x1, t2 x2 where x1.b = x2.b order by x1.a;
 
249
select a, b FROM t2 outer_table where
 
250
a = (select a from t2 where b = outer_table.b ) order by a;
 
251
 
 
252
 
 
253
delete from t2;
 
254
delete from t3;
 
255
delete from t4;
 
256
 
 
257
drop table t2;
 
258
drop table t3;
 
259
drop table t4;
 
260
 
 
261
#
 
262
# Test delete and update from table with 3 keys
 
263
#
 
264
 
 
265
CREATE TABLE t5 (
 
266
  a bigint unsigned NOT NULL,
 
267
  b bigint unsigned not null,
 
268
  c bigint unsigned NOT NULL,
 
269
  d int unsigned,
 
270
  PRIMARY KEY(a, b, c)
 
271
) engine=ndbcluster;
 
272
 
 
273
insert into t5 values(10, 19, 5, 26010);
 
274
 
 
275
delete from t5 where a=10 and b=19 and c=5;
 
276
 
 
277
select * from t5;
 
278
 
 
279
insert into t5 values(10, 19, 5, 26010);
 
280
 
 
281
update t5 set d=21997 where a=10 and b=19 and c=5;
 
282
 
 
283
select * from t5;
 
284
 
 
285
delete from t5;
 
286
 
 
287
drop table t5;
 
288
 
 
289
#
 
290
# Test using table with a char(255) column first in table
 
291
#
 
292
 
 
293
CREATE TABLE t6 (
 
294
  adress char(255),
 
295
  a int NOT NULL PRIMARY KEY,
 
296
  b int
 
297
) engine = NDB;
 
298
 
 
299
insert into t6 values
 
300
 ("Nice road 3456", 1, 23),
 
301
 ("Street Road 78", 3, 92),
 
302
 ("Road street 89C", 5, 71),
 
303
 (NULL, 7, NULL);
 
304
select * from t6 order by a;
 
305
select a, b from t6 order by a;
 
306
 
 
307
update t6 set adress="End of road 09" where a=3;
 
308
update t6 set b=181, adress="Street 76" where a=7;
 
309
select * from t6 order by a;
 
310
select * from t6 where a=1;
 
311
delete from t6 where a=1;
 
312
select * from t6 order by a;
 
313
delete from t6 where b=71;
 
314
select * from t6 order by a;
 
315
 
 
316
drop table t6;
 
317
 
 
318
#
 
319
# Test using table with a char(255) column first in table and a 
 
320
# primary key consisting of two columns
 
321
#
 
322
 
 
323
CREATE TABLE t7 (
 
324
  adress char(255),
 
325
  a int NOT NULL,
 
326
  b int,
 
327
  c int NOT NULL,
 
328
  PRIMARY KEY(a, c)     
 
329
) engine = NDB;
 
330
 
 
331
insert into t7 values
 
332
 ("Highway 3456", 1, 23, 2),
 
333
 ("Street Road 78", 3, 92, 3),
 
334
 ("Main street 89C", 5, 71, 4),
 
335
 (NULL, 8, NULL, 12);
 
336
select * from t7 order by a;
 
337
select a, b from t7 order by a;
 
338
 
 
339
update t7 set adress="End of road 09" where a=3;
 
340
update t7 set adress="GatuvƤgen 90C" where a=5 and c=4;
 
341
update t7 set adress="No adress" where adress is NULL;
 
342
select * from t7 order by a;
 
343
select * from t7 where a=1 and c=2;
 
344
delete from t7 where a=1;
 
345
delete from t7 where a=3 and c=3;
 
346
delete from t7 where a=5 and c=4;
 
347
select * from t7;
 
348
delete from t7 where b=23;
 
349
select * from t7;
 
350
 
 
351
drop table t7;
 
352
 
 
353
#
 
354
# Test multiple databases in one statement
 
355
#
 
356
 
 
357
CREATE TABLE t1 (
 
358
  pk1 INT NOT NULL PRIMARY KEY,
 
359
  attr1 INT NOT NULL,
 
360
  attr2 INT,
 
361
  attr3 VARCHAR(10)
 
362
) ENGINE=ndbcluster;
 
363
 
 
364
INSERT INTO t1 VALUES (9410,9412, NULL, '9412'), (9411,9413, 17, '9413');
 
365
 
 
366
create database mysqltest;
 
367
use mysqltest;
 
368
 
 
369
CREATE TABLE t2 (
 
370
  a bigint unsigned NOT NULL PRIMARY KEY,
 
371
  b int unsigned not null,
 
372
  c int unsigned
 
373
) engine=ndbcluster;
 
374
 
 
375
insert into t2 select pk1,attr1,attr2 from test.t1;
 
376
select * from t2 order by a;
 
377
select b from test.t1, t2 where c = test.t1.attr2;
 
378
select b,test.t1.attr1 from test.t1, t2 where test.t1.pk1 < a;
 
379
 
 
380
drop table test.t1, t2;
 
381
drop database mysqltest;
 
382
 
 
383
#
 
384
# BUG#6031 - DROP DATABASE doesn't drop database on first try
 
385
#
 
386
 
 
387
--disable_warnings
 
388
drop database if exists ndbtest1;
 
389
--enable_warnings
 
390
 
 
391
create database ndbtest1;
 
392
use ndbtest1;
 
393
create table t1(id int) engine=ndbcluster;
 
394
drop database ndbtest1;
 
395
--error 1008
 
396
drop database ndbtest1;
 
397
 
 
398
#
 
399
# test support of char(0)
 
400
#
 
401
 
 
402
use test;
 
403
create table t1 (a int primary key, b char(0));
 
404
insert into t1 values (1,"");
 
405
insert into t1 values (2,NULL);
 
406
select * from t1 order by a;
 
407
select * from t1 order by b;
 
408
select * from t1 where b IS NULL;
 
409
select * from t1 where b IS NOT NULL;
 
410
drop table t1;
 
411
 
 
412
#
 
413
# test the limit of no of attributes in one table
 
414
#
 
415
# also tests bug#17179, more than 31 attributes in
 
416
# a partitioned table
 
417
#
 
418
create table t1 (
 
419
c1 int,
 
420
c2 int,
 
421
c3 int,
 
422
c4 int,
 
423
c5 int,
 
424
c6 int,
 
425
c7 int,
 
426
c8 int,
 
427
c9 int,
 
428
c10 int,
 
429
c11 int,
 
430
c12 int,
 
431
c13 int,
 
432
c14 int,
 
433
c15 int,
 
434
c16 int,
 
435
c17 int,
 
436
c18 int,
 
437
c19 int,
 
438
c20 int,
 
439
c21 int,
 
440
c22 int,
 
441
c23 int,
 
442
c24 int,
 
443
c25 int,
 
444
c26 int,
 
445
c27 int,
 
446
c28 int,
 
447
c29 int,
 
448
c30 int,
 
449
c31 int,
 
450
c32 int,
 
451
c33 int,
 
452
c34 int,
 
453
c35 int,
 
454
c36 int,
 
455
c37 int,
 
456
c38 int,
 
457
c39 int,
 
458
c40 int,
 
459
c41 int,
 
460
c42 int,
 
461
c43 int,
 
462
c44 int,
 
463
c45 int,
 
464
c46 int,
 
465
c47 int,
 
466
c48 int,
 
467
c49 int,
 
468
c50 int,
 
469
c51 int,
 
470
c52 int,
 
471
c53 int,
 
472
c54 int,
 
473
c55 int,
 
474
c56 int,
 
475
c57 int,
 
476
c58 int,
 
477
c59 int,
 
478
c60 int,
 
479
c61 int,
 
480
c62 int,
 
481
c63 int,
 
482
c64 int,
 
483
c65 int,
 
484
c66 int,
 
485
c67 int,
 
486
c68 int,
 
487
c69 int,
 
488
c70 int,
 
489
c71 int,
 
490
c72 int,
 
491
c73 int,
 
492
c74 int,
 
493
c75 int,
 
494
c76 int,
 
495
c77 int,
 
496
c78 int,
 
497
c79 int,
 
498
c80 int,
 
499
c81 int,
 
500
c82 int,
 
501
c83 int,
 
502
c84 int,
 
503
c85 int,
 
504
c86 int,
 
505
c87 int,
 
506
c88 int,
 
507
c89 int,
 
508
c90 int,
 
509
c91 int,
 
510
c92 int,
 
511
c93 int,
 
512
c94 int,
 
513
c95 int,
 
514
c96 int,
 
515
c97 int,
 
516
c98 int,
 
517
c99 int,
 
518
c100 int,
 
519
c101 int,
 
520
c102 int,
 
521
c103 int,
 
522
c104 int,
 
523
c105 int,
 
524
c106 int,
 
525
c107 int,
 
526
c108 int,
 
527
c109 int,
 
528
c110 int,
 
529
c111 int,
 
530
c112 int,
 
531
c113 int,
 
532
c114 int,
 
533
c115 int,
 
534
c116 int,
 
535
c117 int,
 
536
c118 int,
 
537
c119 int,
 
538
c120 int,
 
539
c121 int,
 
540
c122 int,
 
541
c123 int,
 
542
c124 int,
 
543
c125 int,
 
544
c126 int,
 
545
c127 int,
 
546
c128 int,
 
547
primary key using hash(c1)) engine=ndb partition by key(c1);
 
548
drop table t1;
 
549
 
 
550
#
 
551
# test max size of attribute name and truncation
 
552
#
 
553
 
 
554
create table t1 (
 
555
a1234567890123456789012345678901234567890 int primary key,
 
556
a12345678901234567890123456789a1234567890 int,
 
557
index(a12345678901234567890123456789a1234567890)
 
558
) engine=ndb;
 
559
show tables;
 
560
insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2),(6,1),(7,1);
 
561
--replace_column 9 #
 
562
explain select * from t1 where a12345678901234567890123456789a1234567890=2;
 
563
select * from t1 where a12345678901234567890123456789a1234567890=2;
 
564
drop table t1;
 
565
 
 
566
#
 
567
# test fragment creation
 
568
#
 
569
# first a table with _many_ fragments per node group
 
570
# then a table with just one fragment per node group
 
571
#
 
572
create table t1
 
573
  (a bigint, b bigint, c bigint, d bigint, 
 
574
   primary key (a,b,c,d)) 
 
575
  engine=ndb
 
576
  max_rows=800000000;
 
577
insert into t1 values
 
578
  (1,2,3,4),(2,3,4,5),(3,4,5,6),
 
579
  (3,2,3,4),(1,3,4,5),(2,4,5,6),
 
580
  (1,2,3,5),(2,3,4,8),(3,4,5,9),
 
581
  (3,2,3,5),(1,3,4,8),(2,4,5,9),
 
582
  (1,2,3,6),(2,3,4,6),(3,4,5,7),
 
583
  (3,2,3,6),(1,3,4,6),(2,4,5,7),
 
584
  (1,2,3,7),(2,3,4,7),(3,4,5,8),
 
585
  (3,2,3,7),(1,3,4,7),(2,4,5,8),
 
586
  (1,3,3,4),(2,4,4,5),(3,5,5,6),
 
587
  (3,3,3,4),(1,4,4,5),(2,5,5,6),
 
588
  (1,3,3,5),(2,4,4,8),(3,5,5,9),
 
589
  (3,3,3,5),(1,4,4,8),(2,5,5,9),
 
590
  (1,3,3,6),(2,4,4,6),(3,5,5,7),
 
591
  (3,3,3,6),(1,4,4,6),(2,5,5,7),
 
592
  (1,3,3,7),(2,4,4,7),(3,5,5,8),
 
593
  (3,3,3,7),(1,4,4,7),(2,5,5,8);
 
594
select count(*) from t1;
 
595
drop table t1;
 
596
 
 
597
create table t1
 
598
  (a bigint, b bigint, c bigint, d bigint, 
 
599
   primary key (a)) 
 
600
  engine=ndb
 
601
  max_rows=1;
 
602
drop table t1;
 
603
 
 
604
#
 
605
# Test auto_increment
 
606
#
 
607
 
 
608
connect (con1,localhost,root,,test);
 
609
connect (con2,localhost,root,,test);
 
610
 
 
611
create table t1
 
612
        (counter int(64) NOT NULL auto_increment,
 
613
         datavalue char(40) default 'XXXX',
 
614
         primary key (counter)
 
615
        ) ENGINE=ndbcluster;
 
616
 
 
617
connection con1;
 
618
insert into t1 (datavalue) values ('newval');
 
619
insert into t1 (datavalue) values ('newval');
 
620
select * from t1 order by counter;
 
621
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
 
622
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
 
623
select * from t1 order by counter;
 
624
connection con2;
 
625
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
 
626
insert into t1 (datavalue) select datavalue from t1 where counter < 100;
 
627
select * from t1 order by counter;
 
628
 
 
629
drop table t1;
 
630
 
 
631
#
 
632
# bug#27437
 
633
connection con1;
 
634
create table t1 (a int primary key auto_increment) engine = ndb;
 
635
insert into t1() values (),(),(),(),(),(),(),(),(),(),(),();
 
636
connection con2;
 
637
insert into t1(a) values (20),(28);
 
638
connection con1;
 
639
insert into t1() values (),(),(),(),(),(),(),(),(),(),(),();
 
640
connection con2;
 
641
insert into t1() values (21), (22);
 
642
connection con1;
 
643
 
 
644
drop table t1;
 
645
 
 
646
#
 
647
# BUG#14514 Creating table with packed key fails silently
 
648
#
 
649
 
 
650
CREATE TABLE t1 ( b INT ) PACK_KEYS = 0 ENGINE = ndb;
 
651
select * from t1;
 
652
drop table t1;
 
653
 
 
654
#
 
655
# Bug #17249 delete statement with join where clause fails 
 
656
# when table do not have pk
 
657
        #
 
658
 
 
659
create table t1 (a int) engine=ndb;
 
660
create table t2 (a int) engine=ndb;
 
661
insert into t1 values (1);
 
662
insert into t2 values (1);
 
663
delete t1.* from t1, t2 where t1.a = t2.a;
 
664
select * from t1;
 
665
select * from t2;
 
666
drop table t1;
 
667
drop table t2;
 
668
 
 
669
#
 
670
# Bug #17257 update fails for inner joins if tables 
 
671
# do not have Primary Key
 
672
#
 
673
 
 
674
CREATE TABLE t1 (
 
675
  i   INT,
 
676
  j   INT,
 
677
  x   INT,
 
678
  y   INT,
 
679
  z   INT
 
680
) engine=ndb;
 
681
 
 
682
CREATE TABLE t2 (
 
683
  i   INT,
 
684
  k   INT,
 
685
  x   INT,
 
686
  y   INT,
 
687
  z   INT
 
688
) engine=ndb;
 
689
 
 
690
CREATE TABLE t3 (
 
691
  j   INT,
 
692
  k   INT,
 
693
  x   INT,
 
694
  y   INT,
 
695
  z   INT
 
696
) engine=ndb;
 
697
 
 
698
INSERT INTO t1 VALUES ( 1, 2,13,14,15);
 
699
INSERT INTO t2 VALUES ( 1, 3,23,24,25);
 
700
INSERT INTO t3 VALUES ( 2, 3, 1,34,35), ( 2, 3, 1,34,36);
 
701
 
 
702
UPDATE      t1 AS a
 
703
INNER JOIN  t2 AS b
 
704
              ON a.i = b.i
 
705
INNER JOIN  t3 AS c
 
706
              ON a.j = c.j  AND  b.k = c.k
 
707
SET         a.x = b.x,
 
708
            a.y = b.y,
 
709
            a.z = (
 
710
              SELECT  sum(z)
 
711
              FROM    t3
 
712
              WHERE   y = 34
 
713
            )
 
714
WHERE       b.x = 23;
 
715
select * from t1;
 
716
drop table t1;
 
717
drop table t2;
 
718
drop table t3;
 
719
 
 
720
# End of 4.1 tests
 
721
 
 
722
#
 
723
# Test long table name
 
724
#
 
725
create table atablewithareallylongandirritatingname (a int);
 
726
insert into atablewithareallylongandirritatingname values (2);
 
727
select * from atablewithareallylongandirritatingname;
 
728
drop table atablewithareallylongandirritatingname;
 
729
 
 
730
#
 
731
# Bug#15682
 
732
#
 
733
create table t1 (f1 varchar(50), f2 text,f3 int, primary key(f1)) engine=NDB;
 
734
insert into t1 (f1,f2,f3)VALUES("111111","aaaaaa",1);
 
735
insert into t1 (f1,f2,f3)VALUES("222222","bbbbbb",2);
 
736
select * from t1 order by f1;
 
737
select * from t1 order by f2;
 
738
select * from t1 order by f3;
 
739
drop table t1;
 
740
# Bug#16561 Unknown ERROR msg "ERROR 1186 (HY000): Binlog closed" by perror
 
741
#
 
742
 
 
743
# As long there is no error code 1186 defined by NDB
 
744
# we should get a message "Illegal ndb error code: 1186"
 
745
--error 1
 
746
--exec $MY_PERROR --ndb 1186 2>&1
 
747
 
 
748
#
 
749
# Bug #25746 - VARCHAR UTF8 PK issue
 
750
# - prior to bugfix 4209, illegal length parameter would be
 
751
# returned in SELECT *
 
752
 
 
753
CREATE TABLE t1 (
 
754
a VARBINARY(40) NOT NULL,
 
755
b VARCHAR (256) CHARACTER SET UTF8 NOT NULL,
 
756
c VARCHAR(256) CHARACTER SET UTF8 NOT NULL,
 
757
PRIMARY KEY (b,c))  ENGINE=ndbcluster;
 
758
INSERT INTO t1 VALUES
 
759
("a","ab","abc"),("b","abc","abcd"),("c","abc","ab"),("d","ab","ab"),("e","abc","abc");
 
760
SELECT * FROM t1 ORDER BY a;
 
761
DROP TABLE t1;
 
762
 
 
763
# delete
 
764
create table t1 (a int not null primary key, b int not null) engine=ndb;
 
765
create table t2 (a int not null primary key, b int not null) engine=ndb;
 
766
insert into t1 values (1,10), (2,20), (3,30);
 
767
insert into t2 values (1,10), (2,20), (3,30);
 
768
select * from t1 order by a;
 
769
delete from t1 where a > 0 order by a desc limit 1;
 
770
select * from t1 order by a;
 
771
delete from t1,t2 using t1,t2 where t1.a = t2.a;
 
772
select * from t2 order by a;
 
773
drop table t1,t2;
 
774
 
 
775
# insert ignore
 
776
create table t1 (a int not null primary key, b int not null) engine=ndb;
 
777
insert into t1 values (1,10), (2,20), (3,30);
 
778
--error ER_DUP_ENTRY
 
779
insert into t1 set a=1, b=100;
 
780
insert ignore into t1 set a=1, b=100;
 
781
select * from t1 order by a;
 
782
insert into t1 set a=1, b=1000 on duplicate key update b=b+1;
 
783
select * from t1 order by a;
 
784
drop table t1;
 
785
 
 
786
# update
 
787
create table t1 (a int not null primary key, b int not null) engine=ndb;
 
788
create table t2 (c int not null primary key, d int not null) engine=ndb;
 
789
insert into t1 values (1,10), (2,10), (3,30), (4, 30);
 
790
insert into t2 values (1,10), (2,10), (3,30), (4, 30);
 
791
--error ER_DUP_ENTRY
 
792
update t1 set a = 1 where a = 3;
 
793
select * from t1 order by a;
 
794
update t1 set b = 1 where a > 1 order by a desc limit 1;
 
795
select * from t1 order by a;
 
796
--error ER_DUP_ENTRY
 
797
update t1,t2 set a = 1, c = 1 where a = 3 and c = 3;
 
798
select * from t1 order by a;
 
799
update ignore t1,t2 set a = 1, c = 1 where a = 3 and c = 3;
 
800
select * from t1 order by a;
 
801
drop table t1,t2;
 
802
 
 
803
#
 
804
# Bug#31635
 
805
#
 
806
create table t1 (a varchar(100) primary key, b varchar(100)) engine = NDB;
 
807
insert into t1 values
 
808
  ('a', 'a'),('b','b'),('c', 'c'),('aa', 'aa'),('bb', 'bb'),('cc', 'cc');
 
809
replace into t1 values ('a', '-a');
 
810
replace into t1 values ('b', '-b');
 
811
replace into t1 values ('c', '-c');
 
812
 
 
813
replace into t1 values ('aa', '-aa');
 
814
replace into t1 values ('bb', '-bb');
 
815
replace into t1 values ('cc', '-cc');
 
816
 
 
817
replace into t1 values ('aaa', '-aaa');
 
818
replace into t1 values ('bbb', '-bbb');
 
819
replace into t1 values ('ccc', '-ccc');
 
820
select * from t1 order by 1,2;
 
821
drop table t1;
 
822
 
 
823
--echo End of 5.0 tests
 
824
 
 
825
#
 
826
# Bug #18483 Cannot create table with FK constraint
 
827
# ndb does not support foreign key constraint, it is silently ignored
 
828
# in line with other storage engines
 
829
#
 
830
CREATE TABLE t1 (a VARCHAR(255) NOT NULL,
 
831
                 CONSTRAINT pk_a PRIMARY KEY (a))engine=ndb;
 
832
CREATE TABLE t2(a VARCHAR(255) NOT NULL,
 
833
                b VARCHAR(255) NOT NULL,
 
834
                c VARCHAR(255) NOT NULL,
 
835
                CONSTRAINT pk_b_c_id PRIMARY KEY (b,c),
 
836
                CONSTRAINT fk_a FOREIGN KEY(a) REFERENCES t1(a))engine=ndb;
 
837
drop table t1, t2;
 
838
 
 
839
# bug#24301
 
840
create table t1 (a int not null primary key, b int) engine=ndb;
 
841
insert into t1 values(1,1),(2,2),(3,3);
 
842
create table t2 like t1;
 
843
insert into t2 select * from t1;
 
844
select * from t1 order by a;
 
845
select * from t2 order by a;
 
846
drop table t1, t2;
 
847
 
 
848
# create table if not exists
 
849
--disable_warnings
 
850
create table t1 (a int not null primary key, b int not null default 0, c varchar(254)) engine=ndb;
 
851
create table if not exists t1 (a int not null primary key, b int not null default 0, c varchar(254)) engine=ndb;
 
852
--enable_warnings
 
853
 
 
854
# create like
 
855
create table t2 like t1;
 
856
 
 
857
# multi rename
 
858
rename table t1 to t10, t2 to t20;
 
859
drop table t10,t20;
 
860
 
 
861
--echo End of 5.1 tests