~vkolesnikov/pbxt/pbxt-07-diskfull

« back to all changes in this revision

Viewing changes to pbxt/mysql-test-update/mysql-test/r/merge.result

  • Committer: paul-mccullagh
  • Date: 2006-10-23 09:14:04 UTC
  • Revision ID: paul-mccullagh-918861e03d351978a9541168a96e58cc826734ee
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
drop table if exists t1,t2,t3,t4,t5,t6;
 
2
drop database if exists mysqltest;
 
3
create table t1 (a int not null primary key auto_increment, message char(20));
 
4
create table t2 (a int not null primary key auto_increment, message char(20));
 
5
INSERT INTO t1 (message) VALUES ("Testing"),("table"),("t1");
 
6
INSERT INTO t2 (message) VALUES ("Testing"),("table"),("t2");
 
7
create table t3 (a int not null, b char(20), key(a)) engine=MERGE UNION=(t1,t2);
 
8
select * from t3;
 
9
a       b
 
10
1       Testing
 
11
2       table
 
12
3       t1
 
13
1       Testing
 
14
2       table
 
15
3       t2
 
16
select * from t3 order by a desc;
 
17
a       b
 
18
3       t1
 
19
3       t2
 
20
2       table
 
21
2       table
 
22
1       Testing
 
23
1       Testing
 
24
drop table t3;
 
25
insert into t1 select NULL,message from t2;
 
26
insert into t2 select NULL,message from t1;
 
27
insert into t1 select NULL,message from t2;
 
28
insert into t2 select NULL,message from t1;
 
29
insert into t1 select NULL,message from t2;
 
30
insert into t2 select NULL,message from t1;
 
31
insert into t1 select NULL,message from t2;
 
32
insert into t2 select NULL,message from t1;
 
33
insert into t1 select NULL,message from t2;
 
34
insert into t2 select NULL,message from t1;
 
35
insert into t1 select NULL,message from t2;
 
36
create table t3 (a int not null, b char(20), key(a)) engine=MERGE UNION=(test.t1,test.t2);
 
37
explain select * from t3 where a < 10;
 
38
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
39
1       SIMPLE  t3      range   a       a       4       NULL    18      Using where
 
40
explain select * from t3 where a > 10 and a < 20;
 
41
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
42
1       SIMPLE  t3      range   a       a       4       NULL    17      Using where
 
43
select * from t3 where a = 10;
 
44
a       b
 
45
10      Testing
 
46
10      Testing
 
47
select * from t3 where a < 10;
 
48
a       b
 
49
1       Testing
 
50
1       Testing
 
51
2       table
 
52
2       table
 
53
3       t1
 
54
3       t2
 
55
4       Testing
 
56
4       Testing
 
57
5       table
 
58
5       table
 
59
6       t2
 
60
6       t1
 
61
7       Testing
 
62
7       Testing
 
63
8       table
 
64
8       table
 
65
9       t2
 
66
9       t2
 
67
select * from t3 where a > 10 and a < 20;
 
68
a       b
 
69
11      table
 
70
11      table
 
71
12      t1
 
72
12      t1
 
73
13      Testing
 
74
13      Testing
 
75
14      table
 
76
14      table
 
77
15      t2
 
78
15      t2
 
79
16      Testing
 
80
16      Testing
 
81
17      table
 
82
17      table
 
83
18      t2
 
84
18      t2
 
85
19      Testing
 
86
19      Testing
 
87
explain select a from t3 order by a desc limit 10;
 
88
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
89
1       SIMPLE  t3      index   NULL    a       4       NULL    1131    Using index
 
90
select a from t3 order by a desc limit 10;
 
91
a
 
92
699
 
93
698
 
94
697
 
95
696
 
96
695
 
97
694
 
98
693
 
99
692
 
100
691
 
101
690
 
102
select a from t3 order by a desc limit 300,10;
 
103
a
 
104
416
 
105
415
 
106
415
 
107
414
 
108
414
 
109
413
 
110
413
 
111
412
 
112
412
 
113
411
 
114
delete from t3 where a=3;
 
115
select * from t3 where a < 10;
 
116
a       b
 
117
1       Testing
 
118
1       Testing
 
119
2       table
 
120
2       table
 
121
4       Testing
 
122
4       Testing
 
123
5       table
 
124
5       table
 
125
6       t2
 
126
6       t1
 
127
7       Testing
 
128
7       Testing
 
129
8       table
 
130
8       table
 
131
9       t2
 
132
9       t2
 
133
delete from t3 where a >= 6 and a <= 8;
 
134
select * from t3 where a < 10;
 
135
a       b
 
136
1       Testing
 
137
1       Testing
 
138
2       table
 
139
2       table
 
140
4       Testing
 
141
4       Testing
 
142
5       table
 
143
5       table
 
144
9       t2
 
145
9       t2
 
146
update t3 set a=3 where a=9;
 
147
select * from t3 where a < 10;
 
148
a       b
 
149
1       Testing
 
150
1       Testing
 
151
2       table
 
152
2       table
 
153
3       t2
 
154
3       t2
 
155
4       Testing
 
156
4       Testing
 
157
5       table
 
158
5       table
 
159
update t3 set a=6 where a=7;
 
160
select * from t3 where a < 10;
 
161
a       b
 
162
1       Testing
 
163
1       Testing
 
164
2       table
 
165
2       table
 
166
3       t2
 
167
3       t2
 
168
4       Testing
 
169
4       Testing
 
170
5       table
 
171
5       table
 
172
show create table t3;
 
173
Table   Create Table
 
174
t3      CREATE TABLE `t3` (
 
175
  `a` int(11) NOT NULL,
 
176
  `b` char(20) DEFAULT NULL,
 
177
  KEY `a` (`a`)
 
178
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`)
 
179
create table t4 (a int not null, b char(10), key(a)) engine=MERGE UNION=(t1,t2);
 
180
select * from t4;
 
181
ERROR HY000: All tables in the MERGE table are not identically defined
 
182
alter table t4 add column c int;
 
183
ERROR HY000: All tables in the MERGE table are not identically defined
 
184
flush tables;
 
185
select * from t4;
 
186
ERROR HY000: All tables in the MERGE table are not identically defined
 
187
create database mysqltest;
 
188
create table mysqltest.t6 (a int not null primary key auto_increment, message char(20));
 
189
create table t5 (a int not null, b char(20), key(a)) engine=MERGE UNION=(test.t1,mysqltest.t6);
 
190
show create table t5;
 
191
Table   Create Table
 
192
t5      CREATE TABLE `t5` (
 
193
  `a` int(11) NOT NULL,
 
194
  `b` char(20) DEFAULT NULL,
 
195
  KEY `a` (`a`)
 
196
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`mysqltest`.`t6`)
 
197
alter table t5 engine=myisam;
 
198
drop table t5, mysqltest.t6;
 
199
drop database mysqltest;
 
200
drop table t4,t3,t1,t2;
 
201
create table t1 (c char(10)) engine=myisam;
 
202
create table t2 (c char(10)) engine=myisam;
 
203
create table t3 (c char(10)) union=(t1,t2) engine=merge;
 
204
insert into t1 (c) values ('test1');
 
205
insert into t1 (c) values ('test1');
 
206
insert into t1 (c) values ('test1');
 
207
insert into t2 (c) values ('test2');
 
208
insert into t2 (c) values ('test2');
 
209
insert into t2 (c) values ('test2');
 
210
select * from t3;
 
211
c
 
212
test1
 
213
test1
 
214
test1
 
215
test2
 
216
test2
 
217
test2
 
218
select * from t3;
 
219
c
 
220
test1
 
221
test1
 
222
test1
 
223
test2
 
224
test2
 
225
test2
 
226
delete from t3 where 1=1;
 
227
select * from t3;
 
228
c
 
229
select * from t1;
 
230
c
 
231
drop table t3,t2,t1;
 
232
CREATE TABLE t1 (incr int not null, othr int not null, primary key(incr));
 
233
CREATE TABLE t2 (incr int not null, othr int not null, primary key(incr));
 
234
CREATE TABLE t3 (incr int not null, othr int not null, primary key(incr))
 
235
ENGINE=MERGE UNION=(t1,t2);
 
236
SELECT * from t3;
 
237
incr    othr
 
238
INSERT INTO t1 VALUES ( 1,10),( 3,53),( 5,21),( 7,12),( 9,17);
 
239
INSERT INTO t2 VALUES ( 2,24),( 4,33),( 6,41),( 8,26),( 0,32);
 
240
INSERT INTO t1 VALUES (11,20),(13,43),(15,11),(17,22),(19,37);
 
241
INSERT INTO t2 VALUES (12,25),(14,31),(16,42),(18,27),(10,30);
 
242
SELECT * from t3 where incr in (1,2,3,4) order by othr;
 
243
incr    othr
 
244
1       10
 
245
2       24
 
246
4       33
 
247
3       53
 
248
alter table t3 UNION=(t1);
 
249
select count(*) from t3;
 
250
count(*)
 
251
10
 
252
alter table t3 UNION=(t1,t2);
 
253
select count(*) from t3;
 
254
count(*)
 
255
20
 
256
alter table t3 ENGINE=MYISAM;
 
257
select count(*) from t3;
 
258
count(*)
 
259
20
 
260
drop table t3;
 
261
CREATE TABLE t3 (incr int not null, othr int not null, primary key(incr))
 
262
ENGINE=MERGE UNION=(t1,t2);
 
263
show create table t3;
 
264
Table   Create Table
 
265
t3      CREATE TABLE `t3` (
 
266
  `incr` int(11) NOT NULL,
 
267
  `othr` int(11) NOT NULL,
 
268
  PRIMARY KEY (`incr`)
 
269
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`)
 
270
alter table t3 drop primary key;
 
271
show create table t3;
 
272
Table   Create Table
 
273
t3      CREATE TABLE `t3` (
 
274
  `incr` int(11) NOT NULL,
 
275
  `othr` int(11) NOT NULL
 
276
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`)
 
277
drop table t3,t2,t1;
 
278
create table t1 (a int not null, key(a)) engine=merge;
 
279
select * from t1;
 
280
a
 
281
drop table t1;
 
282
create table t1 (a int not null, b int not null, key(a,b));
 
283
create table t2 (a int not null, b int not null, key(a,b));
 
284
create table t3 (a int not null, b int not null, key(a,b)) ENGINE=MERGE UNION=(t1,t2);
 
285
insert into t1 values (1,2),(2,1),(0,0),(4,4),(5,5),(6,6);
 
286
insert into t2 values (1,1),(2,2),(0,0),(4,4),(5,5),(6,6);
 
287
flush tables;
 
288
select * from t3 where a=1 order by b limit 2;
 
289
a       b
 
290
1       1
 
291
1       2
 
292
drop table t3,t1,t2;
 
293
create table t1 (a int not null, b int not null auto_increment, primary key(a,b));
 
294
create table t2 (a int not null, b int not null auto_increment, primary key(a,b));
 
295
create table t3 (a int not null, b int not null, key(a,b)) UNION=(t1,t2) INSERT_METHOD=NO;
 
296
create table t4 (a int not null, b int not null, key(a,b)) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=NO;
 
297
create table t5 (a int not null, b int not null auto_increment, primary key(a,b)) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=FIRST;
 
298
create table t6 (a int not null, b int not null auto_increment, primary key(a,b)) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;
 
299
show create table t3;
 
300
Table   Create Table
 
301
t3      CREATE TABLE `t3` (
 
302
  `a` int(11) NOT NULL,
 
303
  `b` int(11) NOT NULL,
 
304
  KEY `a` (`a`,`b`)
 
305
) ENGINE=PBXT DEFAULT CHARSET=latin1
 
306
show create table t4;
 
307
Table   Create Table
 
308
t4      CREATE TABLE `t4` (
 
309
  `a` int(11) NOT NULL,
 
310
  `b` int(11) NOT NULL,
 
311
  KEY `a` (`a`,`b`)
 
312
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`)
 
313
show create table t5;
 
314
Table   Create Table
 
315
t5      CREATE TABLE `t5` (
 
316
  `a` int(11) NOT NULL,
 
317
  `b` int(11) NOT NULL AUTO_INCREMENT,
 
318
  PRIMARY KEY (`a`,`b`)
 
319
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=FIRST UNION=(`t1`,`t2`)
 
320
show create table t6;
 
321
Table   Create Table
 
322
t6      CREATE TABLE `t6` (
 
323
  `a` int(11) NOT NULL,
 
324
  `b` int(11) NOT NULL AUTO_INCREMENT,
 
325
  PRIMARY KEY (`a`,`b`)
 
326
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`)
 
327
insert into t1 values (1,NULL),(1,NULL),(1,NULL),(1,NULL);
 
328
insert into t2 values (2,NULL),(2,NULL),(2,NULL),(2,NULL);
 
329
select * from t3 order by b,a limit 3;
 
330
a       b
 
331
select * from t4 order by b,a limit 3;
 
332
a       b
 
333
1       1
 
334
2       1
 
335
1       2
 
336
select * from t5 order by b,a limit 3,3;
 
337
a       b
 
338
2       2
 
339
1       3
 
340
2       3
 
341
select * from t6 order by b,a limit 6,3;
 
342
a       b
 
343
1       4
 
344
2       4
 
345
insert into t5 values (5,1),(5,2);
 
346
insert into t6 values (6,1),(6,2);
 
347
select * from t1 order by a,b;
 
348
a       b
 
349
1       1
 
350
1       2
 
351
1       3
 
352
1       4
 
353
5       1
 
354
5       2
 
355
select * from t2 order by a,b;
 
356
a       b
 
357
2       1
 
358
2       2
 
359
2       3
 
360
2       4
 
361
6       1
 
362
6       2
 
363
select * from t4 order by a,b;
 
364
a       b
 
365
1       1
 
366
1       2
 
367
1       3
 
368
1       4
 
369
2       1
 
370
2       2
 
371
2       3
 
372
2       4
 
373
5       1
 
374
5       2
 
375
6       1
 
376
6       2
 
377
insert into t3 values (3,1),(3,2),(3,3),(3,4);
 
378
select * from t3 order by a,b;
 
379
a       b
 
380
3       1
 
381
3       2
 
382
3       3
 
383
3       4
 
384
alter table t4 UNION=(t1,t2,t3);
 
385
show create table t4;
 
386
Table   Create Table
 
387
t4      CREATE TABLE `t4` (
 
388
  `a` int(11) NOT NULL,
 
389
  `b` int(11) NOT NULL,
 
390
  KEY `a` (`a`,`b`)
 
391
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`,`t2`,`t3`)
 
392
select * from t4 order by a,b;
 
393
a       b
 
394
1       1
 
395
1       2
 
396
1       3
 
397
1       4
 
398
2       1
 
399
2       2
 
400
2       3
 
401
2       4
 
402
3       1
 
403
3       2
 
404
3       3
 
405
3       4
 
406
5       1
 
407
5       2
 
408
6       1
 
409
6       2
 
410
alter table t4 INSERT_METHOD=FIRST;
 
411
show create table t4;
 
412
Table   Create Table
 
413
t4      CREATE TABLE `t4` (
 
414
  `a` int(11) NOT NULL,
 
415
  `b` int(11) NOT NULL,
 
416
  KEY `a` (`a`,`b`)
 
417
) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=FIRST UNION=(`t1`,`t2`,`t3`)
 
418
insert into t4 values (4,1),(4,2);
 
419
select * from t1 order by a,b;
 
420
a       b
 
421
1       1
 
422
1       2
 
423
1       3
 
424
1       4
 
425
4       1
 
426
4       2
 
427
5       1
 
428
5       2
 
429
select * from t2 order by a,b;
 
430
a       b
 
431
2       1
 
432
2       2
 
433
2       3
 
434
2       4
 
435
6       1
 
436
6       2
 
437
select * from t3 order by a,b;
 
438
a       b
 
439
3       1
 
440
3       2
 
441
3       3
 
442
3       4
 
443
select * from t4 order by a,b;
 
444
a       b
 
445
1       1
 
446
1       2
 
447
1       3
 
448
1       4
 
449
2       1
 
450
2       2
 
451
2       3
 
452
2       4
 
453
3       1
 
454
3       2
 
455
3       3
 
456
3       4
 
457
4       1
 
458
4       2
 
459
5       1
 
460
5       2
 
461
6       1
 
462
6       2
 
463
select * from t5 order by a,b;
 
464
a       b
 
465
1       1
 
466
1       2
 
467
1       3
 
468
1       4
 
469
2       1
 
470
2       2
 
471
2       3
 
472
2       4
 
473
4       1
 
474
4       2
 
475
5       1
 
476
5       2
 
477
6       1
 
478
6       2
 
479
select 1;
 
480
1
 
481
1
 
482
insert into t5 values (1,NULL),(5,NULL);
 
483
insert into t6 values (2,NULL),(6,NULL);
 
484
select * from t1 order by a,b;
 
485
a       b
 
486
1       1
 
487
1       2
 
488
1       3
 
489
1       4
 
490
1       5
 
491
4       1
 
492
4       2
 
493
5       1
 
494
5       2
 
495
5       3
 
496
select * from t2 order by a,b;
 
497
a       b
 
498
2       1
 
499
2       2
 
500
2       3
 
501
2       4
 
502
2       5
 
503
6       1
 
504
6       2
 
505
6       3
 
506
select * from t5 order by a,b;
 
507
a       b
 
508
1       1
 
509
1       2
 
510
1       3
 
511
1       4
 
512
1       5
 
513
2       1
 
514
2       2
 
515
2       3
 
516
2       4
 
517
2       5
 
518
4       1
 
519
4       2
 
520
5       1
 
521
5       2
 
522
5       3
 
523
6       1
 
524
6       2
 
525
6       3
 
526
select * from t6 order by a,b;
 
527
a       b
 
528
1       1
 
529
1       2
 
530
1       3
 
531
1       4
 
532
1       5
 
533
2       1
 
534
2       2
 
535
2       3
 
536
2       4
 
537
2       5
 
538
4       1
 
539
4       2
 
540
5       1
 
541
5       2
 
542
5       3
 
543
6       1
 
544
6       2
 
545
6       3
 
546
insert into t1 values (99,NULL);
 
547
select * from t4 where a+0 > 90;
 
548
a       b
 
549
99      1
 
550
insert t5 values (1,1);
 
551
ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
 
552
insert t6 values (2,1);
 
553
ERROR 23000: Duplicate entry '2-1' for key 'PRIMARY'
 
554
insert t5 values (1,1) on duplicate key update b=b+10;
 
555
insert t6 values (2,1) on duplicate key update b=b+20;
 
556
select * from t5 where a < 3;
 
557
a       b
 
558
1       2
 
559
1       3
 
560
1       4
 
561
1       5
 
562
1       11
 
563
2       2
 
564
2       3
 
565
2       4
 
566
2       5
 
567
2       21
 
568
drop table t6, t5, t4, t3, t2, t1;
 
569
CREATE TABLE t1 (  a int(11) NOT NULL default '0',  b int(11) NOT NULL default '0',  PRIMARY KEY  (a,b)) ENGINE=MyISAM;
 
570
INSERT INTO t1 VALUES (1,1), (2,1);
 
571
CREATE TABLE t2 (  a int(11) NOT NULL default '0',  b int(11) NOT NULL default '0',  PRIMARY KEY  (a,b)) ENGINE=MyISAM;
 
572
INSERT INTO t2 VALUES (1,2), (2,2);
 
573
CREATE TABLE t3 (  a int(11) NOT NULL default '0',  b int(11) NOT NULL default '0',  KEY a (a,b)) ENGINE=MRG_MyISAM UNION=(t1,t2);
 
574
select max(b) from t3 where a = 2;
 
575
max(b)
 
576
2
 
577
select max(b) from t1 where a = 2;
 
578
max(b)
 
579
1
 
580
drop table t3,t1,t2;
 
581
create table t1 (a int not null);
 
582
create table t2 (a int not null);
 
583
insert into t1 values (1);
 
584
insert into t2 values (2);
 
585
create temporary table t3 (a int not null) ENGINE=MERGE UNION=(t1,t2);
 
586
select * from t3;
 
587
a
 
588
1
 
589
2
 
590
create temporary table t4 (a int not null);
 
591
create temporary table t5 (a int not null);
 
592
insert into t4 values (1);
 
593
insert into t5 values (2);
 
594
create temporary table t6 (a int not null) ENGINE=MERGE UNION=(t4,t5);
 
595
select * from t6;
 
596
a
 
597
1
 
598
2
 
599
drop table t6, t3, t1, t2, t4, t5;
 
600
CREATE TABLE t1 (
 
601
fileset_id tinyint(3) unsigned NOT NULL default '0',
 
602
file_code varchar(32) NOT NULL default '',
 
603
fileset_root_id tinyint(3) unsigned NOT NULL default '0',
 
604
PRIMARY KEY  (fileset_id,file_code),
 
605
KEY files (fileset_id,fileset_root_id)
 
606
) ENGINE=MyISAM;
 
607
INSERT INTO t1 VALUES (2, '0000000111', 1), (2, '0000000112', 1), (2, '0000000113', 1),
 
608
(2, '0000000114', 1), (2, '0000000115', 1), (2, '0000000116', 1), (2, '0000000117', 1),
 
609
(2, '0000000118', 1), (2, '0000000119', 1), (2, '0000000120', 1);
 
610
CREATE TABLE t2 (
 
611
fileset_id tinyint(3) unsigned NOT NULL default '0',
 
612
file_code varchar(32) NOT NULL default '',
 
613
fileset_root_id tinyint(3) unsigned NOT NULL default '0',
 
614
PRIMARY KEY  (fileset_id,file_code),
 
615
KEY files (fileset_id,fileset_root_id)
 
616
) ENGINE=MRG_MyISAM UNION=(t1);
 
617
EXPLAIN SELECT * FROM t2 IGNORE INDEX (files) WHERE fileset_id = 2
 
618
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
 
619
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
620
1       SIMPLE  t2      range   PRIMARY PRIMARY 35      NULL    5       Using where
 
621
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
 
622
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
 
623
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
624
1       SIMPLE  t2      range   PRIMARY,files   PRIMARY 35      NULL    5       Using where
 
625
EXPLAIN SELECT * FROM t1 WHERE fileset_id = 2
 
626
AND file_code BETWEEN '0000000115' AND '0000000120' LIMIT 1;
 
627
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
628
1       SIMPLE  t1      range   PRIMARY,files   PRIMARY 35      NULL    5       Using where
 
629
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
 
630
AND file_code = '0000000115' LIMIT 1;
 
631
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
632
1       SIMPLE  t2      ref     PRIMARY,files   PRIMARY 35      const,const     1       Using where
 
633
DROP TABLE t2, t1;
 
634
create table t1 (x int, y int, index xy(x, y));
 
635
create table t2 (x int, y int, index xy(x, y));
 
636
create table t3 (x int, y int, index xy(x, y)) engine=merge union=(t1,t2);
 
637
insert into t1 values(1, 2);
 
638
insert into t2 values(1, 3);
 
639
select * from t3 where x = 1 and y < 5 order by y;
 
640
x       y
 
641
1       2
 
642
1       3
 
643
select * from t3 where x = 1 and y < 5 order by y desc;
 
644
x       y
 
645
1       3
 
646
1       2
 
647
drop table t1,t2,t3;
 
648
create table t1 (a int);
 
649
create table t2 (a int);
 
650
insert into t1 values (0);
 
651
insert into t2 values (1);
 
652
create table t3 engine=merge union=(t1, t2) select * from t1;
 
653
ERROR HY000: You can't specify target table 't1' for update in FROM clause
 
654
create table t3 engine=merge union=(t1, t2) select * from t2;
 
655
ERROR HY000: You can't specify target table 't2' for update in FROM clause
 
656
create table t3 engine=merge union=(t1, t2) select (select max(a) from t2);
 
657
ERROR HY000: You can't specify target table 't2' for update in FROM clause
 
658
drop table t1, t2;
 
659
create table t1 (
 
660
a double(14,4),
 
661
b varchar(10),
 
662
index (a,b)
 
663
) engine=merge union=(t2,t3);
 
664
create table t2 (
 
665
a double(14,4),
 
666
b varchar(10),
 
667
index (a,b)
 
668
) engine=myisam;
 
669
create table t3 (
 
670
a double(14,4),
 
671
b varchar(10),
 
672
index (a,b)
 
673
) engine=myisam;
 
674
insert into t2 values ( null, '');
 
675
insert into t2 values ( 9999999999.999, '');
 
676
insert into t3 select * from t2;
 
677
select min(a), max(a) from t1;
 
678
min(a)  max(a)
 
679
9999999999.9990 9999999999.9990
 
680
flush tables;
 
681
select min(a), max(a) from t1;
 
682
min(a)  max(a)
 
683
9999999999.9990 9999999999.9990
 
684
drop table t1, t2, t3;
 
685
create table t1 (a int,b int,c int, index (a,b,c));
 
686
create table t2 (a int,b int,c int, index (a,b,c));
 
687
create table t3 (a int,b int,c int, index (a,b,c))
 
688
engine=merge union=(t1 ,t2);
 
689
insert into t1 (a,b,c) values (1,1,0),(1,2,0);
 
690
insert into t2 (a,b,c) values (1,1,1),(1,2,1);
 
691
explain select a,b,c from t3 force index (a) where a=1 order by a,b,c;
 
692
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
693
1       SIMPLE  t3      ref     a       a       5       const   2       Using where; Using index
 
694
select a,b,c from t3 force index (a) where a=1 order by a,b,c;
 
695
a       b       c
 
696
1       1       0
 
697
1       1       1
 
698
1       2       0
 
699
1       2       1
 
700
explain select a,b,c from t3 force index (a) where a=1 order by a desc, b desc, c desc;
 
701
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
702
1       SIMPLE  t3      ref     a       a       5       const   2       Using where; Using index
 
703
select a,b,c from t3 force index (a) where a=1 order by a desc, b desc, c desc;
 
704
a       b       c
 
705
1       2       1
 
706
1       2       0
 
707
1       1       1
 
708
1       1       0
 
709
show index from t3;
 
710
Table   Non_unique      Key_name        Seq_in_index    Column_name     Collation       Cardinality     Sub_part        Packed  Null    Index_type      Comment
 
711
t3      1       a       1       a       A       NULL    NULL    NULL    YES     BTREE   
 
712
t3      1       a       2       b       A       NULL    NULL    NULL    YES     BTREE   
 
713
t3      1       a       3       c       A       NULL    NULL    NULL    YES     BTREE   
 
714
drop table t1, t2, t3;
 
715
CREATE TABLE t1 ( a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), UNIQUE (b) )
 
716
ENGINE=MyISAM;
 
717
CREATE TABLE t2 ( a INT AUTO_INCREMENT, b VARCHAR(10), INDEX (a), INDEX (b) )
 
718
ENGINE=MERGE UNION (t1) INSERT_METHOD=FIRST;
 
719
INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=2;
 
720
INSERT INTO t2 (b) VALUES (1) ON DUPLICATE KEY UPDATE b=3;
 
721
SELECT b FROM t2;
 
722
b
 
723
3
 
724
DROP TABLE t1, t2;
 
725
create table t1(a int);
 
726
create table t2(a int);
 
727
insert into t1 values (1);
 
728
insert into t2 values (2);
 
729
create table t3 (a int) engine=merge union=(t1, t2) insert_method=first;
 
730
select * from t3;
 
731
a
 
732
1
 
733
2
 
734
insert t2 select * from t2;
 
735
select * from t2;
 
736
a
 
737
2
 
738
2
 
739
insert t3 select * from t1;
 
740
select * from t3;
 
741
a
 
742
1
 
743
1
 
744
2
 
745
2
 
746
insert t1 select * from t3;
 
747
select * from t1;
 
748
a
 
749
1
 
750
1
 
751
1
 
752
1
 
753
2
 
754
2
 
755
select * from t2;
 
756
a
 
757
2
 
758
2
 
759
select * from t3;
 
760
a
 
761
1
 
762
1
 
763
1
 
764
1
 
765
2
 
766
2
 
767
2
 
768
2
 
769
check table t1, t2;
 
770
Table   Op      Msg_type        Msg_text
 
771
test.t1 check   status  OK
 
772
test.t2 check   status  OK
 
773
drop table t1, t2, t3;
 
774
create table t1 (b bit(1));
 
775
create table t2 (b bit(1));
 
776
create table tm (b bit(1)) engine = merge union = (t1,t2);
 
777
select * from tm;
 
778
b
 
779
drop table tm, t1, t2;
 
780
create table t1 (a int) insert_method = last engine = merge;
 
781
insert into t1 values (1);
 
782
ERROR HY000: Table 't1' is read only
 
783
create table t2 (a int) engine = myisam;
 
784
alter table t1 union (t2);
 
785
insert into t1 values (1);
 
786
alter table t1 insert_method = no;
 
787
insert into t1 values (1);
 
788
ERROR HY000: Table 't1' is read only
 
789
drop table t2;
 
790
drop table t1;
 
791
End of 5.0 tests