일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- zabbix
- cdb
- DML
- ncloud
- mongo
- RDS
- 성능테스트
- MyISAM
- DELETE
- Connection
- NOSQL
- online ddl
- Maria
- Docker
- maxclients
- vacuum
- mysql
- RDBMS
- NCP
- 6.2.7
- REDIS
- InnoDB
- Cloud DB for MySQL
- slack
- jmeter
- autovacuum
- postgresql
- opensource
- percona
- OD
- Today
- Total
개인 공부
[ MySQL ] Online DDL - Varchar 본문
MySQL 5.6부터 Online DDL을 사용할 수 있게 되었고 인덱스 칼럼 추가/삭제 등 이렇게 Online DDL이 지원하게 되면서 pt-online-schema-change tool을 사용하지 않고도 서비스 중단 없이 DDL을 수행할 수 있게 되었다.
이번에는 Online DDl에서 VARCHAR Column을 변경할때 발생할 수 있는 문제 상황을 테스트해보았다.
■ VARCAHR Size Extension
- https://dev.mysql.com/doc/refman/5.7/en/innodb-online-ddl-operations.html
The number of length bytes required by a VARCHAR column must remain the same. For VARCHAR columns of 0 to 255 bytes in size, one length byte is required to encode the value. For VARCHAR columns of 256 bytes in size or more, two length bytes are required. As a result, in-place ALTER TABLE only supports increasing VARCHAR column size from 0 to 255 bytes, or from 256 bytes to a greater size. In-place ALTER TABLE does not support increasing the size of a VARCHAR column from less than 256 bytes to a size equal to or greater than 256 bytes. In this case, the number of required length bytes changes from 1 to 2, which is only supported by a table copy (ALGORITHM=COPY)
■ VARCAHR Online DDL 테스트
- 같은 구간인 8(1~63) -> 16(1~63) 으로 변경하였을 경우는 Inplace 알고리즘을 사용하여 ONLINE DDL이 가능하다.
- 다른 구간인 16(1~63) -> 255(64 이상 구간)의 경우 inplace 알고리즘을 사용하게 되면 ERROR가 발생하고 COPY 알고리즘을 사용하게 된다. 이때 TABLE LOCK이 발생하게 된다.
1. 테스트 Table 생성
CREATE TABLE `test` (
`a` varchar(8) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
2. VARCHAR(8) -> VARCHAR(16)
mysql> alter table test modify a varchar(16), algorithm=inplace;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
3. VARCHAR(16) -> VARCHAR(255)
mysql> alter table test modify a varchar(255), algorithm=inplace;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.
mysql> alter table test modify a varchar(255), algorithm=COPY;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
■ 참조
'MySQL & Maria' 카테고리의 다른 글
[Maria] Galera Cluster to Single DB(DR) (0) | 2022.05.07 |
---|---|
[ Maria ] DDL시 Replication Delay 발생 (0) | 2022.04.26 |
[Maria] Maxscale GUI 설치 (2) | 2022.03.22 |
[ MySQL & Maria ] Innodb_buffer_pool 사용량 조회 (0) | 2022.03.21 |
MRTE ( MySQL Real Traffic Emulator ) (0) | 2022.01.21 |