Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decimal type fields cannot be resized or precision improved within the partition table #54441

Open
tonyhu214 opened this issue Jul 4, 2024 · 3 comments
Labels
component/ddl This issue is related to DDL of TiDB. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 report/community The community has encountered this bug. severity/major type/bug This issue is a bug.

Comments

@tonyhu214
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table test(
id int not null primary key auto_increment,
cost decimal(10,0) default 0 not null
)engine = innodb
partition by hash(id)
PARTITIONS 4 ;

alter table test modify column cost decimal(20,4) default 0 not null;

2. What did you expect to see? (Required)

sql error : Unsupported modify column: table is partition table

3. What did you see instead (Required)

Change fields to decimal(20,4)

4. What is your TiDB version? (Required)

6.5.0 +

@tonyhu214 tonyhu214 added the type/bug This issue is a bug. label Jul 4, 2024
@Defined2014 Defined2014 added the component/ddl This issue is related to DDL of TiDB. label Jul 5, 2024
@River2000i
Copy link
Contributor

seems block from

tidb/pkg/ddl/ddl_api.go

Lines 6006 to 6014 in 7d5f1d7

needChangeColData := needChangeColumnData(col.ColumnInfo, newCol.ColumnInfo)
if needChangeColData {
if err = isGeneratedRelatedColumn(t.Meta(), newCol.ColumnInfo, col.ColumnInfo); err != nil {
return nil, errors.Trace(err)
}
if t.Meta().Partition != nil {
return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStackByArgs("table is partition table")
}
}

@tonyhu214
Copy link
Author

TKS!Based on your information, I took a closer look at the code for the needChangeColumnData function.

tidb/pkg/ddl/column.go

Lines 386 to 402 in d8098b9

// Deal with the same type.
if oldCol.GetType() == newCol.GetType() {
switch oldCol.GetType() {
case mysql.TypeNewDecimal:
// Since type decimal will encode the precision, frac, negative(signed) and wordBuf into storage together, there is no short
// cut to eliminate data reorg change for column type change between decimal.
return oldCol.GetFlen() != newCol.GetFlen() || oldCol.GetDecimal() != newCol.GetDecimal() || toUnsigned != originUnsigned
case mysql.TypeEnum, mysql.TypeSet:
return IsElemsChangedToModifyColumn(oldCol.GetElems(), newCol.GetElems())
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
return toUnsigned != originUnsigned
case mysql.TypeString:
// Due to the behavior of padding \x00 at binary type, always change column data when binary length changed
if types.IsBinaryStr(&oldCol.FieldType) {
return newCol.GetFlen() != oldCol.GetFlen()
}
}

How do I go about understanding how the decimal type is stored in TiDB?Is there any code that can be viewed?

@tonyhu214
Copy link
Author

Of course. MySQL supports changes to the decimal type of partitioned tables. I hope Tidb can also support it.

@seiya-annie seiya-annie added the report/community The community has encountered this bug. label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ddl This issue is related to DDL of TiDB. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 report/community The community has encountered this bug. severity/major type/bug This issue is a bug.
5 participants