From 5d454a1eb493aa8b0a219389914143450c8075ff Mon Sep 17 00:00:00 2001 From: xhe Date: Fri, 21 Aug 2020 16:30:57 +0800 Subject: [PATCH 1/2] cherry pick #19270 to release-4.0 Signed-off-by: ti-srebot --- ddl/db_integration_test.go | 96 ++++++++++++++++++++++++++- ddl/ddl_algorithm.go | 18 +++-- ddl/ddl_algorithm_test.go | 71 ++++++++++++-------- ddl/ddl_api.go | 6 +- executor/seqtest/seq_executor_test.go | 7 +- 5 files changed, 161 insertions(+), 37 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 6faf741ec2430..efdc7759726b2 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1212,6 +1212,7 @@ func (s *testIntegrationSuite6) TestCreateTableTooLarge(c *C) { } func (s *testIntegrationSuite3) TestChangeColumnPosition(c *C) { +<<<<<<< HEAD s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") @@ -1253,13 +1254,56 @@ func (s *testIntegrationSuite3) TestChangeColumnPosition(c *C) { s.tk.MustExec("alter table position4 change column b c int first") createSQL := s.tk.MustQuery("show create table position4").Rows()[0][1] exceptedSQL := []string{ +======= + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + + tk.MustExec("create table position (a int default 1, b int default 2)") + tk.MustExec("insert into position value ()") + tk.MustExec("insert into position values (3,4)") + tk.MustQuery("select * from position").Check(testkit.Rows("1 2", "3 4")) + tk.MustExec("alter table position modify column b int first") + tk.MustQuery("select * from position").Check(testkit.Rows("2 1", "4 3")) + tk.MustExec("insert into position value ()") + tk.MustQuery("select * from position").Check(testkit.Rows("2 1", "4 3", " 1")) + + tk.MustExec("create table position1 (a int, b int, c double, d varchar(5))") + tk.MustExec(`insert into position1 value (1, 2, 3.14, 'TiDB')`) + tk.MustExec("alter table position1 modify column d varchar(5) after a") + tk.MustQuery("select * from position1").Check(testkit.Rows("1 TiDB 2 3.14")) + tk.MustExec("alter table position1 modify column a int after c") + tk.MustQuery("select * from position1").Check(testkit.Rows("TiDB 2 3.14 1")) + tk.MustExec("alter table position1 modify column c double first") + tk.MustQuery("select * from position1").Check(testkit.Rows("3.14 TiDB 2 1")) + tk.MustGetErrCode("alter table position1 modify column b int after b", errno.ErrBadField) + + tk.MustExec("create table position2 (a int, b int)") + tk.MustExec("alter table position2 add index t(a, b)") + tk.MustExec("alter table position2 modify column b int first") + tk.MustExec("insert into position2 value (3, 5)") + tk.MustQuery("select a from position2 where a = 3").Check(testkit.Rows()) + tk.MustExec("alter table position2 change column b c int first") + tk.MustQuery("select * from position2 where c = 3").Check(testkit.Rows("3 5")) + tk.MustGetErrCode("alter table position2 change column c b int after c", errno.ErrBadField) + + tk.MustExec("create table position3 (a int default 2)") + tk.MustExec("alter table position3 modify column a int default 5 first") + tk.MustExec("insert into position3 value ()") + tk.MustQuery("select * from position3").Check(testkit.Rows("5")) + + tk.MustExec("create table position4 (a int, b int)") + tk.MustExec("alter table position4 add index t(b)") + tk.MustExec("alter table position4 change column b c int first") + createSQL := tk.MustQuery("show create table position4").Rows()[0][1] + expectedSQL := []string{ +>>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) "CREATE TABLE `position4` (", " `c` int(11) DEFAULT NULL,", " `a` int(11) DEFAULT NULL,", " KEY `t` (`c`)", ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", } - c.Assert(createSQL, Equals, strings.Join(exceptedSQL, "\n")) + c.Assert(createSQL, Equals, strings.Join(expectedSQL, "\n")) } func (s *testIntegrationSuite2) TestAddIndexAfterAddColumn(c *C) { @@ -1477,6 +1521,7 @@ func (s *testIntegrationSuite3) TestAlterAlgorithm(c *C) { PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN (21) )`) +<<<<<<< HEAD s.assertAlterErrorExec(c, "alter table t modify column a bigint, ALGORITHM=INPLACE;") s.tk.MustExec("alter table t modify column a bigint, ALGORITHM=INPLACE, ALGORITHM=INSTANT;") s.tk.MustExec("alter table t modify column a bigint, ALGORITHM=DEFAULT;") @@ -1523,6 +1568,55 @@ func (s *testIntegrationSuite3) TestAlterAlgorithm(c *C) { s.assertAlterWarnExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") s.assertAlterErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") +======= + s.assertAlterWarnExec(tk, c, "alter table t modify column a bigint, ALGORITHM=INPLACE;") + tk.MustExec("alter table t modify column a bigint, ALGORITHM=INPLACE, ALGORITHM=INSTANT;") + tk.MustExec("alter table t modify column a bigint, ALGORITHM=DEFAULT;") + + // Test add/drop index + s.assertAlterErrorExec(tk, c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") + s.assertAlterWarnExec(tk, c, "alter table t add index idx_b1(b), ALGORITHM=COPY") + tk.MustExec("alter table t add index idx_b2(b), ALGORITHM=INPLACE") + tk.MustExec("alter table t add index idx_b3(b), ALGORITHM=DEFAULT") + s.assertAlterWarnExec(tk, c, "alter table t drop index idx_b3, ALGORITHM=INPLACE") + s.assertAlterWarnExec(tk, c, "alter table t drop index idx_b1, ALGORITHM=COPY") + tk.MustExec("alter table t drop index idx_b2, ALGORITHM=INSTANT") + + // Test rename + s.assertAlterWarnExec(tk, c, "alter table t rename to t1, ALGORITHM=COPY") + s.assertAlterWarnExec(tk, c, "alter table t1 rename to t2, ALGORITHM=INPLACE") + tk.MustExec("alter table t2 rename to t, ALGORITHM=INSTANT") + tk.MustExec("alter table t rename to t1, ALGORITHM=DEFAULT") + tk.MustExec("alter table t1 rename to t") + + // Test rename index + s.assertAlterWarnExec(tk, c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") + s.assertAlterWarnExec(tk, c, "alter table t rename index idx_c1 to idx_c2, ALGORITHM=INPLACE") + tk.MustExec("alter table t rename index idx_c2 to idx_c, ALGORITHM=INSTANT") + tk.MustExec("alter table t rename index idx_c to idx_c1, ALGORITHM=DEFAULT") + + // partition. + s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=COPY, truncate partition p1") + s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=INPLACE, truncate partition p2") + tk.MustExec("alter table t ALGORITHM=INSTANT, truncate partition p3") + + s.assertAlterWarnExec(tk, c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") + s.assertAlterWarnExec(tk, c, "alter table t add partition (partition p5 values less than (3002)), ALGORITHM=INPLACE") + tk.MustExec("alter table t add partition (partition p6 values less than (4002)), ALGORITHM=INSTANT") + + s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=COPY, drop partition p4") + s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=INPLACE, drop partition p5") + tk.MustExec("alter table t ALGORITHM=INSTANT, drop partition p6") + + // Table options + s.assertAlterWarnExec(tk, c, "alter table t comment = 'test', ALGORITHM=COPY") + s.assertAlterWarnExec(tk, c, "alter table t comment = 'test', ALGORITHM=INPLACE") + tk.MustExec("alter table t comment = 'test', ALGORITHM=INSTANT") + + s.assertAlterWarnExec(tk, c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") + s.assertAlterWarnExec(tk, c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") + tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") +>>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) } func (s *testIntegrationSuite3) TestAlterTableAddUniqueOnPartionRangeColumn(c *C) { diff --git a/ddl/ddl_algorithm.go b/ddl/ddl_algorithm.go index b717ad724c99d..901fc6a6384d2 100644 --- a/ddl/ddl_algorithm.go +++ b/ddl/ddl_algorithm.go @@ -25,6 +25,7 @@ import ( // because we never block the DML but costs some time to backfill the index data) // See https://dev.mysql.com/doc/refman/8.0/en/alter-table.html#alter-table-performance. type AlterAlgorithm struct { + // supported MUST store algorithms in the order 'INSTANT, INPLACE, COPY' supported []ast.AlgorithmType // If the alter algorithm is not given, the defAlgorithm will be used. defAlgorithm ast.AlgorithmType @@ -47,18 +48,27 @@ func getProperAlgorithm(specify ast.AlgorithmType, algorithm *AlterAlgorithm) (a return algorithm.defAlgorithm, nil } + r := ast.AlgorithmTypeDefault + for _, a := range algorithm.supported { - if specify == a { - return specify, nil + if specify <= a { + r = a + break } } - return algorithm.defAlgorithm, ErrAlterOperationNotSupported.GenWithStackByArgs(fmt.Sprintf("ALGORITHM=%s", specify), fmt.Sprintf("Cannot alter table by %s", specify), fmt.Sprintf("ALGORITHM=%s", algorithm.defAlgorithm)) + var err error + if specify != r { + err = ErrAlterOperationNotSupported.GenWithStackByArgs(fmt.Sprintf("ALGORITHM=%s", specify), fmt.Sprintf("Cannot alter table by %s", specify), fmt.Sprintf("ALGORITHM=%s", algorithm.defAlgorithm)) + } + return r, err } // ResolveAlterAlgorithm resolves the algorithm of the alterSpec. -// If specify algorithm is not supported by the alter action, errAlterOperationNotSupported will be returned. // If specify is the ast.AlterAlgorithmDefault, then the default algorithm of the alter action will be returned. +// If specify algorithm is not supported by the alter action, it will try to find a better algorithm in the order `INSTANT > INPLACE > COPY`, errAlterOperationNotSupported will be returned. +// E.g. INSTANT may be returned if specify=INPLACE +// If failed to choose any valid algorithm, AlgorithmTypeDefault and errAlterOperationNotSupported will be returned func ResolveAlterAlgorithm(alterSpec *ast.AlterTableSpec, specify ast.AlgorithmType) (ast.AlgorithmType, error) { switch alterSpec.Tp { // For now, TiDB only support inplace algorithm and instant algorithm. diff --git a/ddl/ddl_algorithm_test.go b/ddl/ddl_algorithm_test.go index 0457c64ae8606..a99c9bb22b609 100644 --- a/ddl/ddl_algorithm_test.go +++ b/ddl/ddl_algorithm_test.go @@ -31,42 +31,55 @@ type testDDLAlgorithmSuite struct{} type testCase struct { alterSpec ast.AlterTableSpec supportedAlgorithm []ast.AlgorithmType - defAlgorithm ast.AlgorithmType + expectedAlgorithm []ast.AlgorithmType } func (s *testDDLAlgorithmSuite) TestFindAlterAlgorithm(c *C) { - instantAlgorithm := []ast.AlgorithmType{ast.AlgorithmTypeInstant} - inplaceAlgorithm := []ast.AlgorithmType{ast.AlgorithmTypeInplace} + supportedInstantAlgorithms := []ast.AlgorithmType{ast.AlgorithmTypeDefault, ast.AlgorithmTypeCopy, ast.AlgorithmTypeInplace, ast.AlgorithmTypeInstant} + expectedInstantAlgorithms := []ast.AlgorithmType{ast.AlgorithmTypeInstant, ast.AlgorithmTypeInstant, ast.AlgorithmTypeInstant, ast.AlgorithmTypeInstant} testCases := []testCase{ - {ast.AlterTableSpec{Tp: ast.AlterTableAddConstraint}, inplaceAlgorithm, ast.AlgorithmTypeInplace}, - {ast.AlterTableSpec{Tp: ast.AlterTableAddColumns}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableDropColumn}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableDropIndex}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableDropForeignKey}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableRenameTable}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableRenameIndex}, instantAlgorithm, ast.AlgorithmTypeInstant}, + { + ast.AlterTableSpec{Tp: ast.AlterTableAddConstraint}, + []ast.AlgorithmType{ast.AlgorithmTypeDefault, ast.AlgorithmTypeCopy, ast.AlgorithmTypeInplace}, + []ast.AlgorithmType{ast.AlgorithmTypeInplace, ast.AlgorithmTypeInplace, ast.AlgorithmTypeInplace}, + }, + + {ast.AlterTableSpec{Tp: ast.AlterTableAddColumns}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropColumn}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropIndex}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropForeignKey}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableRenameTable}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableRenameIndex}, supportedInstantAlgorithms, expectedInstantAlgorithms}, // Alter table options. - {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionShardRowID}}}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionAutoIncrement}}}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionComment}}}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCharset}}}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCollate}}}, instantAlgorithm, ast.AlgorithmTypeInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionShardRowID}}}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionAutoIncrement}}}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionComment}}}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCharset}}}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCollate}}}, supportedInstantAlgorithms, expectedInstantAlgorithms}, // TODO: after we support migrate the data of partitions, change below cases. +<<<<<<< HEAD {ast.AlterTableSpec{Tp: ast.AlterTableCoalescePartitions}, instantAlgorithm, ast.AlgorithmTypeInstant}, {ast.AlterTableSpec{Tp: ast.AlterTableAddPartitions}, instantAlgorithm, ast.AlgorithmTypeInstant}, {ast.AlterTableSpec{Tp: ast.AlterTableDropPartition}, instantAlgorithm, ast.AlgorithmTypeInstant}, {ast.AlterTableSpec{Tp: ast.AlterTableTruncatePartition}, instantAlgorithm, ast.AlgorithmTypeInstant}, +======= + {ast.AlterTableSpec{Tp: ast.AlterTableCoalescePartitions}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableAddPartitions}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropPartition}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableTruncatePartition}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableExchangePartition}, supportedInstantAlgorithms, expectedInstantAlgorithms}, +>>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) // TODO: after we support lock a table, change the below case. - {ast.AlterTableSpec{Tp: ast.AlterTableLock}, instantAlgorithm, ast.AlgorithmTypeInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableLock}, supportedInstantAlgorithms, expectedInstantAlgorithms}, // TODO: after we support changing the column type, below cases need to change. - {ast.AlterTableSpec{Tp: ast.AlterTableModifyColumn}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableChangeColumn}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableAlterColumn}, instantAlgorithm, ast.AlgorithmTypeInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableModifyColumn}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableChangeColumn}, supportedInstantAlgorithms, expectedInstantAlgorithms}, + {ast.AlterTableSpec{Tp: ast.AlterTableAlterColumn}, supportedInstantAlgorithms, expectedInstantAlgorithms}, } for _, tc := range testCases { @@ -75,10 +88,6 @@ func (s *testDDLAlgorithmSuite) TestFindAlterAlgorithm(c *C) { } func runAlterAlgorithmTestCases(c *C, tc *testCase) { - algorithm, err := ddl.ResolveAlterAlgorithm(&tc.alterSpec, ast.AlgorithmTypeDefault) - c.Assert(err, IsNil) - c.Assert(algorithm, Equals, tc.defAlgorithm) - unsupported := make([]ast.AlgorithmType, 0, len(allAlgorithm)) Loop: for _, alm := range allAlgorithm { @@ -91,16 +100,22 @@ Loop: unsupported = append(unsupported, alm) } + var algorithm ast.AlgorithmType + var err error + // Test supported. - for _, alm := range tc.supportedAlgorithm { + for i, alm := range tc.supportedAlgorithm { algorithm, err = ddl.ResolveAlterAlgorithm(&tc.alterSpec, alm) - c.Assert(err, IsNil) - c.Assert(algorithm, Equals, alm) + if err != nil { + c.Assert(ddl.ErrAlterOperationNotSupported.Equal(err), IsTrue) + } + c.Assert(algorithm, Equals, tc.expectedAlgorithm[i]) } // Test unsupported. for _, alm := range unsupported { - _, err = ddl.ResolveAlterAlgorithm(&tc.alterSpec, alm) + algorithm, err = ddl.ResolveAlterAlgorithm(&tc.alterSpec, alm) + c.Assert(algorithm, Equals, ast.AlgorithmTypeDefault) c.Assert(err, NotNil, Commentf("Tp:%v, alm:%s", tc.alterSpec.Tp, alm)) c.Assert(ddl.ErrAlterOperationNotSupported.Equal(err), IsTrue) } diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 8450155a81778..0ce48000220c8 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2053,11 +2053,11 @@ func resolveAlterTableSpec(ctx sessionctx.Context, specs []*ast.AlterTableSpec) for _, spec := range validSpecs { resolvedAlgorithm, err := ResolveAlterAlgorithm(spec, algorithm) if err != nil { - if algorithm != ast.AlgorithmTypeCopy { + // If TiDB failed to choose a better algorithm, report the error + if resolvedAlgorithm == ast.AlgorithmTypeDefault { return nil, errors.Trace(err) } - // For the compatibility, we return warning instead of error when the algorithm is COPY, - // because the COPY ALGORITHM is not supported in TiDB. + // For the compatibility, we return warning instead of error when a better algorithm is chosed by TiDB ctx.GetSessionVars().StmtCtx.AppendError(err) } diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index 36005cf19c782..eb4cd4aa28012 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -287,7 +287,7 @@ func (s *seqTestSuite) TestShow(c *C) { d int UNIQUE KEY, index (b) invisible, index (d) invisible)`) - excepted := + expected := "t CREATE TABLE `t` (\n" + " `a` int(11) DEFAULT NULL,\n" + " `b` int(11) DEFAULT NULL,\n" + @@ -298,7 +298,12 @@ func (s *seqTestSuite) TestShow(c *C) { " UNIQUE KEY `c` (`c`),\n" + " UNIQUE KEY `d_2` (`d`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" +<<<<<<< HEAD tk.MustQuery("show create table t").Check(testkit.Rows(excepted)) +======= + tk.MustQuery("show create table t").Check(testkit.Rows(expected)) + tk.MustExec("drop table t") +>>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) testSQL = "SHOW VARIABLES LIKE 'character_set_results';" result = tk.MustQuery(testSQL) From cfc50552aabc4cf0207307e9ee4611998e290d57 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Fri, 21 Aug 2020 16:57:10 +0800 Subject: [PATCH 2/2] fix conflict --- ddl/db_integration_test.go | 117 +++----------------------- ddl/ddl_algorithm_test.go | 7 -- executor/seqtest/seq_executor_test.go | 4 - 3 files changed, 12 insertions(+), 116 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index efdc7759726b2..b972746a99530 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1212,7 +1212,6 @@ func (s *testIntegrationSuite6) TestCreateTableTooLarge(c *C) { } func (s *testIntegrationSuite3) TestChangeColumnPosition(c *C) { -<<<<<<< HEAD s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") @@ -1253,50 +1252,7 @@ func (s *testIntegrationSuite3) TestChangeColumnPosition(c *C) { s.tk.MustExec("alter table position4 add index t(b)") s.tk.MustExec("alter table position4 change column b c int first") createSQL := s.tk.MustQuery("show create table position4").Rows()[0][1] - exceptedSQL := []string{ -======= - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - - tk.MustExec("create table position (a int default 1, b int default 2)") - tk.MustExec("insert into position value ()") - tk.MustExec("insert into position values (3,4)") - tk.MustQuery("select * from position").Check(testkit.Rows("1 2", "3 4")) - tk.MustExec("alter table position modify column b int first") - tk.MustQuery("select * from position").Check(testkit.Rows("2 1", "4 3")) - tk.MustExec("insert into position value ()") - tk.MustQuery("select * from position").Check(testkit.Rows("2 1", "4 3", " 1")) - - tk.MustExec("create table position1 (a int, b int, c double, d varchar(5))") - tk.MustExec(`insert into position1 value (1, 2, 3.14, 'TiDB')`) - tk.MustExec("alter table position1 modify column d varchar(5) after a") - tk.MustQuery("select * from position1").Check(testkit.Rows("1 TiDB 2 3.14")) - tk.MustExec("alter table position1 modify column a int after c") - tk.MustQuery("select * from position1").Check(testkit.Rows("TiDB 2 3.14 1")) - tk.MustExec("alter table position1 modify column c double first") - tk.MustQuery("select * from position1").Check(testkit.Rows("3.14 TiDB 2 1")) - tk.MustGetErrCode("alter table position1 modify column b int after b", errno.ErrBadField) - - tk.MustExec("create table position2 (a int, b int)") - tk.MustExec("alter table position2 add index t(a, b)") - tk.MustExec("alter table position2 modify column b int first") - tk.MustExec("insert into position2 value (3, 5)") - tk.MustQuery("select a from position2 where a = 3").Check(testkit.Rows()) - tk.MustExec("alter table position2 change column b c int first") - tk.MustQuery("select * from position2 where c = 3").Check(testkit.Rows("3 5")) - tk.MustGetErrCode("alter table position2 change column c b int after c", errno.ErrBadField) - - tk.MustExec("create table position3 (a int default 2)") - tk.MustExec("alter table position3 modify column a int default 5 first") - tk.MustExec("insert into position3 value ()") - tk.MustQuery("select * from position3").Check(testkit.Rows("5")) - - tk.MustExec("create table position4 (a int, b int)") - tk.MustExec("alter table position4 add index t(b)") - tk.MustExec("alter table position4 change column b c int first") - createSQL := tk.MustQuery("show create table position4").Rows()[0][1] expectedSQL := []string{ ->>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) "CREATE TABLE `position4` (", " `c` int(11) DEFAULT NULL,", " `a` int(11) DEFAULT NULL,", @@ -1521,8 +1477,7 @@ func (s *testIntegrationSuite3) TestAlterAlgorithm(c *C) { PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN (21) )`) -<<<<<<< HEAD - s.assertAlterErrorExec(c, "alter table t modify column a bigint, ALGORITHM=INPLACE;") + s.assertAlterWarnExec(c, "alter table t modify column a bigint, ALGORITHM=INPLACE;") s.tk.MustExec("alter table t modify column a bigint, ALGORITHM=INPLACE, ALGORITHM=INSTANT;") s.tk.MustExec("alter table t modify column a bigint, ALGORITHM=DEFAULT;") @@ -1530,93 +1485,45 @@ func (s *testIntegrationSuite3) TestAlterAlgorithm(c *C) { s.assertAlterErrorExec(c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") s.assertAlterWarnExec(c, "alter table t add index idx_b1(b), ALGORITHM=COPY") s.tk.MustExec("alter table t add index idx_b2(b), ALGORITHM=INPLACE") - s.assertAlterErrorExec(c, "alter table t drop index idx_b, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t add index idx_b3(b), ALGORITHM=DEFAULT") + s.assertAlterWarnExec(c, "alter table t drop index idx_b3, ALGORITHM=INPLACE") s.assertAlterWarnExec(c, "alter table t drop index idx_b1, ALGORITHM=COPY") s.tk.MustExec("alter table t drop index idx_b2, ALGORITHM=INSTANT") // Test rename s.assertAlterWarnExec(c, "alter table t rename to t1, ALGORITHM=COPY") - s.assertAlterErrorExec(c, "alter table t1 rename to t, ALGORITHM=INPLACE") - s.tk.MustExec("alter table t1 rename to t, ALGORITHM=INSTANT") + s.assertAlterWarnExec(c, "alter table t1 rename to t2, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t2 rename to t, ALGORITHM=INSTANT") s.tk.MustExec("alter table t rename to t1, ALGORITHM=DEFAULT") s.tk.MustExec("alter table t1 rename to t") // Test rename index s.assertAlterWarnExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") - s.assertAlterErrorExec(c, "alter table t rename index idx_c1 to idx_c, ALGORITHM=INPLACE") - s.tk.MustExec("alter table t rename index idx_c1 to idx_c, ALGORITHM=INSTANT") + s.assertAlterWarnExec(c, "alter table t rename index idx_c1 to idx_c2, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t rename index idx_c2 to idx_c, ALGORITHM=INSTANT") s.tk.MustExec("alter table t rename index idx_c to idx_c1, ALGORITHM=DEFAULT") // partition. s.assertAlterWarnExec(c, "alter table t ALGORITHM=COPY, truncate partition p1") - s.assertAlterErrorExec(c, "alter table t ALGORITHM=INPLACE, truncate partition p2") + s.assertAlterWarnExec(c, "alter table t ALGORITHM=INPLACE, truncate partition p2") s.tk.MustExec("alter table t ALGORITHM=INSTANT, truncate partition p3") s.assertAlterWarnExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") - s.assertAlterErrorExec(c, "alter table t add partition (partition p5 values less than (3002)), ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t add partition (partition p5 values less than (3002)), ALGORITHM=INPLACE") s.tk.MustExec("alter table t add partition (partition p6 values less than (4002)), ALGORITHM=INSTANT") s.assertAlterWarnExec(c, "alter table t ALGORITHM=COPY, drop partition p4") - s.assertAlterErrorExec(c, "alter table t ALGORITHM=INPLACE, drop partition p5") + s.assertAlterWarnExec(c, "alter table t ALGORITHM=INPLACE, drop partition p5") s.tk.MustExec("alter table t ALGORITHM=INSTANT, drop partition p6") // Table options s.assertAlterWarnExec(c, "alter table t comment = 'test', ALGORITHM=COPY") - s.assertAlterErrorExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") s.tk.MustExec("alter table t comment = 'test', ALGORITHM=INSTANT") s.assertAlterWarnExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") - s.assertAlterErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") -======= - s.assertAlterWarnExec(tk, c, "alter table t modify column a bigint, ALGORITHM=INPLACE;") - tk.MustExec("alter table t modify column a bigint, ALGORITHM=INPLACE, ALGORITHM=INSTANT;") - tk.MustExec("alter table t modify column a bigint, ALGORITHM=DEFAULT;") - - // Test add/drop index - s.assertAlterErrorExec(tk, c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") - s.assertAlterWarnExec(tk, c, "alter table t add index idx_b1(b), ALGORITHM=COPY") - tk.MustExec("alter table t add index idx_b2(b), ALGORITHM=INPLACE") - tk.MustExec("alter table t add index idx_b3(b), ALGORITHM=DEFAULT") - s.assertAlterWarnExec(tk, c, "alter table t drop index idx_b3, ALGORITHM=INPLACE") - s.assertAlterWarnExec(tk, c, "alter table t drop index idx_b1, ALGORITHM=COPY") - tk.MustExec("alter table t drop index idx_b2, ALGORITHM=INSTANT") - - // Test rename - s.assertAlterWarnExec(tk, c, "alter table t rename to t1, ALGORITHM=COPY") - s.assertAlterWarnExec(tk, c, "alter table t1 rename to t2, ALGORITHM=INPLACE") - tk.MustExec("alter table t2 rename to t, ALGORITHM=INSTANT") - tk.MustExec("alter table t rename to t1, ALGORITHM=DEFAULT") - tk.MustExec("alter table t1 rename to t") - - // Test rename index - s.assertAlterWarnExec(tk, c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") - s.assertAlterWarnExec(tk, c, "alter table t rename index idx_c1 to idx_c2, ALGORITHM=INPLACE") - tk.MustExec("alter table t rename index idx_c2 to idx_c, ALGORITHM=INSTANT") - tk.MustExec("alter table t rename index idx_c to idx_c1, ALGORITHM=DEFAULT") - - // partition. - s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=COPY, truncate partition p1") - s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=INPLACE, truncate partition p2") - tk.MustExec("alter table t ALGORITHM=INSTANT, truncate partition p3") - - s.assertAlterWarnExec(tk, c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") - s.assertAlterWarnExec(tk, c, "alter table t add partition (partition p5 values less than (3002)), ALGORITHM=INPLACE") - tk.MustExec("alter table t add partition (partition p6 values less than (4002)), ALGORITHM=INSTANT") - - s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=COPY, drop partition p4") - s.assertAlterWarnExec(tk, c, "alter table t ALGORITHM=INPLACE, drop partition p5") - tk.MustExec("alter table t ALGORITHM=INSTANT, drop partition p6") - - // Table options - s.assertAlterWarnExec(tk, c, "alter table t comment = 'test', ALGORITHM=COPY") - s.assertAlterWarnExec(tk, c, "alter table t comment = 'test', ALGORITHM=INPLACE") - tk.MustExec("alter table t comment = 'test', ALGORITHM=INSTANT") - - s.assertAlterWarnExec(tk, c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") - s.assertAlterWarnExec(tk, c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") - tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") ->>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) } func (s *testIntegrationSuite3) TestAlterTableAddUniqueOnPartionRangeColumn(c *C) { diff --git a/ddl/ddl_algorithm_test.go b/ddl/ddl_algorithm_test.go index a99c9bb22b609..0c312bd3bdce9 100644 --- a/ddl/ddl_algorithm_test.go +++ b/ddl/ddl_algorithm_test.go @@ -61,18 +61,11 @@ func (s *testDDLAlgorithmSuite) TestFindAlterAlgorithm(c *C) { {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCollate}}}, supportedInstantAlgorithms, expectedInstantAlgorithms}, // TODO: after we support migrate the data of partitions, change below cases. -<<<<<<< HEAD - {ast.AlterTableSpec{Tp: ast.AlterTableCoalescePartitions}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableAddPartitions}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableDropPartition}, instantAlgorithm, ast.AlgorithmTypeInstant}, - {ast.AlterTableSpec{Tp: ast.AlterTableTruncatePartition}, instantAlgorithm, ast.AlgorithmTypeInstant}, -======= {ast.AlterTableSpec{Tp: ast.AlterTableCoalescePartitions}, supportedInstantAlgorithms, expectedInstantAlgorithms}, {ast.AlterTableSpec{Tp: ast.AlterTableAddPartitions}, supportedInstantAlgorithms, expectedInstantAlgorithms}, {ast.AlterTableSpec{Tp: ast.AlterTableDropPartition}, supportedInstantAlgorithms, expectedInstantAlgorithms}, {ast.AlterTableSpec{Tp: ast.AlterTableTruncatePartition}, supportedInstantAlgorithms, expectedInstantAlgorithms}, {ast.AlterTableSpec{Tp: ast.AlterTableExchangePartition}, supportedInstantAlgorithms, expectedInstantAlgorithms}, ->>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) // TODO: after we support lock a table, change the below case. {ast.AlterTableSpec{Tp: ast.AlterTableLock}, supportedInstantAlgorithms, expectedInstantAlgorithms}, diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index eb4cd4aa28012..f71c155759d72 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -298,12 +298,8 @@ func (s *seqTestSuite) TestShow(c *C) { " UNIQUE KEY `c` (`c`),\n" + " UNIQUE KEY `d_2` (`d`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" -<<<<<<< HEAD - tk.MustQuery("show create table t").Check(testkit.Rows(excepted)) -======= tk.MustQuery("show create table t").Check(testkit.Rows(expected)) tk.MustExec("drop table t") ->>>>>>> f851898... ddl: improve compatibility for ALTER TABLE algorithms (#19270) testSQL = "SHOW VARIABLES LIKE 'character_set_results';" result = tk.MustQuery(testSQL)