ddl: fix issue that cannot modify other columns on auto_random table (#18664)

This commit is contained in:
tangenta
2020-07-17 16:48:21 +08:00
committed by GitHub
parent ef913dc0c8
commit d86cb284e2
2 changed files with 13 additions and 2 deletions

View File

@ -3562,7 +3562,10 @@ func checkColumnWithIndexConstraint(tbInfo *model.TableInfo, originalCol, newCol
func checkAutoRandom(tableInfo *model.TableInfo, originCol *table.Column, specNewColumn *ast.ColumnDef) (uint64, error) {
// Disallow add/drop actions on auto_random.
oldRandBits := tableInfo.AutoRandomBits
var oldRandBits uint64
if tableInfo.PKIsHandle && (tableInfo.GetPkName().L == originCol.Name.L) {
oldRandBits = tableInfo.AutoRandomBits
}
newRandBits, err := extractAutoRandomBitsFromColDef(specNewColumn)
if err != nil {
return 0, errors.Trace(err)

View File

@ -1028,6 +1028,7 @@ func (s *testSerialSuite) TestAutoRandom(c *C) {
// Add/drop the auto_random attribute is not allowed.
mustExecAndDrop("create table t (a bigint auto_random(3) primary key)", func() {
assertAlterValue("alter table t modify column a bigint")
assertAlterValue("alter table t modify column a bigint auto_random(0)")
assertAlterValue("alter table t change column a b bigint")
})
mustExecAndDrop("create table t (a bigint, b char, c bigint auto_random(3), primary key(c))", func() {
@ -1037,6 +1038,10 @@ func (s *testSerialSuite) TestAutoRandom(c *C) {
mustExecAndDrop("create table t (a bigint primary key)", func() {
assertAlterValue("alter table t modify column a bigint auto_random(3)")
})
mustExecAndDrop("create table t (a bigint, b bigint, primary key(a, b))", func() {
assertAlterValue("alter table t modify column a bigint auto_random(3)")
assertAlterValue("alter table t modify column b bigint auto_random(3)")
})
// Decrease auto_random bits is not allowed.
mustExecAndDrop("create table t (a bigint auto_random(10) primary key)", func() {
@ -1064,10 +1069,13 @@ func (s *testSerialSuite) TestAutoRandom(c *C) {
// Here the throw error is `ERROR 8200 (HY000): Unsupported modify column: length 11 is less than origin 20`,
// instead of `ERROR 8216 (HY000): Invalid auto random: modifying the auto_random column type is not supported`
// Because the origin column is `bigint`, it can not change to any other column type in TiDB limitation.
mustExecAndDrop("create table t (a bigint primary key auto_random(3))", func() {
mustExecAndDrop("create table t (a bigint primary key auto_random(3), b int)", func() {
assertModifyColType("alter table t modify column a int auto_random(3)")
assertModifyColType("alter table t modify column a mediumint auto_random(3)")
assertModifyColType("alter table t modify column a smallint auto_random(3)")
tk.MustExec("alter table t modify column b int")
tk.MustExec("alter table t modify column b bigint")
tk.MustExec("alter table t modify column a bigint auto_random(3)")
})
// Test show warnings when create auto_random table.