From 470cbdd569ac13b1b2a52b1bdd5af6a23b18a5b8 Mon Sep 17 00:00:00 2001 From: winkyao Date: Tue, 25 Dec 2018 16:20:19 +0800 Subject: [PATCH 01/10] ddl: support alter algorithm INPLACE/INSTANT --- ddl/db_integration_test.go | 70 ++++++++++++++++++++++++ ddl/ddl.go | 4 ++ ddl/ddl_algorithm.go | 76 ++++++++++++++++++++++++++ ddl/ddl_algorithm_test.go | 107 +++++++++++++++++++++++++++++++++++++ ddl/ddl_api.go | 32 +++++++++-- go.mod | 2 + go.sum | 2 + 7 files changed, 290 insertions(+), 3 deletions(-) create mode 100644 ddl/ddl_algorithm.go create mode 100644 ddl/ddl_algorithm_test.go diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index e2bbff37e0b0a..10df1d89f52cc 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1140,3 +1140,73 @@ func (s *testIntegrationSuite) TestAlterColumn(c *C) { _, err = s.tk.Exec("alter table mc modify column a bigint auto_increment") // Adds auto_increment should throw error c.Assert(err, NotNil) } + +func (s *testIntegrationSuite) assertErrorExec(c *C, sql string) { + _, err := s.tk.Exec(sql) + c.Assert(ddl.ErrAlterOperationNotSupported.Equal(err), IsTrue, Commentf("error:%v", err)) +} + +func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { + s.tk = testkit.NewTestKit(c, s.store) + s.tk.MustExec("use test") + s.tk.MustExec("drop table if exists t") + s.tk.MustExec("drop table if exists t1") + defer s.tk.MustExec("drop table if exists t") + + s.tk.MustExec(`create table t( + a int, + b varchar(100), + c int, + INDEX idx_c(c)) PARTITION BY RANGE ( a ) ( + PARTITION p0 VALUES LESS THAN (6), + PARTITION p1 VALUES LESS THAN (11), + PARTITION p2 VALUES LESS THAN (16), + PARTITION p3 VALUES LESS THAN (21) + )`) + _, err := s.tk.Exec("alter table t modify column a bigint, ALGORITHM=INPLACE;") + c.Assert(ddl.ErrAlterOperationNotSupported.Equal(err), IsTrue) + 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;") + + // Test add/drop index + s.assertErrorExec(c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") + s.assertErrorExec(c, "alter table t add index idx_b(b), ALGORITHM=COPY") + s.tk.MustExec("alter table t add index idx_b(b), ALGORITHM=INPLACE") + s.assertErrorExec(c, "alter table t drop index idx_b, ALGORITHM=INPLACE") + s.assertErrorExec(c, "alter table t drop index idx_b, ALGORITHM=COPY") + s.tk.MustExec("alter table t drop index idx_b, ALGORITHM=INSTANT") + + // Test rename + s.assertErrorExec(c, "alter table t rename to t1, ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t rename to t1, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t rename to t1, ALGORITHM=INSTANT") + s.tk.MustExec("alter table t1 rename to t, ALGORITHM=DEFAULT") + + // Test rename index + s.assertErrorExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t rename index idx_c to idx_c1, ALGORITHM=INSTANT") + s.tk.MustExec("alter table t rename index idx_c1 to idx_c, ALGORITHM=DEFAULT") + + // partition. + s.assertErrorExec(c, "alter table t truncate partition p1, ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t truncate partition p1, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t truncate partition p1, ALGORITHM=INSTANT") + + s.assertErrorExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=INPLACE") + s.tk.MustExec("alter table t add partition (partition p4 values less than (2002)), ALGORITHM=INSTANT") + + s.assertErrorExec(c, "alter table t drop partition p4, ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t drop partition p4, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t drop partition p4, ALGORITHM=INSTANT") + + // Table options + s.assertErrorExec(c, "alter table t comment = 'test', ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") + s.tk.MustExec("alter table t comment = 'test', ALGORITHM=INSTANT") + + s.assertErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") + s.assertErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") +} diff --git a/ddl/ddl.go b/ddl/ddl.go index 74fc80138933c..18fdc3b78bd79 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -203,6 +203,8 @@ var ( ErrCoalesceOnlyOnHashPartition = terror.ClassDDL.New(codeCoalesceOnlyOnHashPartition, mysql.MySQLErrName[mysql.ErrCoalesceOnlyOnHashPartition]) // ErrViewWrongList returns create view must include all columns in the select clause ErrViewWrongList = terror.ClassDDL.New(codeViewWrongList, mysql.MySQLErrName[mysql.ErrViewWrongList]) + // ErrAlterOperationNotSupported returns when alter operations is not supported. + ErrAlterOperationNotSupported = terror.ClassDDL.New(codeNotSupportedAlterOperation, mysql.MySQLErrName[mysql.ErrAlterOperationNotSupportedReason]) ) // DDL is responsible for updating schema in data store and maintaining in-memory InfoSchema cache. @@ -652,6 +654,7 @@ const ( codeWarnDataTruncated = terror.ErrCode(mysql.WarnDataTruncated) codeCoalesceOnlyOnHashPartition = terror.ErrCode(mysql.ErrCoalesceOnlyOnHashPartition) codeUnknownPartition = terror.ErrCode(mysql.ErrUnknownPartition) + codeNotSupportedAlterOperation = terror.ErrCode(mysql.ErrAlterOperationNotSupportedReason) ) func init() { @@ -703,6 +706,7 @@ func init() { codeWarnDataTruncated: mysql.WarnDataTruncated, codeCoalesceOnlyOnHashPartition: mysql.ErrCoalesceOnlyOnHashPartition, codeUnknownPartition: mysql.ErrUnknownPartition, + codeNotSupportedAlterOperation: mysql.ErrAlterOperationNotSupportedReason, } terror.ErrClassToMySQLCodes[terror.ClassDDL] = ddlMySQLErrCodes } diff --git a/ddl/ddl_algorithm.go b/ddl/ddl_algorithm.go new file mode 100644 index 0000000000000..1bdd620daac3a --- /dev/null +++ b/ddl/ddl_algorithm.go @@ -0,0 +1,76 @@ +// Copyright 2013 The ql Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSES/QL-LICENSE file. + +// Copyright 2015 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package ddl + +import ( + "fmt" + + "github.com/pingcap/parser/ast" +) + +// AlterAlgorithm is used to store supported alter algorithm. +// For now, TiDB only support AlterAlgorithmInplace and AlterAlgorithmInstant. +// The most alter operations are using instant algorithm, and only the add index is using inplace(not really inplace, +// 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 []ast.AlterAlgorithm + // If the alter algorithm is not given, the defAlgorithm will be used. + defAlgorithm ast.AlterAlgorithm +} + +var ( + instantAlgorithm = &AlterAlgorithm{ + supported: []ast.AlterAlgorithm{ast.AlterAlgorithmInstant}, + defAlgorithm: ast.AlterAlgorithmInstant, + } + + inplaceAlgorithm = &AlterAlgorithm{ + supported: []ast.AlterAlgorithm{ast.AlterAlgorithmInplace}, + defAlgorithm: ast.AlterAlgorithmInplace, + } + + defaultAlgorithm = ast.AlterAlgorithmInstant +) + +func getProperAlgorithm(specify ast.AlterAlgorithm, algorithm *AlterAlgorithm) (ast.AlterAlgorithm, error) { + if specify == ast.AlterAlgorithmDefault { + return algorithm.defAlgorithm, nil + } + + for _, a := range algorithm.supported { + if specify == a { + return specify, nil + } + } + + return defaultAlgorithm, ErrAlterOperationNotSupported.GenWithStackByArgs(fmt.Sprintf("ALGORITHM=%s", specify), fmt.Sprintf("Cannot alter table by %s", specify), fmt.Sprintf("ALGORITHM=%s", algorithm.defAlgorithm)) +} + +// ResolveAlterAlgorithm resolves the algorithm of the alterSpec. +// If specify algorithm is not supported by the alter action, errAlterOperationNotSupported will be return. +// If specify is the ast.AlterAlgorithmDefault, then the default algorithm of the alter action will be return. +func ResolveAlterAlgorithm(alterSpec *ast.AlterTableSpec, specify ast.AlterAlgorithm) (ast.AlterAlgorithm, error) { + switch alterSpec.Tp { + // For now, TiDB only support inplace algorithm and instant algorithm. + case ast.AlterTableAddConstraint: + return getProperAlgorithm(specify, inplaceAlgorithm) + default: + return getProperAlgorithm(specify, instantAlgorithm) + } +} diff --git a/ddl/ddl_algorithm_test.go b/ddl/ddl_algorithm_test.go new file mode 100644 index 0000000000000..1622ada9cf3f1 --- /dev/null +++ b/ddl/ddl_algorithm_test.go @@ -0,0 +1,107 @@ +// Copyright 2015 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package ddl_test + +import ( + . "github.com/pingcap/check" + "github.com/pingcap/parser/ast" + "github.com/pingcap/tidb/ddl" +) + +var _ = Suite(&testDDLAlgorithmSuite{}) + +var ( + allAlgorithm = []ast.AlterAlgorithm{ast.AlterAlgorithmCopy, + ast.AlterAlgorithmInplace, ast.AlterAlgorithmInstant} +) + +type testDDLAlgorithmSuite struct{} + +type testCase struct { + alterSpec ast.AlterTableSpec + supportedAlgorithm []ast.AlterAlgorithm + defAlgorithm ast.AlterAlgorithm +} + +func (s *testDDLAlgorithmSuite) TestFindAlterAlgorithm(c *C) { + instantAlgorithm := []ast.AlterAlgorithm{ast.AlterAlgorithmInstant} + inplaceAlgorithm := []ast.AlterAlgorithm{ast.AlterAlgorithmInplace} + + testCases := []testCase{ + {ast.AlterTableSpec{Tp: ast.AlterTableAddConstraint}, inplaceAlgorithm, ast.AlterAlgorithmInplace}, + {ast.AlterTableSpec{Tp: ast.AlterTableAddColumns}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropColumn}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropIndex}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropForeignKey}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableRenameTable}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableRenameIndex}, instantAlgorithm, ast.AlterAlgorithmInstant}, + + // Alter table options. + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionShardRowID}}}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionAutoIncrement}}}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionComment}}}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCharset}}}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableOption, Options: []*ast.TableOption{{Tp: ast.TableOptionCollate}}}, instantAlgorithm, ast.AlterAlgorithmInstant}, + + // TODO: after we support migrate the data of partitions, change below cases. + {ast.AlterTableSpec{Tp: ast.AlterTableCoalescePartitions}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableAddPartitions}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableDropPartition}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableTruncatePartition}, instantAlgorithm, ast.AlterAlgorithmInstant}, + + // TODO: after we support lock a table, change the below case. + {ast.AlterTableSpec{Tp: ast.AlterTableLock}, instantAlgorithm, ast.AlterAlgorithmInstant}, + // TODO: after we support changing the column type, below cases need to change. + {ast.AlterTableSpec{Tp: ast.AlterTableModifyColumn}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableChangeColumn}, instantAlgorithm, ast.AlterAlgorithmInstant}, + {ast.AlterTableSpec{Tp: ast.AlterTableAlterColumn}, instantAlgorithm, ast.AlterAlgorithmInstant}, + } + + for _, tc := range testCases { + runAlterAlgorithmTestCases(c, &tc) + } +} + +func runAlterAlgorithmTestCases(c *C, tc *testCase) { + algorithm, err := ddl.ResolveAlterAlgorithm(&tc.alterSpec, ast.AlterAlgorithmDefault) + c.Assert(err, IsNil) + c.Assert(algorithm, Equals, tc.defAlgorithm) + + unsupported := make([]ast.AlterAlgorithm, 0, len(allAlgorithm)) +Loop: + for _, alm := range allAlgorithm { + for _, almSupport := range tc.supportedAlgorithm { + if alm == almSupport { + continue Loop + } + } + + unsupported = append(unsupported, alm) + } + + // Test supported. + for _, alm := range tc.supportedAlgorithm { + algorithm, err = ddl.ResolveAlterAlgorithm(&tc.alterSpec, alm) + c.Assert(err, IsNil) + c.Assert(algorithm, Equals, alm) + } + + // Test unsupported. + for _, alm := range unsupported { + algorithm, err = ddl.ResolveAlterAlgorithm(&tc.alterSpec, alm) + 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 60e8c320f94ae..7205bf5204422 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1231,10 +1231,16 @@ func getCharsetAndCollateInTableOption(startIdx int, options []*ast.TableOption) return } -func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.AlterTableSpec) (err error) { - // Only handle valid specs. +// resolveAlterTableSpec resolve alter table algorithm and remove ignore table spec in specs. +// returns valied specs, and the occured error. +func resolveAlterTableSpec(specs []*ast.AlterTableSpec) ([]*ast.AlterTableSpec, error) { validSpecs := make([]*ast.AlterTableSpec, 0, len(specs)) + algorithm := ast.AlterAlgorithmDefault for _, spec := range specs { + if spec.Tp == ast.AlterTableAlgorithm { + // find the last AlterTableAlgorithm. + algorithm = spec.Algorithm + } if isIgnorableSpec(spec.Tp) { continue } @@ -1244,7 +1250,27 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A if len(validSpecs) != 1 { // TODO: Hanlde len(validSpecs) == 0. // Now we only allow one schema changing at the same time. - return errRunMultiSchemaChanges + return nil, errRunMultiSchemaChanges + } + + // Verify whether the algorithm is supported. + for _, spec := range validSpecs { + algorithm, err := ResolveAlterAlgorithm(spec, algorithm) + if err != nil { + return nil, errors.Trace(err) + } + + spec.Algorithm = algorithm + } + + // Only handle valid specs. + return validSpecs, nil +} + +func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.AlterTableSpec) (err error) { + validSpecs, err := resolveAlterTableSpec(specs) + if err != nil { + return errors.Trace(err) } for _, spec := range validSpecs { diff --git a/go.mod b/go.mod index f5a6c0a7d7b19..9a7f396365412 100644 --- a/go.mod +++ b/go.mod @@ -86,3 +86,5 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) + +replace github.com/pingcap/parser => github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419 diff --git a/go.sum b/go.sum index f30d7e601d11e..2cfee303ff428 100644 --- a/go.sum +++ b/go.sum @@ -180,6 +180,8 @@ github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf h1:BLcwkDfQ8QPXNXB github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4QUw6lhHsVymzwSDJOZcE0s2X8S20= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= +github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419 h1:h6wrX1A2R0dJJsLsIC9Q55PY7p42dZhChGzpyoPvO3A= +github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= From dd8fa6dd5b354fa1d20d46a494cb7229981b272a Mon Sep 17 00:00:00 2001 From: winkyao Date: Tue, 25 Dec 2018 16:33:22 +0800 Subject: [PATCH 02/10] tidy --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 2cfee303ff428..8de242448cb88 100644 --- a/go.sum +++ b/go.sum @@ -180,7 +180,6 @@ github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf h1:BLcwkDfQ8QPXNXB github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4QUw6lhHsVymzwSDJOZcE0s2X8S20= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= -github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419 h1:h6wrX1A2R0dJJsLsIC9Q55PY7p42dZhChGzpyoPvO3A= github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= From ee0288cdff20b8ab3876945f7ef5a4f12f52f075 Mon Sep 17 00:00:00 2001 From: winkyao Date: Thu, 27 Dec 2018 10:42:40 +0800 Subject: [PATCH 03/10] modify the copyright --- ddl/ddl_algorithm.go | 6 +----- ddl/ddl_algorithm_test.go | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ddl/ddl_algorithm.go b/ddl/ddl_algorithm.go index 1bdd620daac3a..94a53dde9fb7d 100644 --- a/ddl/ddl_algorithm.go +++ b/ddl/ddl_algorithm.go @@ -1,8 +1,4 @@ -// Copyright 2013 The ql Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSES/QL-LICENSE file. - -// Copyright 2015 PingCAP, Inc. +// Copyright 2018 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/ddl/ddl_algorithm_test.go b/ddl/ddl_algorithm_test.go index 1622ada9cf3f1..1d1a49e642daf 100644 --- a/ddl/ddl_algorithm_test.go +++ b/ddl/ddl_algorithm_test.go @@ -1,4 +1,4 @@ -// Copyright 2015 PingCAP, Inc. +// Copyright 2018 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 5de30c5e85301f280b0286fdbf51b440b038cb77 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 4 Jan 2019 16:19:16 +0800 Subject: [PATCH 04/10] return warning instead of error. --- ddl/db_integration_test.go | 56 ++++++++++++++++++++------------------ ddl/ddl_algorithm.go | 6 ++-- ddl/ddl_api.go | 10 +++++-- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 10df1d89f52cc..e809a58da8cba 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1141,9 +1141,12 @@ func (s *testIntegrationSuite) TestAlterColumn(c *C) { c.Assert(err, NotNil) } -func (s *testIntegrationSuite) assertErrorExec(c *C, sql string) { +func (s *testIntegrationSuite) assertWarningExec(c *C, sql string) { _, err := s.tk.Exec(sql) - c.Assert(ddl.ErrAlterOperationNotSupported.Equal(err), IsTrue, Commentf("error:%v", err)) + c.Assert(err, IsNil) + st := s.tk.Se.GetSessionVars().StmtCtx + c.Assert(st.WarningCount(), Equals, uint16(1)) + c.Assert(ddl.ErrAlterOperationNotSupported.Equal(st.GetWarnings()[0].Err), IsTrue, Commentf("error:%v", err)) } func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { @@ -1163,50 +1166,49 @@ func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN (21) )`) - _, err := s.tk.Exec("alter table t modify column a bigint, ALGORITHM=INPLACE;") - c.Assert(ddl.ErrAlterOperationNotSupported.Equal(err), IsTrue) + s.assertWarningExec(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;") // Test add/drop index - s.assertErrorExec(c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") - s.assertErrorExec(c, "alter table t add index idx_b(b), ALGORITHM=COPY") - s.tk.MustExec("alter table t add index idx_b(b), ALGORITHM=INPLACE") - s.assertErrorExec(c, "alter table t drop index idx_b, ALGORITHM=INPLACE") - s.assertErrorExec(c, "alter table t drop index idx_b, ALGORITHM=COPY") - s.tk.MustExec("alter table t drop index idx_b, ALGORITHM=INSTANT") + s.assertWarningExec(c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") + s.assertWarningExec(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.assertWarningExec(c, "alter table t drop index idx_b, ALGORITHM=INPLACE") + s.assertWarningExec(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.assertErrorExec(c, "alter table t rename to t1, ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t rename to t1, ALGORITHM=INPLACE") + s.assertWarningExec(c, "alter table t rename to t1, ALGORITHM=COPY") + s.assertWarningExec(c, "alter table t1 rename to t, ALGORITHM=INPLACE") s.tk.MustExec("alter table t rename to t1, ALGORITHM=INSTANT") s.tk.MustExec("alter table t1 rename to t, ALGORITHM=DEFAULT") // Test rename index - s.assertErrorExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=INPLACE") + s.assertWarningExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") + s.assertWarningExec(c, "alter table t rename index idx_c1 to idx_c, ALGORITHM=INPLACE") s.tk.MustExec("alter table t rename index idx_c to idx_c1, ALGORITHM=INSTANT") s.tk.MustExec("alter table t rename index idx_c1 to idx_c, ALGORITHM=DEFAULT") // partition. - s.assertErrorExec(c, "alter table t truncate partition p1, ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t truncate partition p1, ALGORITHM=INPLACE") - s.tk.MustExec("alter table t truncate partition p1, ALGORITHM=INSTANT") + s.assertWarningExec(c, "alter table t truncate partition p1, ALGORITHM=COPY") + s.assertWarningExec(c, "alter table t truncate partition p2, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t truncate partition p3, ALGORITHM=INSTANT") - s.assertErrorExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=INPLACE") - s.tk.MustExec("alter table t add partition (partition p4 values less than (2002)), ALGORITHM=INSTANT") + s.assertWarningExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") + s.assertWarningExec(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.assertErrorExec(c, "alter table t drop partition p4, ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t drop partition p4, ALGORITHM=INPLACE") - s.tk.MustExec("alter table t drop partition p4, ALGORITHM=INSTANT") + s.assertWarningExec(c, "alter table t drop partition p4, ALGORITHM=COPY") + s.assertWarningExec(c, "alter table t drop partition p5, ALGORITHM=INPLACE") + s.tk.MustExec("alter table t drop partition p6, ALGORITHM=INSTANT") // Table options - s.assertErrorExec(c, "alter table t comment = 'test', ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") + s.assertWarningExec(c, "alter table t comment = 'test', ALGORITHM=COPY") + s.assertWarningExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") s.tk.MustExec("alter table t comment = 'test', ALGORITHM=INSTANT") - s.assertErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") - s.assertErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") + s.assertWarningExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") + s.assertWarningExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") } diff --git a/ddl/ddl_algorithm.go b/ddl/ddl_algorithm.go index 94a53dde9fb7d..cb8fa321c3693 100644 --- a/ddl/ddl_algorithm.go +++ b/ddl/ddl_algorithm.go @@ -55,12 +55,12 @@ func getProperAlgorithm(specify ast.AlterAlgorithm, algorithm *AlterAlgorithm) ( } } - return defaultAlgorithm, ErrAlterOperationNotSupported.GenWithStackByArgs(fmt.Sprintf("ALGORITHM=%s", specify), fmt.Sprintf("Cannot alter table by %s", specify), fmt.Sprintf("ALGORITHM=%s", algorithm.defAlgorithm)) + return algorithm.defAlgorithm, ErrAlterOperationNotSupported.GenWithStackByArgs(fmt.Sprintf("ALGORITHM=%s", specify), fmt.Sprintf("Cannot alter table by %s", specify), fmt.Sprintf("ALGORITHM=%s", algorithm.defAlgorithm)) } // ResolveAlterAlgorithm resolves the algorithm of the alterSpec. -// If specify algorithm is not supported by the alter action, errAlterOperationNotSupported will be return. -// If specify is the ast.AlterAlgorithmDefault, then the default algorithm of the alter action will be return. +// 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. func ResolveAlterAlgorithm(alterSpec *ast.AlterTableSpec, specify ast.AlterAlgorithm) (ast.AlterAlgorithm, error) { switch alterSpec.Tp { // For now, TiDB only support inplace algorithm and instant algorithm. diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 7205bf5204422..a3d9771147adb 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -39,6 +39,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/schemautil" "github.com/pingcap/tidb/util/set" + "github.com/sirupsen/logrus" ) func (d *ddl) CreateSchema(ctx sessionctx.Context, schema model.CIStr, charsetInfo *ast.CharsetOpt) (err error) { @@ -1233,7 +1234,7 @@ func getCharsetAndCollateInTableOption(startIdx int, options []*ast.TableOption) // resolveAlterTableSpec resolve alter table algorithm and remove ignore table spec in specs. // returns valied specs, and the occured error. -func resolveAlterTableSpec(specs []*ast.AlterTableSpec) ([]*ast.AlterTableSpec, error) { +func resolveAlterTableSpec(ctx sessionctx.Context, specs []*ast.AlterTableSpec) ([]*ast.AlterTableSpec, error) { validSpecs := make([]*ast.AlterTableSpec, 0, len(specs)) algorithm := ast.AlterAlgorithmDefault for _, spec := range specs { @@ -1257,7 +1258,10 @@ func resolveAlterTableSpec(specs []*ast.AlterTableSpec) ([]*ast.AlterTableSpec, for _, spec := range validSpecs { algorithm, err := ResolveAlterAlgorithm(spec, algorithm) if err != nil { - return nil, errors.Trace(err) + logrus.Infof("err:%v", err) + // For the compatibility, we return warning instead of error. + ctx.GetSessionVars().StmtCtx.AppendError(err) + err = nil } spec.Algorithm = algorithm @@ -1268,7 +1272,7 @@ func resolveAlterTableSpec(specs []*ast.AlterTableSpec) ([]*ast.AlterTableSpec, } func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.AlterTableSpec) (err error) { - validSpecs, err := resolveAlterTableSpec(specs) + validSpecs, err := resolveAlterTableSpec(ctx, specs) if err != nil { return errors.Trace(err) } From c2c4d55253d0fe6ca6a7dea2b659b1de7795f8ec Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 4 Jan 2019 16:23:44 +0800 Subject: [PATCH 05/10] fix ci --- ddl/ddl_api.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index d8882dd291963..28bab0123e1f7 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -40,11 +40,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/schemautil" "github.com/pingcap/tidb/util/set" -<<<<<<< HEAD - "github.com/sirupsen/logrus" -======= log "github.com/sirupsen/logrus" ->>>>>>> upstream/master ) func (d *ddl) CreateSchema(ctx sessionctx.Context, schema model.CIStr, charsetInfo *ast.CharsetOpt) (err error) { @@ -1283,7 +1279,6 @@ func resolveAlterTableSpec(ctx sessionctx.Context, specs []*ast.AlterTableSpec) for _, spec := range validSpecs { algorithm, err := ResolveAlterAlgorithm(spec, algorithm) if err != nil { - logrus.Infof("err:%v", err) // For the compatibility, we return warning instead of error. ctx.GetSessionVars().StmtCtx.AppendError(err) err = nil From d3e57b8ca13384f555919ab7c0118fd9e3559750 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 4 Jan 2019 16:28:24 +0800 Subject: [PATCH 06/10] remove replace --- go.mod | 2 -- go.sum | 1 - 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index f843404e95fb2..8c87769f48057 100644 --- a/go.mod +++ b/go.mod @@ -86,5 +86,3 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) - -replace github.com/pingcap/parser => github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419 diff --git a/go.sum b/go.sum index 1ba9d6934664a..49785cec81608 100644 --- a/go.sum +++ b/go.sum @@ -166,7 +166,6 @@ github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf h1:BLcwkDfQ8QPXNXB github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4QUw6lhHsVymzwSDJOZcE0s2X8S20= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= -github.com/winkyao/parser v0.0.0-20181221090435-0eaad9528419/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= From cf056bbc2e336cf4975437d6a09f9887d1e62f30 Mon Sep 17 00:00:00 2001 From: winkyao Date: Fri, 4 Jan 2019 16:34:22 +0800 Subject: [PATCH 07/10] update parser --- go.mod | 2 ++ go.sum | 1 + 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index 8c87769f48057..d745106c185ea 100644 --- a/go.mod +++ b/go.mod @@ -86,3 +86,5 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) + +replace github.com/pingcap/parser => github.com/winkyao/parser v0.0.0-20190104083231-284ac5fb2704 diff --git a/go.sum b/go.sum index 49785cec81608..70b8e84f0bdc4 100644 --- a/go.sum +++ b/go.sum @@ -166,6 +166,7 @@ github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf h1:BLcwkDfQ8QPXNXB github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4QUw6lhHsVymzwSDJOZcE0s2X8S20= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= +github.com/winkyao/parser v0.0.0-20190104083231-284ac5fb2704/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= From f0abc89a60b33db1a2daa796bf69a4bc2ceadda2 Mon Sep 17 00:00:00 2001 From: winkyao Date: Tue, 19 Feb 2019 15:56:36 +0800 Subject: [PATCH 08/10] update parser --- go.mod | 2 +- go.sum | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index e1d4f95768a43..07caca29c087b 100644 --- a/go.mod +++ b/go.mod @@ -88,4 +88,4 @@ require ( sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) -replace github.com/pingcap/parser => github.com/winkyao/parser v0.0.0-20190104083231-284ac5fb2704 +replace github.com/pingcap/parser => github.com/winkyao/parser v0.0.0-20190219030644-4a96e9b20471 diff --git a/go.sum b/go.sum index b7d2f8652afa5..6420f296f49e3 100644 --- a/go.sum +++ b/go.sum @@ -171,7 +171,7 @@ github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf h1:BLcwkDfQ8QPXNXB github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4QUw6lhHsVymzwSDJOZcE0s2X8S20= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= -github.com/winkyao/parser v0.0.0-20190104083231-284ac5fb2704/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= +github.com/winkyao/parser v0.0.0-20190219030644-4a96e9b20471/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= From d4b9de2b181af367a53bb2e5dd017d15a78b8b6d Mon Sep 17 00:00:00 2001 From: winkyao Date: Tue, 19 Feb 2019 16:05:20 +0800 Subject: [PATCH 09/10] address comments --- ddl/db_integration_test.go | 46 +++++++++++++++++++++----------------- ddl/ddl_api.go | 4 ++-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 1b089a161b549..786401ff773b0 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1211,12 +1211,16 @@ func (s *testIntegrationSuite) TestAlterColumn(c *C) { c.Assert(err, NotNil) } -func (s *testIntegrationSuite) assertWarningExec(c *C, sql string) { +func (s *testIntegrationSuite) assertWarningExec(c *C, sql string, expectedWarn *terror.Error) { _, err := s.tk.Exec(sql) c.Assert(err, IsNil) st := s.tk.Se.GetSessionVars().StmtCtx c.Assert(st.WarningCount(), Equals, uint16(1)) - c.Assert(ddl.ErrAlterOperationNotSupported.Equal(st.GetWarnings()[0].Err), IsTrue, Commentf("error:%v", err)) + c.Assert(expectedWarn.Equal(st.GetWarnings()[0].Err), IsTrue, Commentf("error:%v", err)) +} + +func (s *testIntegrationSuite) assertAlterWarnExec(c *C, sql string) { + s.assertWarningExec(c, sql, ddl.ErrAlterOperationNotSupported) } func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { @@ -1236,49 +1240,49 @@ func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN (21) )`) - s.assertWarningExec(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;") // Test add/drop index - s.assertWarningExec(c, "alter table t add index idx_b(b), ALGORITHM=INSTANT") - s.assertWarningExec(c, "alter table t add index idx_b1(b), ALGORITHM=COPY") + s.assertAlterWarnExec(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.assertWarningExec(c, "alter table t drop index idx_b, ALGORITHM=INPLACE") - s.assertWarningExec(c, "alter table t drop index idx_b1, ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t drop index idx_b, 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.assertWarningExec(c, "alter table t rename to t1, ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t1 rename to t, ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t rename to t1, ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t1 rename to t, ALGORITHM=INPLACE") s.tk.MustExec("alter table t rename to t1, ALGORITHM=INSTANT") s.tk.MustExec("alter table t1 rename to t, ALGORITHM=DEFAULT") // Test rename index - s.assertWarningExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t rename index idx_c1 to idx_c, ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t rename index idx_c to idx_c1, ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t rename index idx_c1 to idx_c, ALGORITHM=INPLACE") s.tk.MustExec("alter table t rename index idx_c to idx_c1, ALGORITHM=INSTANT") s.tk.MustExec("alter table t rename index idx_c1 to idx_c, ALGORITHM=DEFAULT") // partition. - s.assertWarningExec(c, "alter table t truncate partition p1, ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t truncate partition p2, ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t truncate partition p1, ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t truncate partition p2, ALGORITHM=INPLACE") s.tk.MustExec("alter table t truncate partition p3, ALGORITHM=INSTANT") - s.assertWarningExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t add partition (partition p5 values less than (3002)), ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t add partition (partition p4 values less than (2002)), ALGORITHM=COPY") + 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.assertWarningExec(c, "alter table t drop partition p4, ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t drop partition p5, ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t drop partition p4, ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t drop partition p5, ALGORITHM=INPLACE") s.tk.MustExec("alter table t drop partition p6, ALGORITHM=INSTANT") // Table options - s.assertWarningExec(c, "alter table t comment = 'test', ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t comment = 'test', ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t comment = 'test', ALGORITHM=INPLACE") s.tk.MustExec("alter table t comment = 'test', ALGORITHM=INSTANT") - s.assertWarningExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") - s.assertWarningExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") + s.assertAlterWarnExec(c, "alter table t default charset = utf8mb4, ALGORITHM=COPY") + s.assertAlterWarnExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") } diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index eb64bbea089f5..7e31ba95b8966 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1424,14 +1424,14 @@ func getCharsetAndCollateInTableOption(startIdx int, options []*ast.TableOption) return } -// resolveAlterTableSpec resolve alter table algorithm and remove ignore table spec in specs. +// resolveAlterTableSpec resolves alter table algorithm and removes ignore table spec in specs. // returns valied specs, and the occured error. func resolveAlterTableSpec(ctx sessionctx.Context, specs []*ast.AlterTableSpec) ([]*ast.AlterTableSpec, error) { validSpecs := make([]*ast.AlterTableSpec, 0, len(specs)) algorithm := ast.AlterAlgorithmDefault for _, spec := range specs { if spec.Tp == ast.AlterTableAlgorithm { - // find the last AlterTableAlgorithm. + // Find the last AlterTableAlgorithm. algorithm = spec.Algorithm } if isIgnorableSpec(spec.Tp) { From 52125abc809ee3464c0a439d26ec99c2c2f7cad6 Mon Sep 17 00:00:00 2001 From: winkyao Date: Tue, 19 Feb 2019 16:42:32 +0800 Subject: [PATCH 10/10] update parser --- go.mod | 4 +--- go.sum | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 40960eecc613b..15493fdbbf2eb 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20190131052532-7e329e0c9e32 github.com/pingcap/log v0.0.0-20190214045112-b37da76f67a7 - github.com/pingcap/parser v0.0.0-20190218033509-9545f168ae97 + github.com/pingcap/parser v0.0.0-20190219084020-362712b5ab93 github.com/pingcap/pd v2.1.0-rc.4+incompatible github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible github.com/pingcap/tipb v0.0.0-20181012112600-11e33c750323 @@ -87,5 +87,3 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) - -replace github.com/pingcap/parser => github.com/winkyao/parser v0.0.0-20190219030644-4a96e9b20471 diff --git a/go.sum b/go.sum index 09a36f4525a81..decfa63e32f1c 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/pingcap/kvproto v0.0.0-20190131052532-7e329e0c9e32 h1:9uwqk2DvsAKImRK github.com/pingcap/kvproto v0.0.0-20190131052532-7e329e0c9e32/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY= github.com/pingcap/log v0.0.0-20190214045112-b37da76f67a7 h1:kOHAMalwF69bJrtWrOdVaCSvZjLucrJhP4NQKIu6uM4= github.com/pingcap/log v0.0.0-20190214045112-b37da76f67a7/go.mod h1:xsfkWVaFVV5B8e1K9seWfyJWFrIhbtUTAD8NV1Pq3+w= -github.com/pingcap/parser v0.0.0-20190218033509-9545f168ae97 h1:GIhPQAwFwnf6cSdVYXdSNkx171Nl9ZmIVYrOtN3I2lw= -github.com/pingcap/parser v0.0.0-20190218033509-9545f168ae97/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20190219084020-362712b5ab93 h1:jRnleVTpcisLEHNRYHBu4ilwEPyUkslJJfhYNEQlz2g= +github.com/pingcap/parser v0.0.0-20190219084020-362712b5ab93/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE= github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E= github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible h1:e9Gi/LP9181HT3gBfSOeSBA+5JfemuE4aEAhqNgoE4k= @@ -171,7 +171,6 @@ github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf h1:BLcwkDfQ8QPXNXB github.com/ugorji/go/codec v0.0.0-20181127175209-856da096dbdf/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4QUw6lhHsVymzwSDJOZcE0s2X8S20= github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= -github.com/winkyao/parser v0.0.0-20190219030644-4a96e9b20471/go.mod h1:R7TohkGdsluhClCn0ZTwhHDjjjqoiBr6DFFAPTaFvUI= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=