Skip to content

Commit

Permalink
executor: add a new column is_global into `information_schema.tidb_…
Browse files Browse the repository at this point in the history
…indexes` table (#53345)

close #53342
  • Loading branch information
Defined2014 authored May 17, 2024
1 parent 335af25 commit f5ac93e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ func (e *memtableRetriever) setDataFromIndexes(ctx sessionctx.Context, schemas [
0, // INDEX_ID
"YES", // IS_VISIBLE
"YES", // CLUSTERED
0, // IS_GLOBAL
)
rows = append(rows, record)
}
Expand Down Expand Up @@ -1294,6 +1295,7 @@ func (e *memtableRetriever) setDataFromIndexes(ctx sessionctx.Context, schemas [
idxInfo.ID, // INDEX_ID
visible, // IS_VISIBLE
isClustered, // CLUSTERED
idxInfo.Global, // IS_GLOBAL
)
rows = append(rows, record)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ var tableTiDBIndexesCols = []columnInfo{
{name: "INDEX_ID", tp: mysql.TypeLonglong, size: 21},
{name: "IS_VISIBLE", tp: mysql.TypeVarchar, size: 64},
{name: "CLUSTERED", tp: mysql.TypeVarchar, size: 64},
{name: "IS_GLOBAL", tp: mysql.TypeLonglong, size: 21},
}

var slowQueryCols = []columnInfo{
Expand Down
10 changes: 5 additions & 5 deletions tests/integrationtest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ HashAgg 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#10
└─StreamAgg 8000.00 cop[tikv] group by:explain_easy.t2.c1,
└─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo
select * from information_schema.tidb_indexes where table_name='t4' and table_schema='explain_easy';
TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE CLUSTERED
explain_easy t4 0 PRIMARY 1 a NULL NULL 0 YES YES
explain_easy t4 1 idx 1 a NULL NULL 1 YES NO
explain_easy t4 1 idx 2 b NULL NULL 1 YES NO
explain_easy t4 1 expr_idx 1 NULL NULL `a` + `b` + 1 2 YES NO
TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE CLUSTERED IS_GLOBAL
explain_easy t4 0 PRIMARY 1 a NULL NULL 0 YES YES 0
explain_easy t4 1 idx 1 a NULL NULL 1 YES NO 0
explain_easy t4 1 idx 2 b NULL NULL 1 YES NO 0
explain_easy t4 1 expr_idx 1 NULL NULL `a` + `b` + 1 2 YES NO 0
explain format = 'brief' select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2;
id estRows task access object operator info
StreamAgg 1.00 root funcs:count(1)->Column#5
Expand Down
14 changes: 14 additions & 0 deletions tests/integrationtest/r/globalindex/information_schema.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set tidb_enable_global_index=true;
drop table if exists t;
CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
UNIQUE KEY `idx1` (`b`),
KEY `idx` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`a`) PARTITIONS 5;
select key_name, is_global from information_schema.tidb_indexes where table_name='t' and table_schema='globalindex__information_schema' order by key_name;
key_name is_global
idx 0
idx1 1
set tidb_enable_global_index=default;
15 changes: 15 additions & 0 deletions tests/integrationtest/t/globalindex/information_schema.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set tidb_enable_global_index=true;

drop table if exists t;
CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
UNIQUE KEY `idx1` (`b`),
KEY `idx` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`a`) PARTITIONS 5;

select key_name, is_global from information_schema.tidb_indexes where table_name='t' and table_schema='globalindex__information_schema' order by key_name;

set tidb_enable_global_index=default;

0 comments on commit f5ac93e

Please sign in to comment.