Skip to content

Commit c5d09f7

Browse files
MDEV-5271 Support engine-defined attributes per partition
Make it possible to specify engine-defined attributes on partitions as well as tables. If an engine-defined attribute is only specified at the table level, it applies to all the partitions in the table. This is a backward-compatible behavior. If the same attribute is specified both at the table level and the partition level, the per-partition one takes precedence. So, we can consider per-table attributes as default values. One cannot specify engine-defined attributes on subpartitions. Implementation details: * We store per-partition attributes in the partition_element class because we already have the part_comment field, which is for per-partition comments. * In the case of ALTER TABLE statements, the partition_elements in table->part_info is set up by mysql_unpack_partition(). So, we parse per-partition attributes after the call of the function.
1 parent 83dd7db commit c5d09f7

11 files changed

+588
-124
lines changed

mysql-test/main/partition_error.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ partitions 3
896896
(partition tablespace ts1,
897897
partition x2 tablespace ts2,
898898
partition x3 tablespace ts3);
899-
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 'ts1,
899+
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 '
900900
partition x2 tablespace ts2,
901901
partition x3 tablespace ts3)' at line 8
902902
CREATE TABLE t1 (
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
#
2+
# MDEV-5271 Support engine-defined attributes per partition
3+
#
4+
# partitioned tables
5+
CREATE TABLE `t1` (
6+
`id` INT
7+
) ENGINE=InnoDB ENCRYPTED="YES" PARTITION BY RANGE(id) (
8+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO" ENCRYPTION_KEY_ID=1,
9+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="DEFAULT" ENCRYPTION_KEY_ID=1
10+
);
11+
SHOW CREATE TABLE `t1`;
12+
Table Create Table
13+
t1 CREATE TABLE `t1` (
14+
`id` int(11) DEFAULT NULL
15+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='YES'
16+
PARTITION BY RANGE (`id`)
17+
(PARTITION `pt1` VALUES LESS THAN (100) ENGINE = InnoDB ENCRYPTED = 'NO' ENCRYPTION_KEY_ID = 1,
18+
PARTITION `pt2` VALUES LESS THAN MAXVALUE ENGINE = InnoDB ENCRYPTED = 'DEFAULT' ENCRYPTION_KEY_ID = 1)
19+
INSERT INTO t1 VALUES (1), (2), (3);
20+
DELETE FROM t1 WHERE id = 1;
21+
UPDATE t1 SET id = 4 WHERE id = 3;
22+
SELECT * FROM t1 WHERE id IN (2, 3);
23+
id
24+
2
25+
DROP TABLE `t1`;
26+
CREATE TABLE `t2` (
27+
`id` INT
28+
) ENGINE=InnoDB ENCRYPTED="YES" ENCRYPTION_KEY_ID=2 PARTITION BY RANGE(id) (
29+
PARTITION pt1 VALUES LESS THAN (100),
30+
PARTITION pt2 VALUES LESS THAN MAXVALUE
31+
);
32+
ERROR HY000: Can't create table `test`.`t2` (errno: 140 "Wrong create options")
33+
CREATE TABLE `t3` (
34+
`id` INT
35+
) ENGINE=InnoDB ENCRYPTED="NO" PARTITION BY RANGE(id) (
36+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES" ENCRYPTION_KEY_ID=2,
37+
PARTITION pt2 VALUES LESS THAN MAXVALUE
38+
);
39+
ERROR HY000: Can't create table `test`.`t3` (errno: 140 "Wrong create options")
40+
CREATE TABLE `t4` (
41+
`id` INT
42+
) ENGINE=InnoDB ENCRYPTED="NO";
43+
SHOW CREATE TABLE `t4`;
44+
Table Create Table
45+
t4 CREATE TABLE `t4` (
46+
`id` int(11) DEFAULT NULL
47+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='NO'
48+
ALTER TABLE `t4` PARTITION BY RANGE(id) (
49+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO",
50+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="DEFAULT"
51+
);
52+
SHOW CREATE TABLE `t4`;
53+
Table Create Table
54+
t4 CREATE TABLE `t4` (
55+
`id` int(11) DEFAULT NULL
56+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='NO'
57+
PARTITION BY RANGE (`id`)
58+
(PARTITION `pt1` VALUES LESS THAN (100) ENGINE = InnoDB ENCRYPTED = 'NO',
59+
PARTITION `pt2` VALUES LESS THAN MAXVALUE ENGINE = InnoDB ENCRYPTED = 'DEFAULT')
60+
ALTER TABLE `t4` PARTITION BY RANGE(id) (
61+
PARTITION pt1 VALUES LESS THAN (100),
62+
PARTITION pt2 VALUES LESS THAN MAXVALUE
63+
);
64+
SHOW CREATE TABLE `t4`;
65+
Table Create Table
66+
t4 CREATE TABLE `t4` (
67+
`id` int(11) DEFAULT NULL
68+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='NO'
69+
PARTITION BY RANGE (`id`)
70+
(PARTITION `pt1` VALUES LESS THAN (100) ENGINE = InnoDB,
71+
PARTITION `pt2` VALUES LESS THAN MAXVALUE ENGINE = InnoDB)
72+
ALTER TABLE `t4` PARTITION BY RANGE(id) (
73+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES" ENCRYPTION_KEY_ID=2,
74+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="DEFAULT"
75+
);
76+
ERROR HY000: Can't create table `test`.`t4` (errno: 140 "Wrong create options")
77+
DROP TABLE `t4`;
78+
# subpartitioned tables
79+
CREATE TABLE `t5` (
80+
`id` INT
81+
) ENGINE=InnoDB ENCRYPTED="NO" PARTITION BY RANGE(id)
82+
SUBPARTITION BY HASH(id)
83+
SUBPARTITIONS 2 (
84+
PARTITION pt1 VALUES LESS THAN (100),
85+
PARTITION pt2 VALUES LESS THAN MAXVALUE
86+
);
87+
SHOW CREATE TABLE `t5`;
88+
Table Create Table
89+
t5 CREATE TABLE `t5` (
90+
`id` int(11) DEFAULT NULL
91+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='NO'
92+
PARTITION BY RANGE (`id`)
93+
SUBPARTITION BY HASH (`id`)
94+
SUBPARTITIONS 2
95+
(PARTITION `pt1` VALUES LESS THAN (100) ENGINE = InnoDB,
96+
PARTITION `pt2` VALUES LESS THAN MAXVALUE ENGINE = InnoDB)
97+
DROP TABLE `t5`;
98+
CREATE TABLE `t6` (
99+
`id` INT
100+
) ENGINE=InnoDB PARTITION BY RANGE(id)
101+
SUBPARTITION BY HASH(id)
102+
SUBPARTITIONS 2 (
103+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES",
104+
PARTITION pt2 VALUES LESS THAN MAXVALUE
105+
);
106+
ERROR HY000: Can't create table `test`.`t6` (errno: 140 "Wrong create options")
107+
CREATE TABLE `t7` (
108+
id INT
109+
) ENGINE=InnoDB PARTITION BY RANGE(id)
110+
SUBPARTITION BY HASH(id) (
111+
PARTITION pt1 VALUES LESS THAN (100)(
112+
SUBPARTITION spt1 ENCRYPTED="NO",
113+
SUBPARTITION spt2
114+
),
115+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
116+
SUBPARTITION spt3,
117+
SUBPARTITION spt4
118+
)
119+
);
120+
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 'ENCRYPTED="NO",
121+
SUBPARTITION spt2
122+
),
123+
PARTITION pt2 VALUES LESS THAN MAXVALUE ...' at line 6
124+
CREATE TABLE `t8` (
125+
id INT
126+
) ENGINE=InnoDB ENCRYPTED="NO" PARTITION BY RANGE(id)
127+
SUBPARTITION BY HASH(id) (
128+
PARTITION pt1 VALUES LESS THAN (100) (
129+
SUBPARTITION spt1,
130+
SUBPARTITION spt2
131+
),
132+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
133+
SUBPARTITION spt3,
134+
SUBPARTITION spt4
135+
)
136+
);
137+
SHOW CREATE TABLE `t8`;
138+
Table Create Table
139+
t8 CREATE TABLE `t8` (
140+
`id` int(11) DEFAULT NULL
141+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='NO'
142+
PARTITION BY RANGE (`id`)
143+
SUBPARTITION BY HASH (`id`)
144+
(PARTITION `pt1` VALUES LESS THAN (100)
145+
(SUBPARTITION `spt1` ENGINE = InnoDB,
146+
SUBPARTITION `spt2` ENGINE = InnoDB),
147+
PARTITION `pt2` VALUES LESS THAN MAXVALUE
148+
(SUBPARTITION `spt3` ENGINE = InnoDB,
149+
SUBPARTITION `spt4` ENGINE = InnoDB))
150+
DROP TABLE `t8`;
151+
CREATE TABLE `t9` (
152+
id INT
153+
) ENGINE=InnoDB PARTITION BY RANGE(id)
154+
SUBPARTITION BY HASH(id) (
155+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO" (
156+
SUBPARTITION spt1,
157+
SUBPARTITION spt2
158+
),
159+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
160+
SUBPARTITION spt3,
161+
SUBPARTITION spt4
162+
)
163+
);
164+
SHOW CREATE TABLE `t9`;
165+
Table Create Table
166+
t9 CREATE TABLE `t9` (
167+
`id` int(11) DEFAULT NULL
168+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
169+
PARTITION BY RANGE (`id`)
170+
SUBPARTITION BY HASH (`id`)
171+
(PARTITION `pt1` VALUES LESS THAN (100)
172+
(SUBPARTITION `spt1` ENGINE = InnoDB,
173+
SUBPARTITION `spt2` ENGINE = InnoDB),
174+
PARTITION `pt2` VALUES LESS THAN MAXVALUE
175+
(SUBPARTITION `spt3` ENGINE = InnoDB,
176+
SUBPARTITION `spt4` ENGINE = InnoDB))
177+
DROP TABLE `t9`;
178+
CREATE TABLE `t10` (
179+
id INT
180+
) ENGINE=InnoDB PARTITION BY RANGE(id)
181+
SUBPARTITION BY HASH(id) (
182+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES" (
183+
SUBPARTITION spt1,
184+
SUBPARTITION spt2
185+
),
186+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
187+
SUBPARTITION spt3,
188+
SUBPARTITION spt4
189+
)
190+
);
191+
ERROR HY000: Can't create table `test`.`t10` (errno: 140 "Wrong create options")
192+
CREATE TABLE `t11` (
193+
id INT
194+
) ENGINE=InnoDB ENCRYPTED="YES" PARTITION BY RANGE(id)
195+
SUBPARTITION BY HASH(id) (
196+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO" (
197+
SUBPARTITION spt1,
198+
SUBPARTITION spt2
199+
),
200+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="NO" (
201+
SUBPARTITION spt3,
202+
SUBPARTITION spt4
203+
)
204+
);
205+
SHOW CREATE TABLE `t11`;
206+
Table Create Table
207+
t11 CREATE TABLE `t11` (
208+
`id` int(11) DEFAULT NULL
209+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `ENCRYPTED`='YES'
210+
PARTITION BY RANGE (`id`)
211+
SUBPARTITION BY HASH (`id`)
212+
(PARTITION `pt1` VALUES LESS THAN (100)
213+
(SUBPARTITION `spt1` ENGINE = InnoDB,
214+
SUBPARTITION `spt2` ENGINE = InnoDB),
215+
PARTITION `pt2` VALUES LESS THAN MAXVALUE
216+
(SUBPARTITION `spt3` ENGINE = InnoDB,
217+
SUBPARTITION `spt4` ENGINE = InnoDB))
218+
DROP TABLE `t11`;
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
--echo #
2+
--echo # MDEV-5271 Support engine-defined attributes per partition
3+
--echo #
4+
5+
--source include/have_partition.inc
6+
--source include/have_innodb.inc
7+
8+
--echo # partitioned tables
9+
10+
CREATE TABLE `t1` (
11+
`id` INT
12+
) ENGINE=InnoDB ENCRYPTED="YES" PARTITION BY RANGE(id) (
13+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO" ENCRYPTION_KEY_ID=1,
14+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="DEFAULT" ENCRYPTION_KEY_ID=1
15+
);
16+
SHOW CREATE TABLE `t1`;
17+
18+
INSERT INTO t1 VALUES (1), (2), (3);
19+
DELETE FROM t1 WHERE id = 1;
20+
UPDATE t1 SET id = 4 WHERE id = 3;
21+
SELECT * FROM t1 WHERE id IN (2, 3);
22+
23+
DROP TABLE `t1`;
24+
25+
--error ER_CANT_CREATE_TABLE
26+
CREATE TABLE `t2` (
27+
`id` INT
28+
) ENGINE=InnoDB ENCRYPTED="YES" ENCRYPTION_KEY_ID=2 PARTITION BY RANGE(id) (
29+
PARTITION pt1 VALUES LESS THAN (100),
30+
PARTITION pt2 VALUES LESS THAN MAXVALUE
31+
);
32+
33+
--error ER_CANT_CREATE_TABLE
34+
CREATE TABLE `t3` (
35+
`id` INT
36+
) ENGINE=InnoDB ENCRYPTED="NO" PARTITION BY RANGE(id) (
37+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES" ENCRYPTION_KEY_ID=2,
38+
PARTITION pt2 VALUES LESS THAN MAXVALUE
39+
);
40+
41+
CREATE TABLE `t4` (
42+
`id` INT
43+
) ENGINE=InnoDB ENCRYPTED="NO";
44+
SHOW CREATE TABLE `t4`;
45+
46+
ALTER TABLE `t4` PARTITION BY RANGE(id) (
47+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO",
48+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="DEFAULT"
49+
);
50+
SHOW CREATE TABLE `t4`;
51+
52+
ALTER TABLE `t4` PARTITION BY RANGE(id) (
53+
PARTITION pt1 VALUES LESS THAN (100),
54+
PARTITION pt2 VALUES LESS THAN MAXVALUE
55+
);
56+
SHOW CREATE TABLE `t4`;
57+
58+
--error ER_CANT_CREATE_TABLE
59+
ALTER TABLE `t4` PARTITION BY RANGE(id) (
60+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES" ENCRYPTION_KEY_ID=2,
61+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="DEFAULT"
62+
);
63+
64+
DROP TABLE `t4`;
65+
66+
--echo # subpartitioned tables
67+
68+
CREATE TABLE `t5` (
69+
`id` INT
70+
) ENGINE=InnoDB ENCRYPTED="NO" PARTITION BY RANGE(id)
71+
SUBPARTITION BY HASH(id)
72+
SUBPARTITIONS 2 (
73+
PARTITION pt1 VALUES LESS THAN (100),
74+
PARTITION pt2 VALUES LESS THAN MAXVALUE
75+
);
76+
SHOW CREATE TABLE `t5`;
77+
78+
DROP TABLE `t5`;
79+
80+
--error ER_CANT_CREATE_TABLE
81+
CREATE TABLE `t6` (
82+
`id` INT
83+
) ENGINE=InnoDB PARTITION BY RANGE(id)
84+
SUBPARTITION BY HASH(id)
85+
SUBPARTITIONS 2 (
86+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES",
87+
PARTITION pt2 VALUES LESS THAN MAXVALUE
88+
);
89+
90+
--error ER_PARSE_ERROR
91+
CREATE TABLE `t7` (
92+
id INT
93+
) ENGINE=InnoDB PARTITION BY RANGE(id)
94+
SUBPARTITION BY HASH(id) (
95+
PARTITION pt1 VALUES LESS THAN (100)(
96+
SUBPARTITION spt1 ENCRYPTED="NO",
97+
SUBPARTITION spt2
98+
),
99+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
100+
SUBPARTITION spt3,
101+
SUBPARTITION spt4
102+
)
103+
);
104+
105+
CREATE TABLE `t8` (
106+
id INT
107+
) ENGINE=InnoDB ENCRYPTED="NO" PARTITION BY RANGE(id)
108+
SUBPARTITION BY HASH(id) (
109+
PARTITION pt1 VALUES LESS THAN (100) (
110+
SUBPARTITION spt1,
111+
SUBPARTITION spt2
112+
),
113+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
114+
SUBPARTITION spt3,
115+
SUBPARTITION spt4
116+
)
117+
);
118+
SHOW CREATE TABLE `t8`;
119+
120+
DROP TABLE `t8`;
121+
122+
CREATE TABLE `t9` (
123+
id INT
124+
) ENGINE=InnoDB PARTITION BY RANGE(id)
125+
SUBPARTITION BY HASH(id) (
126+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO" (
127+
SUBPARTITION spt1,
128+
SUBPARTITION spt2
129+
),
130+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
131+
SUBPARTITION spt3,
132+
SUBPARTITION spt4
133+
)
134+
);
135+
SHOW CREATE TABLE `t9`;
136+
137+
DROP TABLE `t9`;
138+
139+
--error ER_CANT_CREATE_TABLE
140+
CREATE TABLE `t10` (
141+
id INT
142+
) ENGINE=InnoDB PARTITION BY RANGE(id)
143+
SUBPARTITION BY HASH(id) (
144+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="YES" (
145+
SUBPARTITION spt1,
146+
SUBPARTITION spt2
147+
),
148+
PARTITION pt2 VALUES LESS THAN MAXVALUE (
149+
SUBPARTITION spt3,
150+
SUBPARTITION spt4
151+
)
152+
);
153+
154+
CREATE TABLE `t11` (
155+
id INT
156+
) ENGINE=InnoDB ENCRYPTED="YES" PARTITION BY RANGE(id)
157+
SUBPARTITION BY HASH(id) (
158+
PARTITION pt1 VALUES LESS THAN (100) ENCRYPTED="NO" (
159+
SUBPARTITION spt1,
160+
SUBPARTITION spt2
161+
),
162+
PARTITION pt2 VALUES LESS THAN MAXVALUE ENCRYPTED="NO" (
163+
SUBPARTITION spt3,
164+
SUBPARTITION spt4
165+
)
166+
);
167+
SHOW CREATE TABLE `t11`;
168+
169+
DROP TABLE `t11`;

0 commit comments

Comments
 (0)