summaryrefslogtreecommitdiff
path: root/mysql-test/main/partition_innodb.test
blob: ae0ce59fabc3613571ab5040b5a0e298a886222d (plain)
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
--source include/not_embedded.inc
--source include/have_partition.inc
--source include/have_innodb.inc

call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction");

set global default_storage_engine='innodb';
set session default_storage_engine='innodb';

set @innodb_stats_persistent_save= @@innodb_stats_persistent;
set @innodb_stats_persistent_sample_pages_save=
      @@innodb_stats_persistent_sample_pages;

set global innodb_stats_persistent= 1;
set global innodb_stats_persistent_sample_pages=100;

--disable_warnings
drop table if exists t1, t2;
--enable_warnings

let $MYSQLD_DATADIR= `SELECT @@datadir`;

--echo #
--echo # Bug#13694811: THE OPTIMIZER WRONGLY USES THE FIRST
--echo #               INNODB PARTITION STATISTICS
--echo #

CREATE TABLE t1
(a INT,
 b varchar(64),
 PRIMARY KEY (a),
 KEY (b))
ENGINE = InnoDB
PARTITION BY RANGE (a)
SUBPARTITION BY HASH (a) SUBPARTITIONS 10
(PARTITION pNeg VALUES LESS THAN (0),
 PARTITION p0 VALUES LESS THAN (1000),
 PARTITION pMAX VALUES LESS THAN MAXVALUE);

--echo # Only one row in the first 10 subpartitions
INSERT INTO t1 VALUES (-1, 'Only negative pk value');

INSERT INTO t1 VALUES (0, 'Mod Zero'), (1, 'One'), (2, 'Two'), (3, 'Three'),
(10, 'Zero'), (11, 'Mod One'), (12, 'Mod Two'), (13, 'Mod Three'),
(20, '0'), (21, '1'), (22, '2'), (23, '3'),
(4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8'), (9, '9');
INSERT INTO t1 SELECT a + 30, b FROM t1 WHERE a >= 0;
INSERT INTO t1 SELECT a + 60, b FROM t1 WHERE a >= 0;
INSERT INTO t1 SELECT a + 120, b FROM t1 WHERE a >= 0;
INSERT INTO t1 SELECT a + 240, b FROM t1 WHERE a >= 0;
ANALYZE TABLE t1;
EXPLAIN SELECT b FROM t1 WHERE b between 'L' and 'N' AND a > -100;
DROP TABLE t1;

--echo #
--echo # Bug#13007154: Crash in keys_to_use_for_scanning with ORDER BY
--echo #               and PARTITIONING
--echo #
CREATE TABLE t1 (a INT, KEY(a))
ENGINE = InnoDB
PARTITION BY KEY (a) PARTITIONS 1;
SELECT 1 FROM t1 WHERE a > (SELECT LAST_INSERT_ID() FROM t1 LIMIT 0)
ORDER BY a;
DROP TABLE t1;

--echo #
--echo # Bug#56287: crash when using Partition datetime in sub in query
--echo #

CREATE TABLE t1
(c1 bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 c2 varchar(40) not null default '',
 c3 datetime not  NULL,
 PRIMARY KEY (c1,c3),
 KEY partidx(c3))
ENGINE=InnoDB
PARTITION BY RANGE (TO_DAYS(c3))
(PARTITION p200912 VALUES LESS THAN (to_days('2010-01-01')),
 PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
 PARTITION p201912 VALUES LESS THAN MAXVALUE);

insert into t1(c2,c3) values ("Test row",'2010-01-01 00:00:00');

SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'test';
SELECT count(*) FROM t1 p where c3 in
(select c3 from t1 t where t.c3 < timestamp '2011-04-26 19:19:44'
 and t.c3 > timestamp '2011-04-26 19:18:44') ;

DROP TABLE t1;


--echo #
--echo # Bug#54747: Deadlock between REORGANIZE PARTITION and
--echo #            SELECT is not detected
--echo #

SET @old_innodb_thread_concurrency := @@innodb_thread_concurrency;
SET @old_innodb_thread_sleep_delay := @@innodb_thread_sleep_delay;
SET GLOBAL innodb_thread_concurrency = 1;

CREATE TABLE t1
(user_num BIGINT,
 hours SMALLINT,
 KEY user_num (user_num))
ENGINE = InnoDB   
PARTITION BY RANGE COLUMNS (hours)
(PARTITION hour_003 VALUES LESS THAN (3),
 PARTITION hour_004 VALUES LESS THAN (4),
 PARTITION hour_005 VALUES LESS THAN (5),
 PARTITION hour_last VALUES LESS THAN (MAXVALUE));

INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);

BEGIN;
SELECT COUNT(*) FROM t1;

--connect (con1,localhost,root,,)
--echo # SEND a ALTER PARTITION which waits on the ongoing transaction.
--send
ALTER TABLE t1
REORGANIZE PARTITION hour_003, hour_004 INTO
(PARTITION oldest VALUES LESS THAN (4));

--echo # Connection default wait until the ALTER is in 'waiting for table...'
--echo # state and then continue the transaction by trying a SELECT
--connection default
let $wait_condition =
SELECT COUNT(*) = 1
FROM information_schema.processlist
WHERE INFO like 'ALTER TABLE t1%REORGANIZE PARTITION hour_003, hour_004%'
AND STATE = 'Waiting for table metadata lock';
--source include/wait_condition.inc
SELECT COUNT(*) FROM t1;
COMMIT;

--echo # reaping ALTER.
--connection con1
--reap

--echo # Cleaning up.
--disconnect con1

--connection default

SET GLOBAL innodb_thread_concurrency = @old_innodb_thread_concurrency;
SET GLOBAL innodb_thread_sleep_delay = @old_innodb_thread_sleep_delay;
DROP TABLE t1;


--echo #
--echo # Bug#50418: DROP PARTITION does not interact with transactions
--echo #
CREATE TABLE t1 (
    id INT AUTO_INCREMENT NOT NULL,
    name CHAR(50) NOT NULL,
    myDate DATE NOT NULL,
    PRIMARY KEY (id, myDate),
    INDEX idx_date (myDate)
    ) ENGINE=InnoDB
PARTITION BY RANGE ( TO_DAYS(myDate) ) (
    PARTITION p0 VALUES LESS THAN (734028),
    PARTITION p1 VALUES LESS THAN (734029),
    PARTITION p2 VALUES LESS THAN (734030),
    PARTITION p3 VALUES LESS THAN MAXVALUE
    ) ;
INSERT INTO t1 VALUES 
(NULL, 'Lachlan', '2009-09-13'),
  (NULL, 'Clint', '2009-09-13'),
  (NULL, 'John', '2009-09-14'),
  (NULL, 'Dave', '2009-09-14'),
  (NULL, 'Jeremy', '2009-09-15'),
  (NULL, 'Scott', '2009-09-15'),
  (NULL, 'Jeff', '2009-09-16'),
  (NULL, 'Joe', '2009-09-16');
SET AUTOCOMMIT=0;
SELECT * FROM t1 FOR UPDATE;
UPDATE t1 SET name = 'Mattias' WHERE id = 7;
SELECT * FROM t1 WHERE id = 7;
--connect (con1, localhost, root,,)
SET lock_wait_timeout = 1;
--echo # After the patch it will wait and fail on timeout.
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 DROP PARTITION p3;
SHOW WARNINGS;
--disconnect con1
--connection default
SELECT * FROM t1;
--echo # No changes.
COMMIT;
DROP TABLE t1;


--echo #
--echo # Bug#51830: Incorrect partition pruning on range partition (regression)
--echo #
CREATE TABLE t1 (a INT NOT NULL)
ENGINE = InnoDB
PARTITION BY RANGE(a)
(PARTITION p10 VALUES LESS THAN (10),
 PARTITION p30 VALUES LESS THAN (30),
 PARTITION p50 VALUES LESS THAN (50),
 PARTITION p70 VALUES LESS THAN (70),
 PARTITION p90 VALUES LESS THAN (90));
INSERT INTO t1 VALUES (10),(30),(50);
INSERT INTO t1 VALUES (70);
INSERT INTO t1 VALUES (80);
INSERT INTO t1 VALUES (89);
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
INSERT INTO t1 VALUES (90);
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
INSERT INTO t1 VALUES (100);
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
insert INTO t1 VALUES (110);
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 90;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 90;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 90;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 89;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 89;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 89;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 100;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 100;
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 100;
DROP TABLE t1;

--echo #
--echo # Bug#50104: Partitioned table with just 1 partion works with fk
--echo #
CREATE TABLE t2 (
  id INT,
  PRIMARY KEY (id)
) ENGINE=InnoDB ;

CREATE TABLE t1 (
  id INT NOT NULL AUTO_INCREMENT,
  parent_id INT DEFAULT NULL,
  PRIMARY KEY (id),
  KEY parent_id (parent_id)
) ENGINE=InnoDB;

ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 1;

--error ER_FOREIGN_KEY_ON_PARTITIONED
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id);

ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 2;

--error ER_FOREIGN_KEY_ON_PARTITIONED
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id);

DROP TABLE t1, t2;

#
# BUG#47774, Assertion failure in InnoDB using column list partitioning
#
create table t1 (a varchar(5), b int signed, c varchar(10), d datetime)
partition by range columns(b,c)
subpartition by hash(to_seconds(d))
( partition p0 values less than (2, 'b'),
  partition p1 values less than (4, 'd'),
  partition p2 values less than (10, 'za'));
insert into t1 values ('a', 3, 'w', '2001-10-27 04:34:00');
insert into t1 values ('r', 7, 'w', '2001-10-27 05:34:00');
insert into t1 values ('g', 10, 'w', '2001-10-27 06:34:00');
update t1 set a = 'c' where a > 'f';
drop table t1;

#
# BUG#47776, Failed to update for MEMORY engine, crash for InnoDB and success for MyISAM
#
create table t1 (a varchar(5))
engine=memory
partition by range columns(a)
( partition p0 values less than ('m'),
  partition p1 values less than ('za'));
insert into t1 values  ('j');
update t1 set a = 'z' where (a >= 'j');
drop table t1;

create table t1 (a varchar(5))
engine=myisam
partition by range columns(a)
( partition p0 values less than ('m'),
  partition p1 values less than ('za'));
insert into t1 values  ('j');
update t1 set a = 'z' where (a >= 'j');
drop table t1;

create table t1 (a varchar(5))
engine=innodb
partition by range columns(a)
( partition p0 values less than ('m'),
  partition p1 values less than ('za'));
insert into t1 values  ('j');
update t1 set a = 'z' where (a >= 'j');
drop table t1;

#
# Bug#47029: Crash when reorganize partition with subpartition
#
create table t1 (a int not null,
                 b datetime not null,
                 primary key (a,b))
engine=innodb
partition by range (to_days(b))
subpartition by hash (a)
subpartitions 2
( partition p0 values less than (to_days('2009-01-01')),
  partition p1 values less than (to_days('2009-02-01')),
  partition p2 values less than (to_days('2009-03-01')),
  partition p3 values less than maxvalue);
alter table t1 reorganize partition p1,p2 into
( partition p2 values less than (to_days('2009-03-01')));
drop table t1;
#
# Bug#40595: Non-matching rows not released with READ-COMMITTED on tables
#            with partitions
CREATE TABLE t1 (id INT PRIMARY KEY, data INT) ENGINE = InnoDB 
PARTITION BY RANGE(id) ( 
 PARTITION p0 VALUES LESS THAN (5), 
 PARTITION p1 VALUES LESS THAN (10), 
 PARTITION p2 VALUES LESS THAN MAXVALUE 
);

INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8),
                      (9,9), (10,10), (11,11);

SET @old_tx_isolation := @@session.tx_isolation;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;

SET autocommit = 0;

UPDATE t1 SET DATA = data*2 WHERE id = 3;

# SHOW ENGINE InnoDB STATUS does not show transaction info in
# PERFORMANCE-VERSION
# grouping/referencing in replace_regex is very slow on long strings,
# removing all before/after the interesting row before grouping/referencing
#--replace_regex /.*---TRANSACTION [0-9]+ [0-9]+, .*, OS thread id [0-9]+// /MySQL thread id [0-9]+, query id [0-9]+ .*// /.*([0-9]+) lock struct\(s\), heap size [0-9]+, ([0-9]+) row lock\(s\).*/\1 lock struct(s) \2 row lock(s)/
#SHOW ENGINE InnoDB STATUS;

UPDATE t1 SET data = data*2 WHERE data = 2;

# SHOW ENGINE InnoDB STATUS does not show transaction info in
# PERFORMANCE-VERSION
# grouping/referencing in replace_regex is very slow on long strings,
# removing all before/after the interesting row before grouping/referencing
#--replace_regex /.*---TRANSACTION [0-9]+ [0-9]+, .*, OS thread id [0-9]+// /MySQL thread id [0-9]+, query id [0-9]+ .*// /.*([0-9]+ lock struct\(s\)), heap size [0-9]+, ([0-9]+ row lock\(s\)).*/\1 \2/
#SHOW ENGINE InnoDB STATUS;

SET @@session.tx_isolation = @old_tx_isolation;

DROP TABLE t1;

#
# Bug37721: ORDER BY when WHERE contains non-partitioned index column
# wrong order since it did not use pk as second compare
--echo # Bug#37721, test of ORDER BY on PK and WHERE on INDEX
CREATE TABLE t1 (
  a INT,
  b INT,
  PRIMARY KEY (a),
  INDEX (b))
ENGINE InnoDB
PARTITION BY HASH(a)
PARTITIONS 3;
# This will give the middle partition the highest value
INSERT INTO t1 VALUES (0,0),(4,0),(2,0);
SELECT a FROM t1 WHERE b = 0 ORDER BY a ASC;
SELECT a FROM t1 WHERE b = 0 ORDER BY a DESC;
ALTER TABLE t1 DROP INDEX b;
SELECT a FROM t1 WHERE b = 0 ORDER BY a ASC;
SELECT a FROM t1 WHERE b = 0 ORDER BY a DESC;
DROP TABLE t1;
CREATE TABLE t1 (
  a VARCHAR(600),
  b VARCHAR(600),
  PRIMARY KEY (a),
  INDEX (b))
ENGINE InnoDB
PARTITION BY KEY(a)
PARTITIONS 3;
# This will give the middle partition the highest value
INSERT INTO t1 VALUES (concat(repeat('MySQL',100),'1'),repeat('0',257));
INSERT INTO t1 VALUES (concat(repeat('MySQL',100),'3'),repeat('0',257));
INSERT INTO t1 VALUES (concat(repeat('MySQL',100),'2'),repeat('0',257));
SELECT right(a,1) FROM t1 WHERE b = repeat('0',257) ORDER BY a ASC;
SELECT right(a,1) FROM t1 WHERE b = repeat('0',257) ORDER BY a DESC;
ALTER TABLE t1 DROP INDEX b;
SELECT right(a,1) FROM t1 WHERE b = repeat('0',257) ORDER BY a ASC;
SELECT right(a,1) FROM t1 WHERE b = repeat('0',257) ORDER BY a DESC;
DROP TABLE t1;

#
# Bug#32948 - FKs allowed to reference partitioned table
#
-- echo # Bug#32948
CREATE TABLE t1 (c1 INT, PRIMARY KEY (c1)) ENGINE=INNODB;
CREATE TABLE t2 (c1 INT, PRIMARY KEY (c1),
                 FOREIGN KEY (c1) REFERENCES t1 (c1)
                 ON DELETE CASCADE)
ENGINE=INNODB;
--error ER_ROW_IS_REFERENCED
ALTER TABLE t1 PARTITION BY HASH(c1) PARTITIONS 5;
--error ER_ROW_IS_REFERENCED
ALTER TABLE t1 ENGINE=MyISAM;
DROP TABLE t2;
DROP TABLE t1;

#
# Bug #14673: Wrong InnoDB default row format
#
create table t1 (a int) engine=innodb partition by hash(a) ;
# Data_free for InnoDB tablespace varies depending on which
# tests have been run before this one
--replace_column 10 # 12 #
show table status like 't1';
drop table t1;

#
# Bug 21173: SHOW TABLE STATUS crashes server in InnoDB
#
create table t1 (a int)
engine = innodb
partition by key (a);
# Data_free for InnoDB tablespace varies depending on which
# tests have been run before this one
--replace_column 10 # 12 #
show table status;
insert into t1 values (0), (1), (2), (3);
# Data_free for InnoDB tablespace varies depending on which
# tests have been run before this one
--replace_column 10 # 12 #
show table status;
drop table t1;

create table t1 (a int auto_increment primary key)
engine = innodb
partition by key (a);
# Data_free for InnoDB tablespace varies depending on which
# tests have been run before this one
--replace_column 10 # 12 #
show table status;
insert into t1 values (NULL), (NULL), (NULL), (NULL);
# Data_free for InnoDB tablespace varies depending on which
# tests have been run before this one
--replace_column 10 # 12 #
show table status;
insert into t1 values (NULL), (NULL), (NULL), (NULL);
# Data_free for InnoDB tablespace varies depending on which
# tests have been run before this one
--replace_column 10 # 12 #
show table status;
drop table t1;

#
# BUG 19122 Crash after ALTER TABLE t1 REBUILD PARTITION p1
#
create table t1 (a int)
partition by key (a)
(partition p1 engine = innodb);

alter table t1 rebuild partition p1;
alter table t1 rebuild partition p1;
alter table t1 rebuild partition p1;
alter table t1 rebuild partition p1;
alter table t1 rebuild partition p1;
alter table t1 rebuild partition p1;
alter table t1 rebuild partition p1;
drop table t1;

#
# Bug 21339: Crash in Explain Partitions
#
create table t1 (a date)
engine = innodb
partition by range (year(a))
(partition p0 values less than (2006),
 partition p1 values less than (2007));
explain partitions select * from t1
where a between '2006-01-01' and '2007-06-01';
drop table t1;

#
# Bug 20397: Partitions: Crash when using non-existing engine
#
SET SQL_MODE="";
create table t1 (a int)
engine = x
partition by key (a);
show create table t1;
drop table t1;

create table t1 (a int)
engine = innodb
partition by list (a)
(partition p0 values in (0));

alter table t1 engine = x;
show create table t1;
drop table t1;
SET SQL_MODE=default;

# BUG#26117: index_merge sort-union over partitioned table crashes

create table t1
(
  id int unsigned auto_increment,
  time datetime not null,
  first_name varchar(40),
  last_name varchar(50),
  primary key (id, time),
  index first_index (first_name),
  index last_index (last_name)	
) engine=Innodb partition by range (to_days(time)) (
  partition p1 values less than (to_days('2007-02-07')),
  partition p2 values less than (to_days('2007-02-08')),
  partition p3 values less than MAXVALUE
);

insert into t1 (time, first_name, last_name) values ('2007-02-07', 'Q', 'Robert'),
('2007-02-07', 'Mark', 'Nate'), ('2007-02-07', 'Nate', 'Oscar'),
('2007-02-07', 'Zack', 'Alice'), ('2007-02-07', 'Jack', 'Kathy'),
('2007-02-06', 'Alice', 'Alice'), ('2007-02-06', 'Brian', 'Charles'),
('2007-02-06', 'Charles', 'David'), ('2007-02-06', 'David', 'Eric'),
('2007-02-07', 'Hector', 'Isaac'), ('2007-02-07', 'Oscar', 'Patricia'),
('2007-02-07', 'Patricia', 'Q'), ('2007-02-07', 'X', 'Yuri'),
('2007-02-07', 'Robert', 'Shawn'), ('2007-02-07', 'Kathy', 'Lois'),
('2007-02-07', 'Eric', 'Francis'), ('2007-02-06', 'Shawn', 'Theron'),
('2007-02-06', 'U', 'Vincent'), ('2007-02-06', 'Francis', 'George'),
('2007-02-06', 'George', 'Hector'), ('2007-02-06', 'Vincent', 'Walter'),
('2007-02-06', 'Walter', 'X'), ('2007-02-07', 'Lois', 'Mark'),
('2007-02-07', 'Yuri', 'Zack'), ('2007-02-07', 'Isaac', 'Jack'),
('2007-02-07', 'Sharon', 'Mark'), ('2007-02-07', 'Michael', 'Michelle'),
('2007-02-07', 'Derick', 'Nathan'), ('2007-02-07', 'Peter', 'Xavier'),
('2007-02-07', 'Fred', 'Harold'), ('2007-02-07', 'Katherine', 'Lisa'),
('2007-02-07', 'Tom', 'Rina'), ('2007-02-07', 'Jerry', 'Victor'),
('2007-02-07', 'Alexander', 'Terry'), ('2007-02-07', 'Justin', 'John'),
('2007-02-07', 'Greg', 'Ernest'), ('2007-02-07', 'Robert', 'Q'),
('2007-02-07', 'Nate', 'Mark'), ('2007-02-07', 'Oscar', 'Nate'),
('2007-02-07', 'Alice', 'Zack'), ('2007-02-07', 'Kathy', 'Jack'),
('2007-02-06', 'Alice', 'Alice'), ('2007-02-06', 'Charles', 'Brian'),
('2007-02-06', 'David', 'Charles'), ('2007-02-06', 'Eric', 'David'),
('2007-02-07', 'Isaac', 'Hector'), ('2007-02-07', 'Patricia', 'Oscar'),
('2007-02-07', 'Q', 'Patricia'), ('2007-02-07', 'Yuri', 'X'),
('2007-02-07', 'Shawn', 'Robert'), ('2007-02-07', 'Lois', 'Kathy'),
('2007-02-07', 'Francis', 'Eric'), ('2007-02-06', 'Theron', 'Shawn'),
('2007-02-06', 'Vincent', 'U'), ('2007-02-06', 'George', 'Francis'),
('2007-02-06', 'Hector', 'George'), ('2007-02-06', 'Walter', 'Vincent'),
('2007-02-06', 'X', 'Walter'), ('2007-02-07', 'Mark', 'Lois'),
('2007-02-07', 'Zack', 'Yuri'), ('2007-02-07', 'Jack', 'Isaac'),
('2007-02-07', 'Mark', 'Sharon'), ('2007-02-07', 'Michelle', 'Michael'),
('2007-02-07', 'Nathan', 'Derick'), ('2007-02-07', 'Xavier', 'Peter'),
('2007-02-07', 'Harold', 'Fred'), ('2007-02-07', 'Lisa', 'Katherine'),
('2007-02-07', 'Rina', 'Tom'), ('2007-02-07', 'Victor', 'Jerry'),
('2007-02-07', 'Terry', 'Alexander'), ('2007-02-07', 'John', 'Justin'),
('2007-02-07', 'Ernest', 'Greg');

SELECT * FROM t1 WHERE first_name='Andy' OR last_name='Jake';

drop table t1;

#
# BUG#30583 - Partition on DOUBLE key + INNODB + count(*) == crash
#
CREATE TABLE t1 (a DOUBLE NOT NULL, KEY(a)) ENGINE=InnoDB
PARTITION BY KEY(a) PARTITIONS 10;
INSERT INTO t1 VALUES(1),(2);
SELECT COUNT(*) FROM t1;
DROP TABLE t1;

#
# Bug #31893 Partitions: crash if subpartitions and engine change
#
create table t1 (int_column int, char_column char(5))
  PARTITION BY RANGE (int_column) subpartition by key (char_column) subpartitions 2
  (PARTITION p1 VALUES LESS THAN (5) ENGINE = InnoDB);
alter table t1
ENGINE = MyISAM
PARTITION BY RANGE (int_column)
   subpartition by key (char_column) subpartitions 2
  (PARTITION p1 VALUES LESS THAN (5));
show create table t1;
drop table t1;

#
# BUG#46483 - drop table of partitioned table may leave extraneous file
# Note: was only repeatable with InnoDB plugin
#
CREATE TABLE t1 (a INT) ENGINE=InnoDB
  PARTITION BY list(a) (PARTITION p1 VALUES IN (1));
CREATE INDEX i1 ON t1 (a);
DROP TABLE t1;

# Before the fix it should show extra file like #sql-2405_2.par
--list_files $MYSQLD_DATADIR/test/ *.par

--disable_parsing
--echo #
--echo # Bug#47343: InnoDB fails to clean-up after lock wait timeout on
--echo #            REORGANIZE PARTITION
--echo #
CREATE TABLE t1 (
	a INT,
	b DATE NOT NULL,
	PRIMARY KEY (a, b)
) ENGINE=InnoDB
PARTITION BY RANGE (a) (
	PARTITION pMAX VALUES LESS THAN MAXVALUE
) ;

INSERT INTO t1 VALUES (1, '2001-01-01'), (2, '2002-02-02'), (3, '2003-03-03');

START TRANSACTION;
SELECT * FROM t1 FOR UPDATE;

connect (con1, localhost, root,,);
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 REORGANIZE PARTITION pMAX INTO
(PARTITION p3 VALUES LESS THAN (3),
 PARTITION pMAX VALUES LESS THAN MAXVALUE);
SHOW WARNINGS;
--error ER_LOCK_WAIT_TIMEOUT
ALTER TABLE t1 REORGANIZE PARTITION pMAX INTO
(PARTITION p3 VALUES LESS THAN (3),
 PARTITION pMAX VALUES LESS THAN MAXVALUE);
SHOW WARNINGS;

#Contents of the 'test' database directory:
--list_files $MYSQLD_DATADIR/test/ *.par

disconnect con1;
connection default;
SELECT * FROM t1;
COMMIT;
DROP TABLE t1;

#
# Bug #55146    Assertion `m_part_spec.start_part == m_part_spec.end_part' in index_read_idx_map
#

CREATE TABLE t1 (i1 int NOT NULL primary key, f1 int) ENGINE = InnoDB
    PARTITION BY HASH(i1) PARTITIONS 2;

INSERT INTO t1 VALUES (1,1), (2,2);

SELECT * FROM t1 WHERE i1 = ( SELECT i1 FROM t1 WHERE f1=0 LIMIT 1 );

DROP TABLE t1;

--enable_parsing

--echo #
--echo # Bug#54783: optimize table crashes with invalid timestamp default value and NO_ZERO_DATE
--echo #

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

CREATE TABLE t1 (a INT, b TIMESTAMP DEFAULT '0000-00-00 00:00:00')
  ENGINE=INNODB PARTITION BY LINEAR HASH (a) PARTITIONS 1;
SET @old_mode = @@sql_mode;
SET SESSION sql_mode = 'NO_ZERO_DATE';
OPTIMIZE TABLE t1;
SET SESSION sql_mode = @old_mode;
DROP TABLE t1;


--echo #
--echo # Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the
--echo #            table unusable".
--echo #
CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a))
  ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2;
INSERT INTO t1 values (0,1), (1,2);
--echo # The below ALTER should fail. It should leave the
--echo # table in its original, non-corrupted, usable state.
--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF
ALTER TABLE t1 ADD UNIQUE KEY (b);
--echo # The below statements should succeed, as ALTER should
--echo # have left table intact.
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;


--echo #
--echo # Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the
--echo #            table unusable".
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a))
  ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2;
INSERT INTO t1 values (0,1), (1,2);
--echo # The below ALTER should fail. It should leave the
--echo # table in its original, non-corrupted, usable state.
--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF
ALTER TABLE t1 ADD UNIQUE KEY (b);
--echo # The below statements should succeed, as ALTER should
--echo # have left table intact.
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Bug #17299181  CREATE_TIME AND UPDATE_TIME ARE
--echo #                WRONG FOR PARTITIONED TABLES
--echo #

CREATE TABLE t1 (a int, PRIMARY KEY (a)) ENGINE=InnoDB
PARTITION BY HASH (a) PARTITIONS 2;

SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE
CREATE_TIME IS NOT NULL AND TABLE_NAME='t1';

DROP TABLE t1;

--echo #
--echo # BUG#12912171 - ASSERTION FAILED: QUICK->HEAD->READ_SET ==
--echo # SAVE_READ_SET
--echo #
CREATE TABLE t1 (
 a INT,
 b INT,
 c INT,
 PRIMARY KEY (c,a), KEY (a),KEY (a)
) ENGINE=INNODB PARTITION BY KEY () PARTITIONS 2;
INSERT INTO t1 VALUES (1,5,1),(2,4,1),(3,3,1),(4,2,1),(5,1,1);
UPDATE t1 SET b = 0, c=1 WHERE a <=>0;
SELECT * FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-5102 : MySQL Bug 69851
--echo #
CREATE TABLE t1 (
  `col1` bigint(20) unsigned NOT NULL ,
  `col2` bigint(20) unsigned NOT NULL ,
  `col3` datetime NOT NULL ,
  PRIMARY KEY (`col3`),
  KEY (`col1`),
  KEY (`col2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 PARTITION BY RANGE (TO_DAYS(col3))
(
 PARTITION p_20130310 VALUES LESS THAN (735303) ENGINE = InnoDB,
 PARTITION p_20130311 VALUES LESS THAN (735304) ENGINE = InnoDB,
 PARTITION p_20130312 VALUES LESS THAN (735305) ENGINE = InnoDB
);
INSERT INTO `t1` VALUES (2,96,'2013-03-08 16:28:05');
INSERT INTO `t1` VALUES (1,2,'2013-03-08 16:47:39');
INSERT INTO `t1` VALUES (1,2,'2013-03-08 16:50:27');
INSERT INTO `t1` VALUES (1,2,'2013-03-11 16:33:04');
INSERT INTO `t1` VALUES (1,2,'2013-03-11 16:33:24');
INSERT INTO `t1` VALUES (2,2,'2013-03-12 10:11:48');

SELECT * FROM t1 WHERE col1 = 1 AND col2 = 2
    AND col3 BETWEEN '2013-03-08 00:00:00' AND '2013-03-12 12:00:00'
GROUP BY 1, 2, 3;
--replace_column 9 #
EXPLAIN SELECT * FROM t1 WHERE col1 = 1 AND col2 = 2
    AND col3 BETWEEN '2013-03-08 00:00:00' AND '2013-03-12 12:00:00'
GROUP BY 1, 2, 3;

SELECT * FROM t1 USE INDEX () WHERE col1 = 1 AND col2 = 2
    AND col3 BETWEEN '2013-03-08 00:00:00' AND '2013-03-12 12:00:00'
GROUP BY 1, 2, 3;

DROP TABLE t1;

--echo #
--echo # MDEV-5177: ha_partition and innodb index intersection produce fewer rows (MySQL Bug#70703)
--echo #
create table t1 (
  a int not null,
  b int not null,
  pk int not null,
  primary key (pk),
  key(a),
  key(b)
) engine=innodb partition by hash(pk) partitions 10;

insert into t1 values (1,2,4); # both
insert into t1 values (1,0,17);  # left
insert into t1 values (1,2,25);   # both

insert into t1 values (10,20,122); 
insert into t1 values (10,20,123);

# Now, fill in some data so that the optimizer choses index_merge
create table t2 (a int);
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

insert into t1 select 1,2, 200 + A.a + 10*B.a + 100*C.a from t2 A, t2 B, t2 C;

insert into t1 select 10+A.a + 10*B.a + 100*C.a + 1000*D.a,
                       10+A.a + 10*B.a + 100*C.a  + 1000*D.a, 
                       2000 + A.a + 10*B.a + 100*C.a + 1000*D.a
                       from t2 A, t2 B, t2 C ,t2 D;

# This should show index_merge, using intersect
--replace_column 9 #
set statement optimizer_switch='rowid_filter=off' for
explain select * from t1 where a=1 and b=2 and  pk between 1 and 999999 ;
# 794 rows in output
set statement optimizer_switch='rowid_filter=off' for
create temporary table t3 as
select * from t1 where a=1 and b=2 and  pk between 1 and 999 ;
select count(*) from t3;
drop table t3;

# 802 rows in output
create temporary table t3 as
select * from t1 ignore index(a,b)  where a=1 and b=2 and  pk between 1 and 999 ;
select count(*) from t3;
drop table t3;

drop table t1,t2;

--echo #
--echo # MySQL Bug#71095: Wrong results with PARTITION BY LIST COLUMNS()
--echo #
create table t1(c1 int, c2 int, c3 int, c4 int,
primary key(c1,c2)) engine=InnoDB
partition by list columns(c2)
(partition p1 values in (1,2) engine=InnoDB,
partition p2 values in (3,4) engine=InnoDB);

insert into t1 values (1,1,1,1),(2,3,1,1);
select * from t1 where c1=2 and c2=3;
drop table t1;

--echo #
--echo # MySQL Bug#72803: Wrong "Impossible where" with LIST partitioning
--echo #  also MDEV-6240: Wrong "Impossible where" with LIST partitioning
--echo #
CREATE TABLE t1 ( d DATE) ENGINE = InnoDB
PARTITION BY LIST COLUMNS (d)
(
  PARTITION p0 VALUES IN ('1990-01-01','1991-01-01'),
  PARTITION p1 VALUES IN ('1981-01-01')
);

INSERT INTO t1 (d) VALUES ('1991-01-01');
SELECT *  FROM t1 WHERE d = '1991-01-01';
DROP TABLE t1;

set global default_storage_engine=default;

--echo #
--echo # MDEV-9455: [ERROR] mysqld got signal 11 
--echo #

CREATE TABLE `t1` (
  `DIARY_TOTAL_DAY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `IMORY_ID` bigint(20) NOT NULL,
  `NAME` varchar(75) DEFAULT NULL,
  `DATETIME` varchar(10) NOT NULL DEFAULT '',
  `DAILY_CALL_CNT` int(11) DEFAULT NULL,
  `DAILY_SMS_CNT` int(11) DEFAULT NULL,
  `NUMBER` varchar(64) DEFAULT NULL,
  `DURATION` varchar(16) DEFAULT NULL,
  PRIMARY KEY (`DIARY_TOTAL_DAY_SEQ`,`DATETIME`),
  KEY `IDX_t1_01` (`IMORY_ID`,`DATETIME`)
) AUTO_INCREMENT=328702514 DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE  COLUMNS(`DATETIME`)
(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB,
 PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB,
 PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB,
 PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB,
 PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB,
 PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB,
 PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB,
 PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB,
 PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB,
 PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB,
 PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB)
;

CREATE TABLE `t2` (
  `DIARY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `IMORY_ID` bigint(20) NOT NULL,
  `CALL_TYPE` varchar(1) DEFAULT NULL,
  `DATA_TYPE` varchar(1) DEFAULT NULL,
  `FEATURES` varchar(1) DEFAULT NULL,
  `NAME` varchar(75) DEFAULT NULL,
  `NUMBER` varchar(64) DEFAULT NULL,
  `DATETIME` datetime NOT NULL,
  `REG_DATE` datetime NOT NULL,
  `TITLE` varchar(50) DEFAULT NULL,
  `BODY` varchar(4200) DEFAULT NULL,
  `MIME_TYPE` varchar(32) DEFAULT NULL,
  `DURATION` varchar(16) DEFAULT NULL,
  `DEVICE_ID` varchar(64) DEFAULT NULL,
  `DEVICE_NAME` varchar(32) DEFAULT NULL,
  PRIMARY KEY (`DIARY_SEQ`,`DATETIME`,`REG_DATE`),
  KEY `IDX_TB_DIARY_01` (`IMORY_ID`,`DATETIME`,`CALL_TYPE`,`NUMBER`),
  KEY `IDX_TB_DIARY_02` (`REG_DATE`)
) AUTO_INCREMENT=688799006 DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE  COLUMNS(REG_DATE)
(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB,
 PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB,
 PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB,
 PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB,
 PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB,
 PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB,
 PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB,
 PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB,
 PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB,
 PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB,
 PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB)
;

SELECT
  A.IMORY_ID,
  A.NUMBER,
  A.NAME,
  DATE_FORMAT(A.DATETIME, '%Y-%m-%d') AS TARGET_DATE,
  SUM( CASE WHEN A.DATA_TYPE='1' THEN 1 ELSE 0 END) AS CALL_CNT,
  SUM( CASE WHEN A.DATA_TYPE IN ('2', '3') THEN 1 ELSE 0 END) AS SMS_CNT,
  SUM(CAST(A.DURATION AS INT)) AS DURATION,
  ( SELECT COUNT(*)
    FROM t1
    WHERE IMORY_ID=A.IMORY_ID
      AND NUMBER=A.NUMBER
      AND NAME=A.NAME 
      AND DATETIME = DATE_FORMAT(A.DATETIME, '%Y-%m-%d')
  ) STATS_COUNT
FROM t2 A
WHERE A.IMORY_ID = 55094102
  AND A.DATETIME LIKE (
    SELECT CONCAT (DATE_FORMAT(DATETIME, '%Y-%m-%d') ,'%')
    FROM t2
    WHERE IMORY_ID=55094102
      AND DIARY_SEQ IN ( 608351221, 608351225, 608351229 )
    group by DATE_FORMAT(DATETIME, '%Y-%m-%d')
  )
GROUP BY A.IMORY_ID, A.NUMBER, A.NAME, DATE_FORMAT(A.DATETIME, '%Y-%m-%d')
;

drop table t2, t1;


set global default_storage_engine='innodb';

--echo #
--echo # MDEV-5963: InnoDB: Assertion failure in file row0sel.cc line 2503, 
--echo #    Failing assertion: 0 with "key ptr now exceeds key end by 762 bytes"
--echo # (independent testcase for Oracle Bug#13947868)
--echo #
CREATE TABLE t1 (f1 VARCHAR(512) CHARACTER SET utf8) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('j');

CREATE TABLE t2 (
  f2 VARCHAR(5) CHARACTER SET latin1,
  f3 VARCHAR(5) CHARACTER SET utf8,
  f4 INT,
  f5 VARCHAR(512) CHARACTER SET utf8,
  f6 VARCHAR(256) CHARACTER SET utf8,
  key (f2),
  key (f3),
  key (f5)
) ENGINE=InnoDB PARTITION BY LIST COLUMNS (f4)
  SUBPARTITION BY KEY(f6) SUBPARTITIONS 4 (
    PARTITION p0 VALUES IN (1,3,9,null),
    PARTITION p1 VALUES IN (2,4,0)
);

INSERT INTO t2 VALUES  
  ('k','s',3,'b','j'),('a','b',NULL,'v','j'),('c','m',9,'t',NULL),
  ('b','l',9,'b',NULL),('i','y',3,'o','w'),('c','m',NULL,'a','m'),  
  ('f','o',9,'m','w'),('f','q',NULL,'o','a');

CREATE TABLE t3 LIKE t2;

SELECT * FROM t1 INNER JOIN t2 ON ( f5 = f1 );
INSERT INTO t3 SELECT * FROM t2 WHERE f3 = 'm' AND f2 ='c';

DROP TABLE t1,t2,t3;

set global default_storage_engine=default;

--echo #
--echo # Bug#13737949: CRASH IN HA_PARTITION::INDEX_INIT
--echo # Bug#18694052: SERVER CRASH IN HA_PARTITION::INIT_RECORD_PRIORITY_QUEUE
--echo #
CREATE TABLE t1
(a INT,
 b INT,
 PRIMARY KEY (a))
 ENGINE = InnoDB
 PARTITION BY HASH (a) PARTITIONS 3;
 START TRANSACTION WITH CONSISTENT SNAPSHOT;
 --connect (con1, localhost, root,,)
 ALTER TABLE t1 ADD INDEX idx1 (b);
 --connection default
 --error ER_TABLE_DEF_CHANGED
 SELECT b FROM t1 WHERE b = 0;
 --error ER_TABLE_DEF_CHANGED
 SELECT b FROM t1 WHERE b = 0;
 --disconnect con1
 DROP TABLE t1;

--echo # Same test without partitioning
CREATE TABLE t1
(a INT,
 b INT,
 PRIMARY KEY (a))
 ENGINE = InnoDB;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
--connect (con1, localhost, root,,)
ALTER TABLE t1 ADD INDEX idx1 (b);
--connection default
--error ER_TABLE_DEF_CHANGED
SELECT b FROM t1 WHERE b = 0;
--error ER_TABLE_DEF_CHANGED
SELECT b FROM t1 WHERE b = 0;
--disconnect con1
DROP TABLE t1;

--echo #
--echo # MDEV-11167: InnoDB: Warning: using a partial-field key prefix
--echo # in search, results in assertion failure or "Can't find record" error
--echo #

set @save_sql_mode = @@sql_mode;
set sql_mode="";
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
CREATE TABLE t2 (b INT, c INT, KEY(b)) ENGINE=InnoDB PARTITION BY HASH(c) PARTITIONS 2;
CREATE ALGORITHM = MERGE VIEW v AS SELECT a, b FROM t1 STRAIGHT_JOIN t2 WHERE b = 'foo' WITH CHECK OPTION;

INSERT INTO t1 VALUES (1),(2);
INSERT IGNORE INTO t2 VALUES (2,2),('three',3),(4,4);
UPDATE v SET a = NULL;

DROP view v;
DROP TABLE t1, t2;

SET @save_isp=@@innodb_stats_persistent;
SET GLOBAL innodb_stats_persistent= ON;

CREATE TABLE t (f1 INT, f2 INT, KEY(f2)) ENGINE=InnoDB PARTITION BY HASH (f1) PARTITIONS 2;
INSERT IGNORE INTO t VALUES (NULL,0),(NULL,0),(0,21),(4,0),(1,8),(5,66);
CREATE ALGORITHM=MERGE VIEW v AS SELECT t1.* FROM t t1 JOIN t t2 WHERE t1.f1 < t2.f2 WITH LOCAL CHECK OPTION;
--error ER_VIEW_CHECK_FAILED
UPDATE v SET f2 = NULL;

SET GLOBAL innodb_stats_persistent= @save_isp;
DROP view v;
DROP TABLE t;
set sql_mode= @save_sql_mode;

--echo #
--echo # Bug#26390658 RENAMING A PARTITIONED TABLE DOES NOT UPDATE
--echo #              MYSQL.INNODB_TABLE_STATS
--echo #

CREATE DATABASE test_jfg;

CREATE TABLE test_jfg.test_jfg1 (id int(10) unsigned NOT NULL,PRIMARY
KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=1;
CREATE TABLE test_jfg.test_jfg2 (id int(10) unsigned NOT NULL,PRIMARY
KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1 STATS_PERSISTENT=1
PARTITION BY RANGE ( id ) (PARTITION p1000 VALUES LESS THAN (1000)
ENGINE = InnoDB,PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE =
InnoDB);

--replace_result #p# #P#
SELECT database_name, table_name FROM mysql.innodb_table_stats WHERE
database_name = 'test_jfg';

RENAME TABLE test_jfg.test_jfg1 TO test_jfg.test_jfg11;
RENAME TABLE test_jfg.test_jfg2 TO test_jfg.test_jfg12;

--replace_result #p# #P#
SELECT database_name, table_name FROM mysql.innodb_table_stats WHERE
database_name = 'test_jfg';

DROP DATABASE test_jfg;

set global innodb_stats_persistent= @innodb_stats_persistent_save;
set global innodb_stats_persistent_sample_pages=
             @innodb_stats_persistent_sample_pages_save;
#
# MDEV-17755 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index) || (!(ptr >= table->record[0] && ptr < table->record[0] + table->s->reclength)))' failed in Field_bit::val_int upon SELECT with JOIN, partitions, indexed virtual column
#
create table t1 (a int) engine=innodb;
create table t2 (
  b int,
  c int,
  d bit not null default 0,
  v bit as (d) virtual,
  key (b,v)
) engine=innodb partition by hash (b);
insert into t1 values (1),(2);
insert into t2 (b,c,d) values (1,1,0),(2,2,0);
explain select t1.* from t1 join t2 on (v = a);
select t1.* from t1 join t2 on (v = a);
drop table t1, t2;

--echo #
--echo # End of 10.2 tests
--echo #

--echo #
--echo # MDEV-16241 Assertion `inited==RND' failed in handler::ha_rnd_end()
--echo #
CREATE TABLE t1 (pk INT PRIMARY KEY, x INT, y INT, z INT, KEY (x), KEY (y, z))
WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME (PARTITION p1 HISTORY, PARTITION pn CURRENT);
INSERT INTO t1 VALUES (1, 7, 8, 9), (2, NULL, NULL, NULL), (3, NULL, NULL, NULL);
SELECT COUNT(*) FROM t1 WHERE x IS NULL AND y IS NULL AND z IS NULL;
DROP TABLE t1;

--echo #
--echo # End of 10.3 tests
--echo #