Skip to content

Commit

Permalink
executor, infoschema: display attribute visible in information_sche…
Browse files Browse the repository at this point in the history
…ma.tidb_indexes (#19202)
  • Loading branch information
wjhuang2016 authored Aug 19, 2020
1 parent bbc0502 commit 0e3bd55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ HashAgg_18 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#
└─IndexReader_73 10000.00 root index:IndexFullScan_72
└─IndexFullScan_72 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:true, stats:pseudo
select * from information_schema.tidb_indexes where table_name='t4';
TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID
test t4 0 PRIMARY 1 a NULL NULL 0
test t4 1 idx 1 a NULL NULL 1
test t4 1 idx 2 b NULL NULL 1
test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 2
TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID IS_VISIBLE
test t4 0 PRIMARY 1 a NULL NULL 0 YES
test t4 1 idx 1 a NULL NULL 1 YES
test t4 1 idx 2 b NULL NULL 1 YES
test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 2 YES
explain select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2;
id estRows task access object operator info
StreamAgg_13 1.00 root funcs:count(1)->Column#5
Expand Down
16 changes: 12 additions & 4 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (e *memtableRetriever) setDataForStatisticsInTable(schema *model.DBInfo, ta
"", // COMMENT
"", // INDEX_COMMENT
"YES", // IS_VISIBLE
"NULL", // Expression
nil, // Expression
)
rows = append(rows, record)
}
Expand Down Expand Up @@ -374,7 +374,8 @@ func (e *memtableRetriever) setDataForStatisticsInTable(schema *model.DBInfo, ta
}

colName := col.Name.O
expression := "NULL"
var expression interface{}
expression = nil
tblCol := table.Columns[col.Offset]
if tblCol.Hidden {
colName = "NULL"
Expand Down Expand Up @@ -769,8 +770,9 @@ func (e *memtableRetriever) setDataFromIndexes(ctx sessionctx.Context, schemas [
pkCol.Name.O, // COLUMN_NAME
nil, // SUB_PART
"", // INDEX_COMMENT
"NULL", // Expression
nil, // Expression
0, // INDEX_ID
"YES", // IS_VISIBLE
)
rows = append(rows, record)
}
Expand All @@ -788,12 +790,17 @@ func (e *memtableRetriever) setDataFromIndexes(ctx sessionctx.Context, schemas [
subPart = col.Length
}
colName := col.Name.O
expression := "NULL"
var expression interface{}
expression = nil
tblCol := tb.Columns[col.Offset]
if tblCol.Hidden {
colName = "NULL"
expression = fmt.Sprintf("(%s)", tblCol.GeneratedExprString)
}
visible := "YES"
if idxInfo.Invisible {
visible = "NO"
}
record := types.MakeDatums(
schema.Name.O, // TABLE_SCHEMA
tb.Name.O, // TABLE_NAME
Expand All @@ -805,6 +812,7 @@ func (e *memtableRetriever) setDataFromIndexes(ctx sessionctx.Context, schemas [
idxInfo.Comment, // INDEX_COMMENT
expression, // Expression
idxInfo.ID, // INDEX_ID
visible, // IS_VISIBLE
)
rows = append(rows, record)
}
Expand Down
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ var tableTiDBIndexesCols = []columnInfo{
{name: "INDEX_COMMENT", tp: mysql.TypeVarchar, size: 2048},
{name: "Expression", tp: mysql.TypeVarchar, size: 64},
{name: "INDEX_ID", tp: mysql.TypeLonglong, size: 21},
{name: "IS_VISIBLE", tp: mysql.TypeVarchar, size: 64},
}

var slowQueryCols = []columnInfo{
Expand Down

0 comments on commit 0e3bd55

Please sign in to comment.