diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 148a5d80e9585..7e5e412721d64 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1577,7 +1577,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { c.Assert(err, NotNil) result := tk.MustQuery("show create table mc") createSQL := result.Rows()[0][1] - expected := "CREATE TABLE `mc` (\n `a` int(11) NOT NULL,\n `b` int(11) DEFAULT NULL,\n `c` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" + expected := "CREATE TABLE `mc` (\n `a` int(11) NOT NULL,\n `b` int(11) DEFAULT NULL,\n `c` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) // Change / modify column should preserve index options. @@ -1588,7 +1588,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { tk.MustExec("alter table mc modify column c bigint") // Unique should be preserved result = tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] - expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` bigint(20) DEFAULT NULL,\n `c` bigint(20) DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `c` (`c`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" + expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` bigint(20) DEFAULT NULL,\n `c` bigint(20) DEFAULT NULL,\n PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */,\n UNIQUE KEY `c` (`c`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) // Dropping or keeping auto_increment is allowed, however adding is not allowed. @@ -1597,7 +1597,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { tk.MustExec("alter table mc modify column a bigint auto_increment") // Keeps auto_increment result = tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] - expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL AUTO_INCREMENT,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" + expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL AUTO_INCREMENT,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) _, err = tk.Exec("alter table mc modify column a bigint") // Droppping auto_increment is not allow when @@tidb_allow_remove_auto_inc == 'off' c.Assert(err, NotNil) @@ -1605,7 +1605,7 @@ func (s *testIntegrationSuite3) TestAlterColumn(c *C) { tk.MustExec("alter table mc modify column a bigint") // Dropping auto_increment is ok when @@tidb_allow_remove_auto_inc == 'on' result = tk.MustQuery("show create table mc") createSQL = result.Rows()[0][1] - expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" + expected = "CREATE TABLE `mc` (\n `a` bigint(20) NOT NULL,\n `b` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) _, err = tk.Exec("alter table mc modify column a bigint auto_increment") // Adds auto_increment should throw error diff --git a/ddl/db_test.go b/ddl/db_test.go index ccb3d7ba08796..887ab41ed5d45 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -1794,7 +1794,7 @@ func (s *testDBSuite5) TestAlterPrimaryKey(c *C) { " `a` int(11) NOT NULL,\n"+ " `b` int(11) NOT NULL,\n"+ " KEY `idx` (`a`),\n"+ - " PRIMARY KEY (`a`,`b`)\n"+ + " PRIMARY KEY (`a`,`b`) /*T![clustered_index] NONCLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) tk.MustExec("alter table test_add_pk2 drop primary key") tk.MustQuery("desc test_add_pk2").Check(testutil.RowsWithSep(",", ""+ @@ -2794,7 +2794,7 @@ func (s *testSerialDBSuite) TestRepairTable(c *C) { // Exec the show create table statement to make sure new tableInfo has been set. result := tk.MustQuery("show create table origin") - c.Assert(result.Rows()[0][1], Equals, "CREATE TABLE `origin` (\n `a` int(11) NOT NULL AUTO_INCREMENT,\n `b` varchar(5) DEFAULT NULL,\n `c` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") + c.Assert(result.Rows()[0][1], Equals, "CREATE TABLE `origin` (\n `a` int(11) NOT NULL AUTO_INCREMENT,\n `b` varchar(5) DEFAULT NULL,\n `c` int(11) DEFAULT NULL,\n PRIMARY KEY (`a`) /*T![clustered_index] NONCLUSTERED */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") } diff --git a/ddl/failtest/fail_db_test.go b/ddl/failtest/fail_db_test.go index 38e73834524c9..635ff7878e904 100644 --- a/ddl/failtest/fail_db_test.go +++ b/ddl/failtest/fail_db_test.go @@ -483,7 +483,7 @@ func (s *testFailDBSuite) TestModifyColumn(c *C) { " `bb` mediumint(9) DEFAULT NULL,\n" + " `a` int(11) NOT NULL DEFAULT '1',\n" + " `c` int(11) NOT NULL DEFAULT '0',\n" + - " PRIMARY KEY (`c`),\n" + + " PRIMARY KEY (`c`) /*T![clustered_index] CLUSTERED */,\n" + " KEY `idx` (`bb`),\n" + " KEY `idx1` (`a`),\n" + " KEY `idx2` (`bb`,`c`)\n" + @@ -497,7 +497,7 @@ func (s *testFailDBSuite) TestModifyColumn(c *C) { " `bb` mediumint(9) DEFAULT NULL,\n" + " `c` int(11) NOT NULL DEFAULT '0',\n" + " `aa` mediumint(9) DEFAULT NULL,\n" + - " PRIMARY KEY (`c`),\n" + + " PRIMARY KEY (`c`) /*T![clustered_index] CLUSTERED */,\n" + " KEY `idx` (`bb`),\n" + " KEY `idx1` (`aa`),\n" + " KEY `idx2` (`bb`,`c`)\n" + diff --git a/executor/clustered_index_test.go b/executor/clustered_index_test.go index 795c8ae18bc61..d8a13cfb0573a 100644 --- a/executor/clustered_index_test.go +++ b/executor/clustered_index_test.go @@ -299,7 +299,9 @@ func (s *testClusteredSerialSuite) TestClusteredIndexSyntax(c *C) { } assertPkType("create table t (a int primary key, b int);", intPKDefault) assertPkType("create table t (a int, b int, primary key(a) clustered);", intClustered) + assertPkType("create table t (a int, b int, primary key(a) /*T![clustered_index] clustered */);", intClustered) assertPkType("create table t (a int, b int, primary key(a) nonclustered);", nonClustered) + assertPkType("create table t (a int, b int, primary key(a) /*T![clustered_index] nonclustered */);", nonClustered) // Test for clustered index. tk.Se.GetSessionVars().EnableClusteredIndex = false @@ -309,6 +311,8 @@ func (s *testClusteredSerialSuite) TestClusteredIndexSyntax(c *C) { tk.Se.GetSessionVars().EnableClusteredIndex = true assertPkType("create table t (a int, b varchar(255), primary key(b, a));", commonPKDefault) assertPkType("create table t (a int, b varchar(255), primary key(b, a) nonclustered);", nonClustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] nonclustered */);", nonClustered) assertPkType("create table t (a int, b varchar(255), primary key(b, a) clustered);", commonClustered) + assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] clustered */);", commonClustered) } } diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index e409fd7ea2773..fa6cf04806d1f 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -198,7 +198,7 @@ func (s *seqTestSuite) TestShow(c *C) { row := result.Rows()[0] // For issue https://github.com/pingcap/tidb/issues/1061 expectedRow := []interface{}{ - "SHOW_test", "CREATE TABLE `SHOW_test` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `c1` int(11) DEFAULT NULL COMMENT 'c1_comment',\n `c2` int(11) DEFAULT NULL,\n `c3` int(11) DEFAULT '1',\n `c4` text DEFAULT NULL,\n `c5` tinyint(1) DEFAULT NULL,\n PRIMARY KEY (`id`),\n KEY `idx_wide_c4` (`c3`,`c4`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=28934 COMMENT='table_comment'"} + "SHOW_test", "CREATE TABLE `SHOW_test` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `c1` int(11) DEFAULT NULL COMMENT 'c1_comment',\n `c2` int(11) DEFAULT NULL,\n `c3` int(11) DEFAULT '1',\n `c4` text DEFAULT NULL,\n `c5` tinyint(1) DEFAULT NULL,\n PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n KEY `idx_wide_c4` (`c3`,`c4`(10))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=28934 COMMENT='table_comment'"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -218,7 +218,7 @@ func (s *seqTestSuite) TestShow(c *C) { c.Check(result.Rows(), HasLen, 1) row = result.Rows()[0] expectedRow = []interface{}{ - "ptest", "CREATE TABLE `ptest` (\n `a` int(11) NOT NULL,\n `b` double NOT NULL DEFAULT '2.0',\n `c` varchar(10) NOT NULL,\n `d` time DEFAULT NULL,\n `e` timestamp NULL DEFAULT NULL,\n `f` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `d` (`d`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} + "ptest", "CREATE TABLE `ptest` (\n `a` int(11) NOT NULL,\n `b` double NOT NULL DEFAULT '2.0',\n `c` varchar(10) NOT NULL,\n `d` time DEFAULT NULL,\n `e` timestamp NULL DEFAULT NULL,\n `f` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n UNIQUE KEY `d` (`d`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"} for i, r := range row { c.Check(r, Equals, expectedRow[i]) } @@ -401,7 +401,7 @@ func (s *seqTestSuite) TestShow(c *C) { ""+ "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`id`)\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=4", )) // for issue https://github.com/pingcap/tidb/issues/4678 @@ -412,7 +412,7 @@ func (s *seqTestSuite) TestShow(c *C) { ""+ "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`id`)\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT="+strconv.Itoa(int(autoID)), )) tk.MustExec(`drop table show_auto_increment`) @@ -421,7 +421,7 @@ func (s *seqTestSuite) TestShow(c *C) { ""+ "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`id`)\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) tk.MustExec("insert into show_auto_increment values(10)") @@ -430,7 +430,7 @@ func (s *seqTestSuite) TestShow(c *C) { ""+ "show_auto_increment CREATE TABLE `show_auto_increment` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`id`)\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT="+strconv.Itoa(int(autoID)), )) @@ -594,7 +594,7 @@ func (s *seqTestSuite) TestShow(c *C) { "t CREATE TABLE `t` (\n"+ " `y` year(4) NOT NULL,\n"+ " `x` int(11) DEFAULT NULL,\n"+ - " PRIMARY KEY (`y`)\n"+ + " PRIMARY KEY (`y`) /*T![clustered_index] NONCLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) // Test show create table with zerofill flag @@ -604,7 +604,7 @@ func (s *seqTestSuite) TestShow(c *C) { "t CREATE TABLE `t` (\n"+ " `id` int(11) NOT NULL,\n"+ " `val` tinyint(10) unsigned zerofill DEFAULT NULL,\n"+ - " PRIMARY KEY (`id`)\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) // Test show columns with different types of default value diff --git a/executor/show.go b/executor/show.go index 44957142f8c7f..939b830915865 100644 --- a/executor/show.go +++ b/executor/show.go @@ -827,6 +827,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T // If PKIsHanle, pk info is not in tb.Indices(). We should handle it here. buf.WriteString(",\n") fmt.Fprintf(buf, " PRIMARY KEY (%s)", stringutil.Escape(pkCol.Name.O, sqlMode)) + buf.WriteString(fmt.Sprintf(" /*T![clustered_index] CLUSTERED */")) } publicIndices := make([]*model.IndexInfo, 0, len(tableInfo.Indices)) @@ -865,6 +866,13 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T if idxInfo.Invisible { fmt.Fprintf(buf, ` /*!80000 INVISIBLE */`) } + if idxInfo.Primary { + if tableInfo.PKIsHandle || tableInfo.IsCommonHandle { + buf.WriteString(fmt.Sprintf(" /*T![clustered_index] CLUSTERED */")) + } else { + buf.WriteString(fmt.Sprintf(" /*T![clustered_index] NONCLUSTERED */")) + } + } if i != len(publicIndices)-1 { buf.WriteString(",\n") } diff --git a/executor/show_test.go b/executor/show_test.go index 6113cfa86fa6c..6cbecb365b152 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -673,7 +673,7 @@ func (s *testSuite5) TestShowCreateTable(c *C) { " `END_TIME` datetime NOT NULL,\n"+ " `USER_TYPE` int(11) DEFAULT NULL,\n"+ " `APP_ID` int(11) DEFAULT NULL,\n"+ - " PRIMARY KEY (`LOG_ID`,`END_TIME`),\n"+ + " PRIMARY KEY (`LOG_ID`,`END_TIME`) /*T![clustered_index] NONCLUSTERED */,\n"+ " KEY `IDX_EndTime` (`END_TIME`),\n"+ " KEY `IDX_RoundId` (`ROUND_ID`),\n"+ " KEY `IDX_UserId_EndTime` (`USER_ID`,`END_TIME`)\n"+ @@ -789,7 +789,7 @@ func (s *testSuite5) TestShowCreateTable(c *C) { "child CREATE TABLE `child` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ " `parent_id` int(11) NOT NULL,\n"+ - " PRIMARY KEY (`id`),\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n"+ " KEY `par_ind` (`parent_id`),\n"+ " CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", @@ -803,7 +803,7 @@ func (s *testSuite5) TestShowCreateTable(c *C) { "child CREATE TABLE `child` (\n"+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"+ " `parent_id` int(11) NOT NULL,\n"+ - " PRIMARY KEY (`id`),\n"+ + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n"+ " KEY `par_ind` (`parent_id`),\n"+ " CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", @@ -887,7 +887,7 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { "auto_random_tbl1 CREATE TABLE `auto_random_tbl1` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(3) */,\n"+ " `b` varchar(255) DEFAULT NULL,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) @@ -898,7 +898,7 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { "auto_random_tbl2 CREATE TABLE `auto_random_tbl2` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ " `b` char(1) DEFAULT NULL,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) @@ -908,7 +908,7 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { ""+ "auto_random_tbl3 CREATE TABLE `auto_random_tbl3` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) // Test show auto_random table option. @@ -918,7 +918,7 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { "auto_random_tbl4 CREATE TABLE `auto_random_tbl4` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ " `b` varchar(255) DEFAULT NULL,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=100 */", )) // Test implicit auto_random with auto_random table option. @@ -928,7 +928,7 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { "auto_random_tbl5 CREATE TABLE `auto_random_tbl5` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ " `b` char(1) DEFAULT NULL,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=50 */", )) // Test auto_random table option already with special comment. @@ -937,7 +937,7 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { ""+ "auto_random_tbl6 CREATE TABLE `auto_random_tbl6` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=200 */", )) } @@ -953,7 +953,7 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { ""+ "t CREATE TABLE `t` (\n"+ " `a` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=10 */", )) tk.MustExec("drop table if exists t") @@ -963,7 +963,7 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { "t CREATE TABLE `t` (\n"+ " `a` int(11) NOT NULL AUTO_INCREMENT,\n"+ " `b` int(11) NOT NULL,\n"+ - " PRIMARY KEY (`b`),\n"+ + " PRIMARY KEY (`b`) /*T![clustered_index] CLUSTERED */,\n"+ " UNIQUE KEY `a` (`a`)\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=100 */", )) @@ -973,7 +973,7 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { ""+ "t CREATE TABLE `t` (\n"+ " `a` int(11) NOT NULL,\n"+ - " PRIMARY KEY (`a`)\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=5 */", )) } @@ -995,7 +995,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { "t CREATE TABLE `t` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`a`),\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n"+ " UNIQUE KEY `b` (`b`)\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 /*T![auto_rand_base] AUTO_RANDOM_BASE=100 */", )) @@ -1006,7 +1006,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { "t CREATE TABLE `t` (\n"+ " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ - " PRIMARY KEY (`a`),\n"+ + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,\n"+ " UNIQUE KEY `b` (`b`)\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=5100 /*T![auto_rand_base] AUTO_RANDOM_BASE=6001 */", )) @@ -1043,7 +1043,7 @@ func (s *testSuite5) TestShowEscape(c *C) { ""+ "t`abl\"e CREATE TABLE `t``abl\"e` (\n"+ " `c``olum\"n` int(11) NOT NULL,\n"+ - " PRIMARY KEY (`c``olum\"n`)\n"+ + " PRIMARY KEY (`c``olum\"n`) /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) @@ -1054,7 +1054,7 @@ func (s *testSuite5) TestShowEscape(c *C) { ""+ "t`abl\"e CREATE TABLE \"t`abl\"\"e\" (\n"+ " \"c`olum\"\"n\" int(11) NOT NULL,\n"+ - " PRIMARY KEY (\"c`olum\"\"n\")\n"+ + " PRIMARY KEY (\"c`olum\"\"n\") /*T![clustered_index] CLUSTERED */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 32f347a1f9d79..00d3ab8d3a5d1 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -244,7 +244,7 @@ func (s *testTableSuite) TestInfoschemaFieldValue(c *C) { "t CREATE TABLE `t` (\n" + " `c` int(11) NOT NULL AUTO_INCREMENT,\n" + " `d` int(11) DEFAULT NULL,\n" + - " PRIMARY KEY (`c`)\n" + + " PRIMARY KEY (`c`) /*T![clustered_index] CLUSTERED */\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=30002")) // Test auto_increment for table without auto_increment column diff --git a/sessionctx/binloginfo/binloginfo_test.go b/sessionctx/binloginfo/binloginfo_test.go index c762747ba2c6f..f6d9e4086fca1 100644 --- a/sessionctx/binloginfo/binloginfo_test.go +++ b/sessionctx/binloginfo/binloginfo_test.go @@ -592,6 +592,18 @@ func (s *testBinlogSuite) TestAddSpecialComment(c *C) { "create table t1 (id int) /*T![auto_id_cache] auto_id_cache=5 */ ;", "create table t1 (id int) /*T![auto_id_cache] auto_id_cache=5 */ ;", }, + { + "create table t1 (id int, a varchar(255), primary key (a, b) clustered);", + "create table t1 (id int, a varchar(255), primary key (a, b) /*T![clustered_index] clustered */ );", + }, + { + "create table t1 (id int, a varchar(255), primary key (a, b) nonclustered);", + "create table t1 (id int, a varchar(255), primary key (a, b) /*T![clustered_index] nonclustered */ );", + }, + { + "create table t1 (id int, a varchar(255), primary key (a, b) /*T![clustered_index] nonclustered */);", + "create table t1 (id int, a varchar(255), primary key (a, b) /*T![clustered_index] nonclustered */);", + }, } for _, ca := range testCase { re := binloginfo.AddSpecialComment(ca.input) diff --git a/table/tables/tables_test.go b/table/tables/tables_test.go index 5b446b497e8cf..36f13d45e0243 100644 --- a/table/tables/tables_test.go +++ b/table/tables/tables_test.go @@ -470,7 +470,7 @@ func (ts *testSuite) TestHiddenColumn(c *C) { " `a` int(11) NOT NULL,\n" + " `c` int(11) DEFAULT NULL,\n" + " `e` int(11) DEFAULT NULL,\n" + - " PRIMARY KEY (`a`)\n" + + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) // Test show (extended) columns @@ -572,7 +572,7 @@ func (ts *testSuite) TestHiddenColumn(c *C) { " `a` int(11) NOT NULL,\n" + " `c` int(11) DEFAULT NULL,\n" + " `e` int(11) DEFAULT NULL,\n" + - " PRIMARY KEY (`a`)\n" + + " PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) tk.MustQuery("show extended columns from t").Check(testutil.RowsWithSep("|", "a|int(11)|NO|PRI||", diff --git a/types/parser_driver/special_cmt_ctrl.go b/types/parser_driver/special_cmt_ctrl.go index c1b018b685705..5621c29e0acbc 100644 --- a/types/parser_driver/special_cmt_ctrl.go +++ b/types/parser_driver/special_cmt_ctrl.go @@ -34,6 +34,7 @@ func init() { parser.SpecialCommentsController.Register(string(FeatureIDAutoRandom)) parser.SpecialCommentsController.Register(string(FeatureIDAutoIDCache)) parser.SpecialCommentsController.Register(string(FeatureIDAutoRandomBase)) + parser.SpecialCommentsController.Register(string(FeatureClusteredIndex)) } // SpecialCommentVersionPrefix is the prefix of TiDB executable comments. @@ -58,6 +59,8 @@ const ( FeatureIDAutoIDCache featureID = "auto_id_cache" // FeatureIDAutoRandomBase is the `auto_random_base` feature. FeatureIDAutoRandomBase featureID = "auto_rand_base" + // FeatureClusteredIndex is the `clustered_index` feature. + FeatureClusteredIndex featureID = "clustered_index" ) // FeatureIDPatterns is used to record special comments patterns. @@ -65,4 +68,5 @@ var FeatureIDPatterns = map[featureID]*regexp.Regexp{ FeatureIDAutoRandom: regexp.MustCompile(`(?i)AUTO_RANDOM\b\s*(\s*\(\s*\d+\s*\)\s*)?`), FeatureIDAutoIDCache: regexp.MustCompile(`(?i)AUTO_ID_CACHE\s*=?\s*\d+\s*`), FeatureIDAutoRandomBase: regexp.MustCompile(`(?i)AUTO_RANDOM_BASE\s*=?\s*\d+\s*`), + FeatureClusteredIndex: regexp.MustCompile(`(?i)(NON)?CLUSTERED`), }