Skip to content

Commit

Permalink
test-case-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samba-rgb committed Sep 19, 2024
1 parent 2b9ae22 commit efbca50
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 122 deletions.
16 changes: 8 additions & 8 deletions pkg/ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func TestShowIndex(t *testing.T) {
}
rows := tk.ResultSetToResult(result, fmt.Sprintf("sql:%s", showIndexSQL))
got := fmt.Sprintf("%s", rows.Rows())
need := fmt.Sprintf("%s", testkit.Rows("t 0 PRIMARY 1 c1 A 0 <nil> <nil> BTREE YES <nil> NO"))
need := fmt.Sprintf("%s", testkit.Rows("t 0 PRIMARY 1 c1 A 0 <nil> <nil> BTREE YES <nil> NO NO"))
if got != need {
checkErr = fmt.Errorf("need %v, but got %v", need, got)
}
Expand All @@ -857,8 +857,8 @@ func TestShowIndex(t *testing.T) {
require.NoError(t, checkErr)

tk.MustQuery(showIndexSQL).Check(testkit.Rows(
"t 0 PRIMARY 1 c1 A 0 <nil> <nil> BTREE YES <nil> NO",
"t 1 c2 1 c2 A 0 <nil> <nil> YES BTREE YES <nil> NO",
"t 0 PRIMARY 1 c1 A 0 <nil> <nil> BTREE YES <nil> NO NO",
"t 1 c2 1 c2 A 0 <nil> <nil> YES BTREE YES <nil> NO NO",
))
testfailpoint.Disable(t, "github.com/pingcap/tidb/pkg/ddl/onJobUpdated")

Expand All @@ -875,26 +875,26 @@ func TestShowIndex(t *testing.T) {
partition p5 values less than (2015)
);`)
tk.MustExec("create index idx1 on tr (purchased);")
tk.MustQuery("show index from tr;").Check(testkit.Rows("tr 1 idx1 1 purchased A 0 <nil> <nil> YES BTREE YES <nil> NO"))
tk.MustQuery("show index from tr;").Check(testkit.Rows("tr 1 idx1 1 purchased A 0 <nil> <nil> YES BTREE YES <nil> NO NO"))

tk.MustExec("drop table if exists tr")
tk.MustExec("create table tr(id int primary key clustered, v int, key vv(v))")
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> YES", "tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO"))
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> YES NO", "tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO NO"))
tk.MustQuery("select key_name, clustered from information_schema.tidb_indexes where table_name = 'tr' order by key_name").Check(testkit.Rows("PRIMARY YES", "vv NO"))

tk.MustExec("drop table if exists tr")
tk.MustExec("create table tr(id int primary key nonclustered, v int, key vv(v))")
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO", "tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> NO"))
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO NO", "tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> NO NO"))
tk.MustQuery("select key_name, clustered from information_schema.tidb_indexes where table_name = 'tr' order by key_name").Check(testkit.Rows("PRIMARY NO", "vv NO"))

tk.MustExec("drop table if exists tr")
tk.MustExec("create table tr(id char(100) primary key clustered, v int, key vv(v))")
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO", "tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> YES"))
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO NO", "tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> YES NO"))
tk.MustQuery("select key_name, clustered from information_schema.tidb_indexes where table_name = 'tr' order by key_name").Check(testkit.Rows("PRIMARY YES", "vv NO"))

tk.MustExec("drop table if exists tr")
tk.MustExec("create table tr(id char(100) primary key nonclustered, v int, key vv(v))")
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO", "tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> NO"))
tk.MustQuery("show index from tr").Check(testkit.Rows("tr 1 vv 1 v A 0 <nil> <nil> YES BTREE YES <nil> NO NO", "tr 0 PRIMARY 1 id A 0 <nil> <nil> BTREE YES <nil> NO NO"))
tk.MustQuery("select key_name, clustered from information_schema.tidb_indexes where table_name = 'tr' order by key_name").Check(testkit.Rows("PRIMARY NO", "vv NO"))
}

Expand Down
14 changes: 2 additions & 12 deletions pkg/executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,6 @@ func (e *ShowExec) fetchShowIndex() error {
return e.tableAccessDenied("SELECT", tb.Meta().Name.O)
}

isGlobalIndex := "NO"

if tb.Meta().PKIsHandle {
var pkCol *table.Column
for _, col := range tb.Cols() {
Expand All @@ -807,14 +805,6 @@ func (e *ShowExec) fetchShowIndex() error {
if colStats != nil {
ndv = colStats.NDV
}

pi := tb.Meta().GetPartitionInfo()
isPartitioned := pi != nil && pi.Type != pmodel.PartitionTypeNone

if isPartitioned && e.Ctx().GetSessionVars().EnableGlobalIndex {
isGlobalIndex = "YES"
}

e.appendRow([]any{
tb.Meta().Name.O, // Table
0, // Non_unique
Expand All @@ -832,7 +822,7 @@ func (e *ShowExec) fetchShowIndex() error {
"YES", // Index_visible
nil, // Expression
"YES", // Clustered
isGlobalIndex, // Global_index
"NO", // Global_index
})
}
for _, idx := range tb.Indices() {
Expand All @@ -845,7 +835,7 @@ func (e *ShowExec) fetchShowIndex() error {
isClustered = "YES"
}

isGlobalIndex = "NO"
isGlobalIndex := "NO"
if idxInfo.Global {
isGlobalIndex = "YES"
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func TestShowIndex(t *testing.T) {
tk.MustExec("use test")
tk.MustExec("create table t(id int, abclmn int);")

defer tk.MustExec("drop table t;")
tk.MustExec("create index idx on t(abclmn);")
tk.MustQuery("show index from t").Check(testkit.Rows("t 1 idx 1 abclmn A 0 <nil> <nil> YES BTREE YES <nil> NO NO"))
}
Expand All @@ -121,7 +120,6 @@ func TestShowIndexWithGlobalIndex(t *testing.T) {

tk.MustExec("create table test_t1 (a int, b int) partition by range (b) (partition p0 values less than (10), partition p1 values less than (maxvalue));")

defer tk.MustExec("drop table test_t1;")
tk.MustExec("insert test_t1 values (1, 1);")
tk.MustExec("alter table test_t1 add unique index p_a (a) GLOBAL;")
tk.MustQuery("show index from test_t1").Check(testkit.Rows("test_t1 0 p_a 1 a A 0 <nil> <nil> YES BTREE YES <nil> NO YES"))
Expand Down
24 changes: 12 additions & 12 deletions pkg/executor/test/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,18 @@ func TestShow(t *testing.T) {
tk.MustExec(`create index expr_idx on show_index ((id*2+1))`)
testSQL = "SHOW index from show_index;"
tk.MustQuery(testSQL).Check(testkit.RowsWithSep("|",
"show_index|0|PRIMARY|1|id|A|0|<nil>|<nil>||BTREE| |YES|<nil>|YES",
"show_index|1|cIdx|1|c|A|0|<nil>|<nil>|YES|HASH||index_comment_for_cIdx|YES|<nil>|NO",
"show_index|1|idx1|1|id|A|0|<nil>|<nil>||HASH| |YES|<nil>|NO",
"show_index|1|idx2|1|id|A|0|<nil>|<nil>||BTREE||idx|YES|<nil>|NO",
"show_index|1|idx3|1|id|A|0|<nil>|<nil>||HASH||idx|YES|<nil>|NO",
"show_index|1|idx4|1|id|A|0|<nil>|<nil>||BTREE||idx|YES|<nil>|NO",
"show_index|1|idx5|1|id|A|0|<nil>|<nil>||BTREE||idx|YES|<nil>|NO",
"show_index|1|idx6|1|id|A|0|<nil>|<nil>||HASH| |YES|<nil>|NO",
"show_index|1|idx7|1|id|A|0|<nil>|<nil>||BTREE| |YES|<nil>|NO",
"show_index|1|idx8|1|id|A|0|<nil>|<nil>||BTREE| |YES|<nil>|NO",
"show_index|1|idx9|1|id|A|0|<nil>|<nil>||BTREE| |NO|<nil>|NO",
"show_index|1|expr_idx|1|NULL|A|0|<nil>|<nil>||BTREE| |YES|`id` * 2 + 1|NO",
"show_index|0|PRIMARY|1|id|A|0|<nil>|<nil>||BTREE| |YES|<nil>|YES|NO",
"show_index|1|cIdx|1|c|A|0|<nil>|<nil>|YES|HASH||index_comment_for_cIdx|YES|<nil>|NO|NO",
"show_index|1|idx1|1|id|A|0|<nil>|<nil>||HASH| |YES|<nil>|NO|NO",
"show_index|1|idx2|1|id|A|0|<nil>|<nil>||BTREE||idx|YES|<nil>|NO|NO",
"show_index|1|idx3|1|id|A|0|<nil>|<nil>||HASH||idx|YES|<nil>|NO|NO",
"show_index|1|idx4|1|id|A|0|<nil>|<nil>||BTREE||idx|YES|<nil>|NO|NO",
"show_index|1|idx5|1|id|A|0|<nil>|<nil>||BTREE||idx|YES|<nil>|NO|NO",
"show_index|1|idx6|1|id|A|0|<nil>|<nil>||HASH| |YES|<nil>|NO|NO",
"show_index|1|idx7|1|id|A|0|<nil>|<nil>||BTREE| |YES|<nil>|NO|NO",
"show_index|1|idx8|1|id|A|0|<nil>|<nil>||BTREE| |YES|<nil>|NO|NO",
"show_index|1|idx9|1|id|A|0|<nil>|<nil>||BTREE| |NO|<nil>|NO|NO",
"show_index|1|expr_idx|1|NULL|A|0|<nil>|<nil>||BTREE| |YES|`id` * 2 + 1|NO|NO",
))

// For show like with escape
Expand Down
6 changes: 3 additions & 3 deletions tests/integrationtest/r/ddl/multi_schema_change.result
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,22 @@ create table t (a int, b int, c int);
alter table t add index t(a), add index t(b);
Error 8200 (HY000): Unsupported operate same index 't'
show index from t;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
drop table if exists t;
create table t (a int, b int, c int);
alter table t add index t(a), drop column a;
Error 8200 (HY000): Unsupported operate same column 'a'
alter table t add index t(a, b), drop column a;
Error 8200 (HY000): Unsupported operate same column 'a'
show index from t;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
drop table if exists t;
create table t (a int, b int, c int);
insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 1);
alter table t add unique index i1(a), add unique index i2(a, b), add unique index i3(c);
Error 1062 (23000): Duplicate entry '1' for key 't.i3'
show index from t;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
alter table t add index i1(a), add index i2(a, b), add index i3(c);
drop table if exists t;
create table t (a int, b int, c int, index t(a));
Expand Down
4 changes: 2 additions & 2 deletions tests/integrationtest/r/ddl/primary_key_handle.result
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,5 @@ a b
alter table t6 drop primary key;
Error 3522 (HY000): A primary key index cannot be invisible
show index from t6 where Key_name='PRIMARY';
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
t6 0 PRIMARY 1 b A 0 NULL NULL BTREE YES NULL NO
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
t6 0 PRIMARY 1 b A 0 NULL NULL BTREE YES NULL NO NO
8 changes: 4 additions & 4 deletions tests/integrationtest/r/executor/executor.result
Original file line number Diff line number Diff line change
Expand Up @@ -3158,11 +3158,11 @@ InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YE
drop table if exists t;
create table t(a int primary key);
show index in t;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES NO
show index from t;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
t 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES NO
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB Executed_Gtid_Set
tidb-binlog 0
Expand Down
30 changes: 15 additions & 15 deletions tests/integrationtest/r/executor/show.result
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@ t CREATE TABLE `t` (
drop table if exists t2;
CREATE TABLE t2(a int primary key, b int unique, c int not null, unique index (c));
SHOW INDEX IN t2;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
t2 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES
t2 0 c 1 c A 0 NULL NULL BTREE YES NULL NO
t2 0 b 1 b A 0 NULL NULL YES BTREE YES NULL NO
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
t2 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES NO
t2 0 c 1 c A 0 NULL NULL BTREE YES NULL NO NO
t2 0 b 1 b A 0 NULL NULL YES BTREE YES NULL NO NO
CREATE INDEX t2_b_c_index ON t2 (b, c);
CREATE INDEX t2_c_b_index ON t2 (c, b);
SHOW INDEX IN t2;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
t2 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES
t2 0 c 1 c A 0 NULL NULL BTREE YES NULL NO
t2 0 b 1 b A 0 NULL NULL YES BTREE YES NULL NO
t2 1 t2_b_c_index 1 b A 0 NULL NULL YES BTREE YES NULL NO
t2 1 t2_b_c_index 2 c A 0 NULL NULL BTREE YES NULL NO
t2 1 t2_c_b_index 1 c A 0 NULL NULL BTREE YES NULL NO
t2 1 t2_c_b_index 2 b A 0 NULL NULL YES BTREE YES NULL NO
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
t2 0 PRIMARY 1 a A 0 NULL NULL BTREE YES NULL YES NO
t2 0 c 1 c A 0 NULL NULL BTREE YES NULL NO NO
t2 0 b 1 b A 0 NULL NULL YES BTREE YES NULL NO NO
t2 1 t2_b_c_index 1 b A 0 NULL NULL YES BTREE YES NULL NO NO
t2 1 t2_b_c_index 2 c A 0 NULL NULL BTREE YES NULL NO NO
t2 1 t2_c_b_index 1 c A 0 NULL NULL BTREE YES NULL NO NO
t2 1 t2_c_b_index 2 b A 0 NULL NULL YES BTREE YES NULL NO NO
drop table if exists test1;
CREATE TABLE `test1` (`id` int(0) NOT NULL,`num` int(0) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
create or replace view test1_v as(select id,row_number() over (partition by num) from test1);
Expand Down Expand Up @@ -895,9 +895,9 @@ xor
year
yearweek
SHOW INDEX FROM performance_schema.events_statements_summary_by_digest;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered
events_statements_summary_by_digest 0 SCHEMA_NAME 1 SCHEMA_NAME A 0 NULL NULL YES BTREE YES NULL NO
events_statements_summary_by_digest 0 SCHEMA_NAME 2 DIGEST A 0 NULL NULL YES BTREE YES NULL NO
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression Clustered Global
events_statements_summary_by_digest 0 SCHEMA_NAME 1 SCHEMA_NAME A 0 NULL NULL YES BTREE YES NULL NO NO
events_statements_summary_by_digest 0 SCHEMA_NAME 2 DIGEST A 0 NULL NULL YES BTREE YES NULL NO NO
drop table if exists t1, t3, t4, t5, t6, t7;
create global temporary table t1 (id int) on commit delete rows;
create global temporary table t3 (i int primary key, j int) on commit delete rows;
Expand Down
Loading

0 comments on commit efbca50

Please sign in to comment.