(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t;
a b
1 First value
3 Three
5 Five
99 End of values
SELECT * FROM tp;
a b
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t;
a b
10 Ten
2 First value
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
SELECT * FROM tp;
a b
1 First value
161 161
162 162
163 163
164 164
200 Two hundred, end of values
3 Three
5 Five
99 End of values
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
SELECT * FROM t;
a b
1 First value
3 Three
5 Five
99 End of values
SELECT * FROM tp;
a b
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
ERROR HY000: Found a row that does not match the partition
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t;
a b
1 First value
3 Three
5 Five
99 End of values
SELECT * FROM tp;
a b
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
# Test list of partitions
ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t IGNORE;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IGNORE' at line 1
ALTER TABLE tp EXCHANGE PARTITION p0,p1 WITH TABLE t IGNORE;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'p1 WITH TABLE t IGNORE' at line 1
ALTER TABLE tp EXCHANGE PARTITION p0,p1 WITH TABLE t;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'p1 WITH TABLE t' at line 1
ALTER TABLE tp EXCHANGE PARTITION (p0,p1) WITH TABLE t;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(p0,p1) WITH TABLE t' at line 1
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE (t,t2);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(t,t2)' at line 1
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t,t2;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't2' at line 1
ALTER TABLE tp EXCHANGE PARTITION non_existent WITH TABLE t;
ERROR HY000: Unknown partition 'non_existent' in table 'tp'
ALTER TABLE tsp EXCHANGE PARTITION p0 WITH TABLE t;
ERROR HY000: Subpartitioned table, use subpartition instead of partition
ALTER TABLE tsp EXCHANGE PARTITION sp0 WITH TABLE tp;
ERROR HY000: Table to exchange with partition is partitioned: 'tp'
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SHOW CREATE TABLE tsp;
Table Create Table
tsp CREATE TABLE `tsp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
SUBPARTITION BY HASH (a)
(PARTITION p0 VALUES LESS THAN (100)
(SUBPARTITION sp0 ENGINE = MyISAM,
SUBPARTITION sp1 ENGINE = MyISAM),
PARTITION p1 VALUES LESS THAN MAXVALUE
(SUBPARTITION sp2 ENGINE = MyISAM,
SUBPARTITION sp3 ENGINE = MyISAM)) */
SELECT * FROM t;
a b
1 First value
3 Three
5 Five
99 End of values
SELECT * FROM tp;
a b
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
# Test exchange partition
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t;
a b
10 Ten
2 First value
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
SELECT * FROM tp;
a b
1 First value
161 161
162 162
163 163
164 164
200 Two hundred, end of values
3 Three
5 Five
99 End of values
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
SELECT * FROM t;
a b
1 First value
3 Three
5 Five
99 End of values
SELECT * FROM tp;
a b
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
# Test exchange subpartition
ALTER TABLE tsp EXCHANGE PARTITION sp1 WITH TABLE t;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tsp;
Table Create Table
tsp CREATE TABLE `tsp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
SUBPARTITION BY HASH (a)
(PARTITION p0 VALUES LESS THAN (100)
(SUBPARTITION sp0 ENGINE = MyISAM,
SUBPARTITION sp1 ENGINE = MyISAM),
PARTITION p1 VALUES LESS THAN MAXVALUE
(SUBPARTITION sp2 ENGINE = MyISAM,
SUBPARTITION sp3 ENGINE = MyISAM)) */
SELECT * FROM t;
a b
61 Sixty one
63 Sixty three
SELECT * FROM tsp;
a b
1 First value
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
3 Three
5 Five
50 Fifty
62 Sixty two
64 Sixty four
99 End of values
ALTER TABLE tsp EXCHANGE PARTITION sp1 WITH TABLE t;
ALTER TABLE t ENGINE = InnoDB;
ALTER TABLE tp ENGINE = InnoDB;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
SELECT * FROM t;
a b
1 First value
3 Three
5 Five
99 End of values
SELECT * FROM tp;
a b
10 Ten
161 161
162 162
163 163
164 164
2 First value
200 Two hundred, end of values
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
SELECT * FROM t;
a b
10 Ten
2 First value
50 Fifty
61 Sixty one
62 Sixty two
63 Sixty three
64 Sixty four
SELECT * FROM tp;
a b
1 First value
161 161
162 162
163 163
164 164
200 Two hundred, end of values
3 Three
5 Five
99 End of values
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
# test different engines
ALTER TABLE t ENGINE = MyISAM;
ALTER TABLE tp ENGINE = InnoDB;
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MariaDB
SHOW CREATE TABLE t;
Table Create Table
t CREATE TABLE `t` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SHOW CREATE TABLE tp;
Table Create Table
tp CREATE TABLE `tp` (
`a` int(11) NOT NULL DEFAULT '0',
`b` varchar(55) DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
# Test different charsets
ALTER TABLE t ENGINE = MyISAM;
CREATE TABLE tmp LIKE t;
INSERT INTO tmp SELECT * FROM t;
RENAME TABLE t TO tmp2, tmp TO t;
ALTER TABLE tp ENGINE = MyISAM;
ALTER TABLE t CHARACTER SET = koi8r COLLATE koi8r_general_ci;
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
ERROR HY000: Non matching attribute 'CHARACTER SET' between partition and table