Skip to content

Commit b7bba72

Browse files
midenokvuvova
authored andcommitted
MDEV-22166 CONVERT PARTITION: move out partition into a table
Syntax for CONVERT keyword ALTER TABLE tbl_name [alter_option [, alter_option] ...] | [partition_options] partition_option: { ... | CONVERT PARTITION partition_name TO TABLE tbl_name } Examples: ALTER TABLE t1 CONVERT PARTITION p2 TO TABLE tp2; New ALTER_PARTITION_CONVERT_OUT command for fast_alter_partition_table() is done in alter_partition_convert_out() function which basically does ha_rename_table(). Partition to extract is marked with the same flag as dropped partition: PART_TO_BE_DROPPED. Note that we cannot have multiple partitioning commands in one ALTER. For DDL logging basically the principle is the same as for other fast_alter_partition_table() commands. The only difference is that it integrates late Atomic DDL functions and introduces additional phase of WFRM_BACKUP_ORIGINAL. That is required for binlog consistency because otherwise we could not revert back after WFRM_INSTALL_SHADOW is done. And before DDL log is complete if we crash or fail the altered table will be already new but binlog will miss that ALTER command. Note that this is different from all other atomic DDL in that it rolls back until the ddl_log_complete() is done even if everything was done fully before the crash. Test cases added to: parts.alter_table \ parts.partition_debug \ versioning.partition \ atomic.alter_partition
1 parent f6b0e34 commit b7bba72

29 files changed

+4280
-72
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[row]
2+
binlog-format=row
3+
4+
[stmt]
5+
binlog-format=statement
6+
7+
[mix]
8+
binlog-format=mixed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# The goal of including this file is to test with different
2+
# binlog combinations: row, stmt or mix
3+
# (see include/binlog_combinations.combinations)
4+
5+
--source include/have_log_bin.inc
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[lcase_def]
2+
[lcase1]
3+
lower_case_table_names=1
4+
[lcase2]
5+
lower_case_table_names=2

mysql-test/include/lcase_names.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The goal of including this file is to test with different
2+
# lower_case_table_names modes (see include/lcase_name.combinations)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[innodb]
2+
innodb
3+
4+
[myisam]
5+
6+
[aria]
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
# Crash recovery
2+
create or replace procedure prepare_table()
3+
begin
4+
create or replace table t1 (x int)
5+
with system versioning
6+
partition by range(x) (
7+
partition p0 values less than (10),
8+
partition p1 values less than (20),
9+
partition pn values less than maxvalue);
10+
insert into t1 values (2), (12), (22);
11+
flush tables;
12+
end $
13+
# QUERY: ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1
14+
# CRASH: ddl_log_create_before_create_frm
15+
t1#P#p0.MYD
16+
t1#P#p0.MYI
17+
t1#P#p1.MYD
18+
t1#P#p1.MYI
19+
t1#P#pn.MYD
20+
t1#P#pn.MYI
21+
t1.frm
22+
t1.par
23+
Table Create Table
24+
t1 CREATE TABLE `t1` (
25+
`x` int(11) DEFAULT NULL
26+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
27+
PARTITION BY RANGE (`x`)
28+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
29+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
30+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
31+
x
32+
2
33+
12
34+
22
35+
# CRASH: ddl_log_alter_partition_after_create_frm
36+
t1#P#p0.MYD
37+
t1#P#p0.MYI
38+
t1#P#p1.MYD
39+
t1#P#p1.MYI
40+
t1#P#pn.MYD
41+
t1#P#pn.MYI
42+
t1.frm
43+
t1.par
44+
Table Create Table
45+
t1 CREATE TABLE `t1` (
46+
`x` int(11) DEFAULT NULL
47+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
48+
PARTITION BY RANGE (`x`)
49+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
50+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
51+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
52+
x
53+
2
54+
12
55+
22
56+
# CRASH: ddl_log_alter_partition_after_write_frm
57+
t1#P#p0.MYD
58+
t1#P#p0.MYI
59+
t1#P#p1.MYD
60+
t1#P#p1.MYI
61+
t1#P#pn.MYD
62+
t1#P#pn.MYI
63+
t1.frm
64+
t1.par
65+
Table Create Table
66+
t1 CREATE TABLE `t1` (
67+
`x` int(11) DEFAULT NULL
68+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
69+
PARTITION BY RANGE (`x`)
70+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
71+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
72+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
73+
x
74+
2
75+
12
76+
22
77+
# CRASH: crash_convert_partition_1
78+
t1#P#p0.MYD
79+
t1#P#p0.MYI
80+
t1#P#p1.MYD
81+
t1#P#p1.MYI
82+
t1#P#pn.MYD
83+
t1#P#pn.MYI
84+
t1.frm
85+
t1.par
86+
Table Create Table
87+
t1 CREATE TABLE `t1` (
88+
`x` int(11) DEFAULT NULL
89+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
90+
PARTITION BY RANGE (`x`)
91+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
92+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
93+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
94+
x
95+
2
96+
12
97+
22
98+
# CRASH: crash_convert_partition_2
99+
t1#P#p0.MYD
100+
t1#P#p0.MYI
101+
t1#P#p1.MYD
102+
t1#P#p1.MYI
103+
t1#P#pn.MYD
104+
t1#P#pn.MYI
105+
t1.frm
106+
t1.par
107+
Table Create Table
108+
t1 CREATE TABLE `t1` (
109+
`x` int(11) DEFAULT NULL
110+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
111+
PARTITION BY RANGE (`x`)
112+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
113+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
114+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
115+
x
116+
2
117+
12
118+
22
119+
# CRASH: crash_convert_partition_3
120+
t1#P#p0.MYD
121+
t1#P#p0.MYI
122+
t1#P#p1.MYD
123+
t1#P#p1.MYI
124+
t1#P#pn.MYD
125+
t1#P#pn.MYI
126+
t1.frm
127+
t1.par
128+
Table Create Table
129+
t1 CREATE TABLE `t1` (
130+
`x` int(11) DEFAULT NULL
131+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
132+
PARTITION BY RANGE (`x`)
133+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
134+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
135+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
136+
x
137+
2
138+
12
139+
22
140+
# CRASH: crash_convert_partition_4
141+
t1#P#p0.MYD
142+
t1#P#p0.MYI
143+
t1#P#p1.MYD
144+
t1#P#p1.MYI
145+
t1#P#pn.MYD
146+
t1#P#pn.MYI
147+
t1.frm
148+
t1.par
149+
Table Create Table
150+
t1 CREATE TABLE `t1` (
151+
`x` int(11) DEFAULT NULL
152+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
153+
PARTITION BY RANGE (`x`)
154+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
155+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
156+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
157+
x
158+
2
159+
12
160+
22
161+
# CRASH: crash_convert_partition_5
162+
t1#P#p0.MYD
163+
t1#P#p0.MYI
164+
t1#P#p1.MYD
165+
t1#P#p1.MYI
166+
t1#P#pn.MYD
167+
t1#P#pn.MYI
168+
t1.frm
169+
t1.par
170+
Table Create Table
171+
t1 CREATE TABLE `t1` (
172+
`x` int(11) DEFAULT NULL
173+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
174+
PARTITION BY RANGE (`x`)
175+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
176+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
177+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
178+
x
179+
2
180+
12
181+
22
182+
# CRASH: crash_convert_partition_6
183+
t1#P#p0.MYD
184+
t1#P#p0.MYI
185+
t1#P#p1.MYD
186+
t1#P#p1.MYI
187+
t1#P#pn.MYD
188+
t1#P#pn.MYI
189+
t1.frm
190+
t1.par
191+
Table Create Table
192+
t1 CREATE TABLE `t1` (
193+
`x` int(11) DEFAULT NULL
194+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
195+
PARTITION BY RANGE (`x`)
196+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
197+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
198+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
199+
x
200+
2
201+
12
202+
22
203+
# CRASH: crash_convert_partition_7
204+
t1#P#p0.MYD
205+
t1#P#p0.MYI
206+
t1#P#p1.MYD
207+
t1#P#p1.MYI
208+
t1#P#pn.MYD
209+
t1#P#pn.MYI
210+
t1.frm
211+
t1.par
212+
Table Create Table
213+
t1 CREATE TABLE `t1` (
214+
`x` int(11) DEFAULT NULL
215+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
216+
PARTITION BY RANGE (`x`)
217+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
218+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
219+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
220+
x
221+
2
222+
12
223+
22
224+
# CRASH: crash_convert_partition_8
225+
t1#P#p0.MYD
226+
t1#P#p0.MYI
227+
t1#P#p1.MYD
228+
t1#P#p1.MYI
229+
t1#P#pn.MYD
230+
t1#P#pn.MYI
231+
t1.frm
232+
t1.par
233+
Table Create Table
234+
t1 CREATE TABLE `t1` (
235+
`x` int(11) DEFAULT NULL
236+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
237+
PARTITION BY RANGE (`x`)
238+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
239+
PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE,
240+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
241+
x
242+
2
243+
12
244+
22
245+
# CRASH: crash_convert_partition_9
246+
t1#P#p0.MYD
247+
t1#P#p0.MYI
248+
t1#P#pn.MYD
249+
t1#P#pn.MYI
250+
t1.frm
251+
t1.par
252+
tp1.MYD
253+
tp1.MYI
254+
tp1.frm
255+
master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1
256+
Table Create Table
257+
t1 CREATE TABLE `t1` (
258+
`x` int(11) DEFAULT NULL
259+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
260+
PARTITION BY RANGE (`x`)
261+
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE,
262+
PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE)
263+
x
264+
2
265+
22
266+
Table Create Table
267+
tp1 CREATE TABLE `tp1` (
268+
`x` int(11) DEFAULT NULL
269+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
270+
x
271+
12
272+
Warnings:
273+
Note 1051 Unknown table 'test.t1'

0 commit comments

Comments
 (0)