A Question About Online DDL

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 关于在线DDL的一个问题

| username: terry0219

[Test/Poc Environment] TiDB
[TiDB Version] 7.5.1
Changing a table column from varchar(100) to varchar(200) is very fast, at the millisecond level. However, changing from varchar(200) to varchar(100) is very slow. When checking with admin show ddl jobs, the operation status is “write reorganization”. What is the reason for this?

| username: 小龙虾爱大龙虾 | Original post link

Changing varchar(100) to varchar(200) should only require modifying the metadata.
Changing varchar(200) to varchar(100) requires backfilling data, which means rewriting everything.

| username: DBAER | Original post link

The size of general types usually increases rather than decreases. Why do you need to reduce it?

| username: 数据库真NB | Original post link

All shrinking involves clearing the original data and then writing it back.

| username: xiaoqiao | Original post link

Considering the data issue

| username: Hacker_QGgM2nks | Original post link

Why does it get smaller? What kind of operation is this? If it gets smaller, to ensure the data is correct, shouldn’t it need to be rewritten?

| username: vincentLi | Original post link

It feels like it’s caused by simple internal processing logic.
Expanding a field only requires modifying some metadata, but shortening it involves the issue of legality after shortening.
I guess TiDB’s internal logic does not record the current maximum length of the table field data. If it recorded the maximum length of all current rows, it should be possible to just modify the metadata, right?

| username: zhaokede | Original post link

The difference between one that does not process data and one that needs to process data.

| username: 健康的腰间盘 | Original post link

Will it automatically truncate when it gets smaller?

| username: Mingdr | Original post link

What if it exceeds 100? Should we exit or continue?

| username: 小龙虾爱大龙虾 | Original post link

It will report an error and exit.

| username: stephanie | Original post link

I think one is logical DDL, and the other is physical DDL. Physical DDL will perform reorg operations, so it will be relatively slow.
Principles and Best Practices of DDL Statements | PingCAP Documentation Center

| username: TiDBer_HErMeXDz | Original post link

Execution Principles and Best Practices of DDL Statements | PingCAP Documentation Center

| username: terry0219 | Original post link

Got it.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.