Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sessionctx: enable clustered index by default #38447

Merged
merged 13 commits into from
Nov 4, 2022
1 change: 1 addition & 0 deletions cmd/explaintest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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" +
Expand Down
4 changes: 2 additions & 2 deletions ddl/index_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions executor/charset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 一二三", "一二三 一二三", "中文 中文"))
}
2 changes: 1 addition & 1 deletion executor/index_merge_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
6 changes: 3 additions & 3 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down
2 changes: 1 addition & 1 deletion executor/showtest/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)" +
Expand Down
2 changes: 1 addition & 1 deletion executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion planner/core/partition_pruner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions planner/core/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)")
Expand Down
4 changes: 2 additions & 2 deletions planner/core/point_get_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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');")
Expand Down
2 changes: 1 addition & 1 deletion planner/funcdep/extract_fd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down