From 2e729efee164b70a44cc4f5141ee7c62b5ab8ba2 Mon Sep 17 00:00:00 2001 From: GMHDBJD <35025882+GMHDBJD@users.noreply.github.com> Date: Tue, 26 Dec 2023 15:39:27 +0800 Subject: [PATCH] dm: set enable cluster index to off for downstream tracker (#10346) close pingcap/tiflow#10308 --- dm/pkg/schema/tracker.go | 12 ++++++++++++ dm/pkg/schema/tracker_test.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dm/pkg/schema/tracker.go b/dm/pkg/schema/tracker.go index f5b7b1950fc..c6bb88625c2 100644 --- a/dm/pkg/schema/tracker.go +++ b/dm/pkg/schema/tracker.go @@ -32,6 +32,7 @@ import ( "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx" + "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/filter" "github.com/pingcap/tidb/pkg/util/mock" @@ -465,6 +466,17 @@ func (dt *downstreamTracker) getTableInfoByCreateStmt(tctx *tcontext.Context, ta return nil, dmterror.ErrSchemaTrackerInvalidCreateTableStmt.Delegate(err, createStr) } + // suppress ErrTooLongKey + strictSQLModeBackup := dt.se.GetSessionVars().StrictSQLMode + dt.se.GetSessionVars().StrictSQLMode = false + // support drop PK + enableClusteredIndexBackup := dt.se.GetSessionVars().EnableClusteredIndex + dt.se.GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOff + defer func() { + dt.se.GetSessionVars().StrictSQLMode = strictSQLModeBackup + dt.se.GetSessionVars().EnableClusteredIndex = enableClusteredIndexBackup + }() + ti, err := ddl.BuildTableInfoWithStmt(dt.se, stmtNode.(*ast.CreateTableStmt), mysql.DefaultCharset, "", nil) if err != nil { return nil, dmterror.ErrSchemaTrackerCannotMockDownstreamTable.Delegate(err, createStr) diff --git a/dm/pkg/schema/tracker_test.go b/dm/pkg/schema/tracker_test.go index 3b04c8df5b9..f8780c7b7ad 100644 --- a/dm/pkg/schema/tracker_test.go +++ b/dm/pkg/schema/tracker_test.go @@ -613,7 +613,7 @@ func TestGetDownStreamIndexInfo(t *testing.T) { mock.ExpectQuery("SHOW CREATE TABLE " + tableID).WillReturnRows( sqlmock.NewRows([]string{"Table", "Create Table"}). - AddRow("test", "create table t(a int primary key, b int, c varchar(20000), key(c(20000)))")) + AddRow("test", "create table t(a int, b int, c varchar(20000), primary key(a, b), key(c(20000)))/*!90000 SHARD_ROW_ID_BITS=6 */")) dti, err := tracker.GetDownStreamTableInfo(tcontext.Background(), tableID, oriTi) require.NoError(t, err) require.NotNil(t, dti.WhereHandle.UniqueNotNullIdx)