Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 分区表 decimal精度无法扩容
[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version] V6.5.0+
[Reproduction Path] Changing the decimal type field of a partitioned table from decimal(10,0) to decimal(20,4) results in an error: Unsupported modify column: table is partition table. According to the official documentation, it seems that there is no column type change.
I tested it, and it really doesn’t work. However, the length of the varchar type can be modified. Is the decimal type more special?
I remember that in MySQL, the precision of the decimal type in partitioned tables cannot be directly modified either.
A regular table should work, but a partitioned table won’t.
Varchar can only be increased, not decreased.
Changing from decimal(10,0) to decimal(20,4) increases the precision, and the field is not truncated.
I originally wanted to look at the source code, but I didn’t know where to start.
I also tried changing from decimal(10,0) to decimal(11,0), and it is not supported either.
However, changing varchar(20) to varchar(30) is possible, but changing it to varchar(10) is not.
This is the standard expectation , fields can only be expanded, not reduced.
Mark, I really didn’t know about this restriction before.
So it might really be that the decimal field type is quite special.
I tried it with MySQL and it worked. For TiDB, the internal format for decimal is in pkg/types/mydecimal. I see there is an add method, maybe it is not fully developed yet?
Based on the source code location you mentioned, I checked it. The pkg/types/mydecimal directory contains functions for decimal type calculations. I think it should be in ddl/column.go.
Yes, it should be in the file you mentioned, the onModifyColumn method. Check how MySQL handles it.
It is not supported. You can only add a column, then update, and delete that column. In change.
This is the issue I submitted. After receiving the relevant reply, I checked the code. The source code in pkg/ddl/ddl_api.go intercepted the error.
Looking at the needChangeColumnData function, I found that the source code should actually be doing a decimal expansion check. Then, when judging the same type of change, it directly returns true. After reading the comments, how does a non-partitioned table change?
The main point is here:
If needChangeColumnData is true, it will reach here. As long as it is a partitioned table, it will directly return a “table is partition table” error. Only non-partitioned tables can proceed normally.