diff --git a/cmd/explaintest/main.go b/cmd/explaintest/main.go index 32f88dc30a6bc..d5f7f0c98b0a1 100644 --- a/cmd/explaintest/main.go +++ b/cmd/explaintest/main.go @@ -724,6 +724,7 @@ func main() { "set @@tidb_window_concurrency=4", "set @@tidb_projection_concurrency=4", "set @@tidb_distsql_scan_concurrency=15", + "set @@tidb_enable_clustered_index='int_only';", "set @@global.tidb_enable_clustered_index=0;", "set @@global.tidb_mem_quota_query=34359738368", "set @@tidb_mem_quota_query=34359738368", diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index c0e087ef4a046..fb92c3087b78b 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -4068,7 +4068,7 @@ func TestCreateAndAlterIntervalPartition(t *testing.T) { tk.MustQuery("select count(*) from ipt").Check(testkit.Rows("27")) - tk.MustExec("create table idpt (id date primary key, val varchar(255), key (val)) partition by range COLUMNS (id) INTERVAL (1 week) FIRST PARTITION LESS THAN ('2022-02-01') LAST PARTITION LESS THAN ('2022-03-29') NULL PARTITION MAXVALUE PARTITION") + tk.MustExec("create table idpt (id date primary key nonclustered, val varchar(255), key (val)) partition by range COLUMNS (id) INTERVAL (1 week) FIRST PARTITION LESS THAN ('2022-02-01') LAST PARTITION LESS THAN ('2022-03-29') NULL PARTITION MAXVALUE PARTITION") tk.MustQuery("SHOW CREATE TABLE idpt").Check(testkit.Rows( "idpt CREATE TABLE `idpt` (\n" + " `id` date NOT NULL,\n" + @@ -4094,7 +4094,7 @@ func TestCreateAndAlterIntervalPartition(t *testing.T) { // if using a month with 31 days. // But managing partitions with the day-part of 29, 30 or 31 will be troublesome, since once the FIRST is not 31 // both the ALTER TABLE t FIRST PARTITION and MERGE FIRST PARTITION will have issues - tk.MustExec("create table t (id date primary key, val varchar(255), key (val)) partition by range COLUMNS (id) INTERVAL (1 MONTH) FIRST PARTITION LESS THAN ('2022-01-31') LAST PARTITION LESS THAN ('2022-05-31')") + tk.MustExec("create table t (id date primary key nonclustered, val varchar(255), key (val)) partition by range COLUMNS (id) INTERVAL (1 MONTH) FIRST PARTITION LESS THAN ('2022-01-31') LAST PARTITION LESS THAN ('2022-05-31')") tk.MustQuery("show create table t").Check(testkit.Rows( "t CREATE TABLE `t` (\n" + " `id` date NOT NULL,\n" + diff --git a/ddl/index_modify_test.go b/ddl/index_modify_test.go index 00695b3da8f6e..38f091f41bc10 100644 --- a/ddl/index_modify_test.go +++ b/ddl/index_modify_test.go @@ -816,7 +816,7 @@ func TestDropIndexes(t *testing.T) { store := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease, mockstore.WithDDLChecker()) // drop multiple indexes - createSQL := "create table test_drop_indexes (id int, c1 int, c2 int, primary key(id), key i1(c1), key i2(c2));" + createSQL := "create table test_drop_indexes (id int, c1 int, c2 int, primary key(id) nonclustered, key i1(c1), key i2(c2));" dropIdxSQL := "alter table test_drop_indexes drop index i1, drop index i2;" idxNames := []string{"i1", "i2"} testDropIndexes(t, store, createSQL, dropIdxSQL, idxNames) @@ -826,7 +826,7 @@ func TestDropIndexes(t *testing.T) { idxNames = []string{"primary", "i1"} testDropIndexes(t, store, createSQL, dropIdxSQL, idxNames) - createSQL = "create table test_drop_indexes (uuid varchar(32), c1 int, c2 int, primary key(uuid), unique key i1(c1), key i2(c2));" + createSQL = "create table test_drop_indexes (uuid varchar(32), c1 int, c2 int, primary key(uuid) nonclustered, unique key i1(c1), key i2(c2));" dropIdxSQL = "alter table test_drop_indexes drop primary key, drop index i1, drop index i2;" idxNames = []string{"primary", "i1", "i2"} testDropIndexes(t, store, createSQL, dropIdxSQL, idxNames) diff --git a/executor/charset_test.go b/executor/charset_test.go index 72dd9351f1b6c..d40bc6a2fe296 100644 --- a/executor/charset_test.go +++ b/executor/charset_test.go @@ -101,9 +101,9 @@ func TestCharsetWithPrefixIndex(t *testing.T) { tk.MustExec("use test") tk.MustExec("create table t(a char(20) charset gbk, b char(20) charset gbk, primary key (a(2)))") tk.MustExec("insert into t values ('a', '中文'), ('中文', '中文'), ('一二三', '一二三'), ('b', '一二三')") - tk.MustQuery("select * from t").Check(testkit.Rows("a 中文", "中文 中文", "一二三 一二三", "b 一二三")) + tk.MustQuery("select * from t;").Sort().Check(testkit.Rows("a 中文", "b 一二三", "一二三 一二三", "中文 中文")) tk.MustExec("drop table t") tk.MustExec("create table t(a char(20) charset gbk, b char(20) charset gbk, unique index idx_a(a(2)))") tk.MustExec("insert into t values ('a', '中文'), ('中文', '中文'), ('一二三', '一二三'), ('b', '一二三')") - tk.MustQuery("select * from t").Check(testkit.Rows("a 中文", "中文 中文", "一二三 一二三", "b 一二三")) + tk.MustQuery("select * from t;").Sort().Check(testkit.Rows("a 中文", "b 一二三", "一二三 一二三", "中文 中文")) } diff --git a/executor/index_merge_reader_test.go b/executor/index_merge_reader_test.go index ae53e1e6c86e2..58dfa71814f28 100644 --- a/executor/index_merge_reader_test.go +++ b/executor/index_merge_reader_test.go @@ -496,7 +496,7 @@ func TestPessimisticLockOnPartitionForIndexMerge(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t1, t2") - tk.MustExec(`create table t1 (c_datetime datetime, c1 int, c2 int, primary key (c_datetime), key(c1), key(c2)) + tk.MustExec(`create table t1 (c_datetime datetime, c1 int, c2 int, primary key (c_datetime) NONCLUSTERED, key(c1), key(c2)) partition by range (to_days(c_datetime)) ( partition p0 values less than (to_days('2020-02-01')), partition p1 values less than (to_days('2020-04-01')), diff --git a/executor/prepared_test.go b/executor/prepared_test.go index 5ebc97e9c0dcc..3d6aa75e06604 100644 --- a/executor/prepared_test.go +++ b/executor/prepared_test.go @@ -860,7 +860,7 @@ func TestIssue29101(t *testing.T) { c_last varchar(16) DEFAULT NULL, c_credit char(2) DEFAULT NULL, c_discount decimal(4,4) DEFAULT NULL, - PRIMARY KEY (c_w_id,c_d_id,c_id), + PRIMARY KEY (c_w_id,c_d_id,c_id) NONCLUSTERED, KEY idx_customer (c_w_id,c_d_id,c_last,c_first) )`) tk.MustExec(`CREATE TABLE warehouse ( @@ -890,12 +890,12 @@ func TestIssue29101(t *testing.T) { ol_w_id int(11) NOT NULL, ol_number int(11) NOT NULL, ol_i_id int(11) NOT NULL, - PRIMARY KEY (ol_w_id,ol_d_id,ol_o_id,ol_number))`) + PRIMARY KEY (ol_w_id,ol_d_id,ol_o_id,ol_number) NONCLUSTERED)`) tk.MustExec(`CREATE TABLE stock ( s_i_id int(11) NOT NULL, s_w_id int(11) NOT NULL, s_quantity int(11) DEFAULT NULL, - PRIMARY KEY (s_w_id,s_i_id))`) + PRIMARY KEY (s_w_id,s_i_id) NONCLUSTERED)`) tk.MustExec(`prepare s1 from 'SELECT /*+ TIDB_INLJ(order_line,stock) */ COUNT(DISTINCT (s_i_id)) stock_count FROM order_line, stock WHERE ol_w_id = ? AND ol_d_id = ? AND ol_o_id < ? AND ol_o_id >= ? - 20 AND s_w_id = ? AND s_i_id = ol_i_id AND s_quantity < ?'`) tk.MustExec(`set @a=391,@b=1,@c=3058,@d=18`) tk.MustExec(`execute s1 using @a,@b,@c,@c,@a,@d`) diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index 3deb9cb8a9c2d..cefdf622f2b13 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -541,7 +541,7 @@ func TestShow(t *testing.T) { // Test show create table year type tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(y year unsigned signed zerofill zerofill, x int, primary key(y));`) + tk.MustExec(`create table t(y year unsigned signed zerofill zerofill, x int, primary key(y) nonclustered);`) tk.MustQuery(`show create table t`).Check(testkit.RowsWithSep("|", "t CREATE TABLE `t` (\n"+ " `y` year(4) NOT NULL,\n"+ diff --git a/executor/showtest/show_test.go b/executor/showtest/show_test.go index 76eb9be2e8558..cd06bd56b2229 100644 --- a/executor/showtest/show_test.go +++ b/executor/showtest/show_test.go @@ -186,7 +186,7 @@ func TestShowCreateTable(t *testing.T) { "`END_TIME` datetime NOT NULL," + "`USER_TYPE` int(11) DEFAULT NULL," + "`APP_ID` int(11) DEFAULT NULL," + - "PRIMARY KEY (`LOG_ID`,`END_TIME`)," + + "PRIMARY KEY (`LOG_ID`,`END_TIME`) NONCLUSTERED," + "KEY `IDX_EndTime` (`END_TIME`)," + "KEY `IDX_RoundId` (`ROUND_ID`)," + "KEY `IDX_UserId_EndTime` (`USER_ID`,`END_TIME`)" + diff --git a/executor/write_test.go b/executor/write_test.go index fc565183009b7..32aa261c5518d 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -322,7 +322,7 @@ func TestInsert(t *testing.T) { require.EqualError(t, err, "[kv:1062]Duplicate entry 'ch' for key 't.PRIMARY'") tk.MustExec("insert into t(name, b) values(\"测试\", 3)") err = tk.ExecToErr("insert into t(name, b) values(\"测试\", 3)") - require.EqualError(t, err, "[kv:1062]Duplicate entry '测试' for key 't.PRIMARY'") + require.EqualError(t, err, "[kv:1062]Duplicate entry '\xe6\xb5' for key 't.PRIMARY'") } func TestMultiBatch(t *testing.T) { diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index c88edf4470d9b..02adf6ad2960f 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -827,7 +827,7 @@ func TestBatchPointGetTablePartition(t *testing.T) { testKit.MustExec("use test") testKit.MustExec("drop table if exists t1,t2,t3,t4,t5,t6") - testKit.MustExec("create table t1(a int, b int, primary key(a,b)) partition by hash(b) partitions 2") + testKit.MustExec("create table t1(a int, b int, primary key(a,b) nonclustered) partition by hash(b) partitions 2") testKit.MustExec("insert into t1 values(1,1),(1,2),(2,1),(2,2)") testKit.MustExec("set @@tidb_partition_prune_mode = 'static'") testKit.MustQuery("explain format = 'brief' select * from t1 where a in (1,2) and b = 1").Check(testkit.Rows( @@ -864,7 +864,7 @@ func TestBatchPointGetTablePartition(t *testing.T) { "1 2", )) - testKit.MustExec("create table t2(a int, b int, primary key(a,b)) partition by range(b) (partition p0 values less than (2), partition p1 values less than maxvalue)") + testKit.MustExec("create table t2(a int, b int, primary key(a,b) nonclustered) partition by range(b) (partition p0 values less than (2), partition p1 values less than maxvalue)") testKit.MustExec("insert into t2 values(1,1),(1,2),(2,1),(2,2)") testKit.MustExec("set @@tidb_partition_prune_mode = 'static'") testKit.MustQuery("explain format = 'brief' select * from t2 where a in (1,2) and b = 1").Check(testkit.Rows( diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 98f494da8ee54..f227e6937a7cf 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -4447,9 +4447,9 @@ func TestReorderSimplifiedOuterJoins(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t1,t2,t3") - tk.MustExec("create table t1 (pk char(32) primary key, col1 char(32), col2 varchar(40), col3 char(32), key (col1), key (col3), key (col2,col3), key (col1,col3))") - tk.MustExec("create table t2 (pk char(32) primary key, col1 varchar(100))") - tk.MustExec("create table t3 (pk char(32) primary key, keycol varchar(100), pad1 tinyint(1) default null, pad2 varchar(40), key (keycol,pad1,pad2))") + tk.MustExec("create table t1 (pk char(32) primary key nonclustered, col1 char(32), col2 varchar(40), col3 char(32), key (col1), key (col3), key (col2,col3), key (col1,col3))") + tk.MustExec("create table t2 (pk char(32) primary key nonclustered, col1 varchar(100))") + tk.MustExec("create table t3 (pk char(32) primary key nonclustered, keycol varchar(100), pad1 tinyint(1) default null, pad2 varchar(40), key (keycol,pad1,pad2))") var input []string var output []struct { @@ -4967,7 +4967,7 @@ func TestMultiColMaxOneRow(t *testing.T) { tk.MustExec("use test") tk.MustExec("drop table if exists t1,t2") tk.MustExec("create table t1(a int)") - tk.MustExec("create table t2(a int, b int, c int, primary key(a,b))") + tk.MustExec("create table t2(a int, b int, c int, primary key(a,b) nonclustered)") var input []string var output []struct { @@ -6525,7 +6525,7 @@ func TestAggPushToCopForCachedTable(t *testing.T) { oper_no varchar(12) DEFAULT NULL, modify_date datetime DEFAULT NULL, d_c_flag varchar(2) NOT NULL, - PRIMARY KEY (process_code,ctrl_class,d_c_flag));`) + PRIMARY KEY (process_code,ctrl_class,d_c_flag) NONCLUSTERED);`) tk.MustExec("insert into t32157 values ('GDEP0071', '05', '1', '10000', '2016-06-29 00:00:00', 'C')") tk.MustExec("insert into t32157 values ('GDEP0071', '05', '0', '0000', '2016-06-01 00:00:00', 'D')") tk.MustExec("alter table t32157 cache") diff --git a/planner/core/partition_pruner_test.go b/planner/core/partition_pruner_test.go index fffef54373bd8..75350e7d3a1ad 100644 --- a/planner/core/partition_pruner_test.go +++ b/planner/core/partition_pruner_test.go @@ -78,7 +78,7 @@ func TestRangeColumnPartitionPruningForIn(t *testing.T) { tk.MustExec(`CREATE TABLE t1 ( id bigint(20) NOT NULL AUTO_INCREMENT, dt date, - PRIMARY KEY (id,dt)) + PRIMARY KEY (id,dt) NONCLUSTERED) PARTITION BY RANGE COLUMNS(dt) ( PARTITION p20201125 VALUES LESS THAN ("20201126"), PARTITION p20201126 VALUES LESS THAN ("20201127"), diff --git a/planner/core/plan_test.go b/planner/core/plan_test.go index 54b6d0ad3e381..8f8c5342794ec 100644 --- a/planner/core/plan_test.go +++ b/planner/core/plan_test.go @@ -314,7 +314,7 @@ func TestNormalizedDigest(t *testing.T) { ol_supply_w_id int(11) DEFAULT NULL, ol_quantity int(11) DEFAULT NULL, ol_dist_info char(24) DEFAULT NULL, - PRIMARY KEY ( ol_w_id , ol_d_id , ol_o_id , ol_number ) + PRIMARY KEY ( ol_w_id , ol_d_id , ol_o_id , ol_number ) NONCLUSTERED );`) tk.MustExec(`CREATE TABLE bmsql_district ( d_w_id int(11) NOT NULL, @@ -328,7 +328,7 @@ func TestNormalizedDigest(t *testing.T) { d_city varchar(20) DEFAULT NULL, d_state char(2) DEFAULT NULL, d_zip char(9) DEFAULT NULL, - PRIMARY KEY ( d_w_id , d_id ) + PRIMARY KEY ( d_w_id , d_id ) NONCLUSTERED );`) tk.MustExec(`CREATE TABLE bmsql_stock ( s_w_id int(11) NOT NULL, @@ -348,7 +348,7 @@ func TestNormalizedDigest(t *testing.T) { s_dist_08 char(24) DEFAULT NULL, s_dist_09 char(24) DEFAULT NULL, s_dist_10 char(24) DEFAULT NULL, - PRIMARY KEY ( s_w_id , s_i_id ) + PRIMARY KEY ( s_w_id , s_i_id ) NONCLUSTERED );`) err := failpoint.Enable("github.com/pingcap/tidb/planner/mockRandomPlanID", "return(true)") diff --git a/planner/core/point_get_plan_test.go b/planner/core/point_get_plan_test.go index 27be9babce05a..1ff0346eecf77 100644 --- a/planner/core/point_get_plan_test.go +++ b/planner/core/point_get_plan_test.go @@ -959,7 +959,7 @@ func TestIssue26638(t *testing.T) { tk.MustQuery("execute stmt1 using @c;").Check(testkit.Rows()) tk.MustQuery("execute stmt2 using @c, @d;").Check(testkit.Rows()) tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t2(a float, b float, c float, primary key(a, b, c));") + tk.MustExec("create table t2(a float, b float, c float, primary key(a, b, c) nonclustered);") tk.MustExec("insert into t2 values(-1, 0, 1), (-1.1, 0, 1.1), (-1.56018e38, -1.96716e38, 9.46347e37), (0, 1, 2);") tk.MustQuery("explain format='brief' select * from t2 where (a, b, c) in ((-1.1, 0, 1.1), (-1.56018e38, -1.96716e38, 9.46347e37));").Check(testkit.Rows("TableDual 0.00 root rows:0")) tk.MustQuery("select * from t2 where (a, b, c) in ((-1.1, 0, 1.1), (-1.56018e38, -1.96716e38, 9.46347e37), (-1, 0, 1));").Check(testkit.Rows("-1 0 1")) @@ -976,7 +976,7 @@ func TestIssue23511(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("CREATE TABLE `t1` (`COL1` bit(11) NOT NULL,PRIMARY KEY (`COL1`));") + tk.MustExec("CREATE TABLE `t1` (`COL1` bit(11) NOT NULL,PRIMARY KEY (`COL1`) NONCLUSTERED);") tk.MustExec("CREATE TABLE `t2` (`COL1` bit(11) NOT NULL);") tk.MustExec("insert into t1 values(b'00000111001'), (b'00000000000');") tk.MustExec("insert into t2 values(b'00000111001');") diff --git a/planner/funcdep/extract_fd_test.go b/planner/funcdep/extract_fd_test.go index 7e5dca8daf44c..f574eba78a872 100644 --- a/planner/funcdep/extract_fd_test.go +++ b/planner/funcdep/extract_fd_test.go @@ -342,7 +342,7 @@ func TestFDSet_MakeOuterJoin(t *testing.T) { tk.MustExec("set @@session.tidb_enable_new_only_full_group_by_check = 'on';") tk.MustExec("CREATE TABLE X (a INT PRIMARY KEY, b INT, c INT, d INT, e INT)") tk.MustExec("CREATE UNIQUE INDEX uni ON X (b, c)") - tk.MustExec("CREATE TABLE Y (m INT, n INT, p INT, q INT, PRIMARY KEY (m, n))") + tk.MustExec("CREATE TABLE Y (m INT, n INT, p INT, q INT, PRIMARY KEY (m, n) NONCLUSTERED)") tests := []struct { sql string diff --git a/session/bootstrap_test.go b/session/bootstrap_test.go index 4a92eca674813..53076c82a0d85 100644 --- a/session/bootstrap_test.go +++ b/session/bootstrap_test.go @@ -625,8 +625,8 @@ func TestUpgradeClusteredIndexDefaultValue(t *testing.T) { require.NoError(t, r.Next(context.Background(), req)) require.Equal(t, 1, req.NumRows()) row := req.GetRow(0) - require.Equal(t, "INT_ONLY", row.GetString(0)) - require.Equal(t, "INT_ONLY", row.GetString(1)) + require.Equal(t, "ON", row.GetString(0)) + require.Equal(t, "ON", row.GetString(1)) domV68.Close() } diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 0cce50a063e9d..c032824110f1d 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1661,7 +1661,7 @@ var defaultSysVars = []*SysVar{ s.AllowAutoRandExplicitInsert = TiDBOptOn(val) return nil }}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableClusteredIndex, Value: IntOnly, Type: TypeEnum, PossibleValues: []string{Off, On, IntOnly}, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableClusteredIndex, Value: On, Type: TypeEnum, PossibleValues: []string{Off, On, IntOnly}, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { if normalizedValue == IntOnly { vars.StmtCtx.AppendWarning(errWarnDeprecatedSyntax.FastGenByArgs(normalizedValue, fmt.Sprintf("'%s' or '%s'", On, Off))) }