From 50fe9e55bace8a3567d6bb2913554ab67436a04e Mon Sep 17 00:00:00 2001 From: lysu Date: Tue, 15 Jun 2021 13:16:36 +0800 Subject: [PATCH] cherry pick #25405 to release-4.0 Signed-off-by: ti-srebot --- ddl/ddl_api.go | 24 +++++++++++++++++ ddl/error.go | 54 +++++++++++++++++++++++++++++++++++++++ executor/ddl.go | 7 +++++ executor/errors.go | 14 ++++++++++ executor/insert_common.go | 9 +++++++ 5 files changed, 108 insertions(+) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 8edac33dd847d..3a5c1831a0d03 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -36,6 +36,10 @@ import ( "github.com/pingcap/parser/mysql" field_types "github.com/pingcap/parser/types" "github.com/pingcap/tidb/config" +<<<<<<< HEAD +======= + "github.com/pingcap/tidb/ddl/placement" +>>>>>>> 932148962... ddl, executor: fix test race in terror (#25405) "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -1168,6 +1172,26 @@ func buildTableInfo( tbInfo.Columns = append(tbInfo.Columns, v.ToInfo()) } for _, constr := range constraints { +<<<<<<< HEAD +======= + // Build hidden columns if necessary. + hiddenCols, err := buildHiddenColumnInfo(ctx, constr.Keys, model.NewCIStr(constr.Name), tbInfo, tblColumns) + if err != nil { + return nil, err + } + for _, hiddenCol := range hiddenCols { + hiddenCol.State = model.StatePublic + hiddenCol.ID = allocateColumnID(tbInfo) + hiddenCol.Offset = len(tbInfo.Columns) + tbInfo.Columns = append(tbInfo.Columns, hiddenCol) + tblColumns = append(tblColumns, table.ToColumn(hiddenCol)) + } + // Check clustered on non-primary key. + if constr.Option != nil && constr.Option.PrimaryKeyTp != model.PrimaryKeyTypeDefault && + constr.Tp != ast.ConstraintPrimaryKey { + return nil, errUnsupportedClusteredSecondaryKey + } +>>>>>>> 932148962... ddl, executor: fix test race in terror (#25405) if constr.Tp == ast.ConstraintForeignKey { for _, fk := range tbInfo.ForeignKeys { if fk.Name.L == strings.ToLower(constr.Name) { diff --git a/ddl/error.go b/ddl/error.go index 9d27ab50e2d74..02a24c1116c44 100644 --- a/ddl/error.go +++ b/ddl/error.go @@ -214,4 +214,58 @@ var ( ErrAddColumnWithSequenceAsDefault = dbterror.ClassDDL.NewStd(mysql.ErrAddColumnWithSequenceAsDefault) // ErrUnsupportedExpressionIndex is returned when create an expression index without allow-expression-index. ErrUnsupportedExpressionIndex = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "creating expression index without allow-expression-index in config"), nil)) +<<<<<<< HEAD +======= + // ErrPartitionExchangePartTable is returned when exchange table partition with another table is partitioned. + ErrPartitionExchangePartTable = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangePartTable) + // ErrTablesDifferentMetadata is returned when exchanges tables is not compatible. + ErrTablesDifferentMetadata = dbterror.ClassDDL.NewStd(mysql.ErrTablesDifferentMetadata) + // ErrRowDoesNotMatchPartition is returned when the row record of exchange table does not match the partition rule. + ErrRowDoesNotMatchPartition = dbterror.ClassDDL.NewStd(mysql.ErrRowDoesNotMatchPartition) + // ErrPartitionExchangeForeignKey is returned when exchanged normal table has foreign keys. + ErrPartitionExchangeForeignKey = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangeForeignKey) + // ErrCheckNoSuchTable is returned when exchanged normal table is view or sequence. + ErrCheckNoSuchTable = dbterror.ClassDDL.NewStd(mysql.ErrCheckNoSuchTable) + errUnsupportedPartitionType = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "partition type of table %s when exchanging partition"), nil)) + // ErrPartitionExchangeDifferentOption is returned when attribute does not match between partition table and normal table. + ErrPartitionExchangeDifferentOption = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangeDifferentOption) + // ErrTableOptionUnionUnsupported is returned when create/alter table with union option. + ErrTableOptionUnionUnsupported = dbterror.ClassDDL.NewStd(mysql.ErrTableOptionUnionUnsupported) + // ErrTableOptionInsertMethodUnsupported is returned when create/alter table with insert method option. + ErrTableOptionInsertMethodUnsupported = dbterror.ClassDDL.NewStd(mysql.ErrTableOptionInsertMethodUnsupported) + + // ErrInvalidPlacementSpec is returned when add/alter an invalid placement rule + ErrInvalidPlacementSpec = dbterror.ClassDDL.NewStd(mysql.ErrInvalidPlacementSpec) + + // ErrInvalidPlacementPolicyCheck is returned when txn_scope and commit data changing do not meet the placement policy + ErrInvalidPlacementPolicyCheck = dbterror.ClassDDL.NewStd(mysql.ErrPlacementPolicyCheck) + + // ErrMultipleDefConstInListPart returns multiple definition of same constant in list partitioning. + ErrMultipleDefConstInListPart = dbterror.ClassDDL.NewStd(mysql.ErrMultipleDefConstInListPart) + + // ErrTruncatedWrongValue is returned when data has been truncated during conversion. + ErrTruncatedWrongValue = dbterror.ClassDDL.NewStd(mysql.ErrTruncatedWrongValue) + + // ErrWarnDataOutOfRange is returned when the value in a numeric column that is outside the permissible range of the column data type. + // See https://dev.mysql.com/doc/refman/5.5/en/out-of-range-and-overflow.html for details + ErrWarnDataOutOfRange = dbterror.ClassDDL.NewStd(mysql.ErrWarnDataOutOfRange) + + // ErrTooLongValueForType is returned when the individual enum element length is too long. + ErrTooLongValueForType = dbterror.ClassDDL.NewStd(mysql.ErrTooLongValueForType) + + // ErrUnknownEngine is returned when the table engine is unknown. + ErrUnknownEngine = dbterror.ClassDDL.NewStd(mysql.ErrUnknownStorageEngine) + + errExchangePartitionDisabled = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Exchange Partition is disabled, please set 'tidb_enable_exchange_partition' if you need to need to enable it", nil)) + + // ErrPartitionNoTemporary returns when partition at temporary mode + ErrPartitionNoTemporary = dbterror.ClassDDL.NewStd(mysql.ErrPartitionNoTemporary) + + // ErrOptOnTemporaryTable returns when exec unsupported opt at temporary mode + ErrOptOnTemporaryTable = dbterror.ClassDDL.NewStd(mysql.ErrOptOnTemporaryTable) + + errUnsupportedOnCommitPreserve = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("TiDB doesn't support ON COMMIT PRESERVE ROWS for now", nil)) + errUnsupportedEngineTemporary = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("TiDB doesn't support this kind of engine for temporary table", nil)) + errUnsupportedClusteredSecondaryKey = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("CLUSTERED/NONCLUSTERED keyword is only supported for primary key", nil)) +>>>>>>> 932148962... ddl, executor: fix test race in terror (#25405) ) diff --git a/executor/ddl.go b/executor/ddl.go index ef903bd4e377d..4a1f5b0c5f7a3 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -551,6 +551,13 @@ func (e *DDLExec) getRecoverTableByTableName(tableName *ast.TableName) (*model.J if tableInfo == nil || jobInfo == nil { return nil, nil, errors.Errorf("Can't find dropped/truncated table: %v in DDL history jobs", tableName.Name) } +<<<<<<< HEAD +======= + // Dropping local temporary tables won't appear in DDL jobs. + if tableInfo.TempTableType == model.TempTableGlobal { + return nil, nil, errUnsupportedFlashbackTmpTable + } +>>>>>>> 932148962... ddl, executor: fix test race in terror (#25405) return jobInfo, tableInfo, nil } diff --git a/executor/errors.go b/executor/errors.go index d648b56b81c81..cd460319ab052 100644 --- a/executor/errors.go +++ b/executor/errors.go @@ -14,6 +14,7 @@ package executor import ( + parser_mysql "github.com/pingcap/parser/mysql" mysql "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/util/dbterror" ) @@ -44,8 +45,21 @@ var ( ErrDeadlock = dbterror.ClassExecutor.NewStd(mysql.ErrLockDeadlock) ErrQueryInterrupted = dbterror.ClassExecutor.NewStd(mysql.ErrQueryInterrupted) +<<<<<<< HEAD ErrBRIEBackupFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEBackupFailed) ErrBRIERestoreFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIERestoreFailed) ErrBRIEImportFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEImportFailed) ErrBRIEExportFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEExportFailed) +======= + ErrBRIEBackupFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEBackupFailed) + ErrBRIERestoreFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIERestoreFailed) + ErrBRIEImportFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEImportFailed) + ErrBRIEExportFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEExportFailed) + ErrCTEMaxRecursionDepth = dbterror.ClassExecutor.NewStd(mysql.ErrCTEMaxRecursionDepth) + ErrDataInConsistentExtraIndex = dbterror.ClassExecutor.NewStd(mysql.ErrDataInConsistentExtraIndex) + ErrDataInConsistentMisMatchIndex = dbterror.ClassExecutor.NewStd(mysql.ErrDataInConsistentMisMatchIndex) + + errUnsupportedFlashbackTmpTable = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Recover/flashback table is not supported on temporary tables", nil)) + errTruncateWrongInsertValue = dbterror.ClassTable.NewStdErr(mysql.ErrTruncatedWrongValue, parser_mysql.Message("Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %d", nil)) +>>>>>>> 932148962... ddl, executor: fix test race in terror (#25405) ) diff --git a/executor/insert_common.go b/executor/insert_common.go index d6fbcfa74b353..07206ddba677f 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -299,6 +299,15 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int err = types.ErrWarnDataOutOfRange.GenWithStackByArgs(colName, rowIdx+1) } else if types.ErrTruncated.Equal(err) { err = types.ErrTruncated.GenWithStackByArgs(colName, rowIdx+1) +<<<<<<< HEAD +======= + } else if types.ErrTruncatedWrongVal.Equal(err) && (colTp == mysql.TypeDuration || colTp == mysql.TypeDatetime || colTp == mysql.TypeDate || colTp == mysql.TypeTimestamp) { + valStr, err1 := val.ToString() + if err1 != nil { + logutil.BgLogger().Debug("time truncated error", zap.Error(err1)) + } + err = errTruncateWrongInsertValue.GenWithStackByArgs(types.TypeStr(colTp), valStr, colName, rowIdx+1) +>>>>>>> 932148962... ddl, executor: fix test race in terror (#25405) } else if types.ErrTruncatedWrongVal.Equal(err) || types.ErrWrongValue.Equal(err) { valStr, err1 := val.ToString() if err1 != nil {