*: information_schema.tables add TIDB_PK_TYPE column for clustered index (#19642)
Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
This commit is contained in:
@ -436,7 +436,7 @@ func (e *memtableRetriever) setDataFromTables(ctx sessionctx.Context, schemas []
|
||||
if checker != nil && !checker.RequestVerification(ctx.GetSessionVars().ActiveRoles, schema.Name.L, table.Name.L, "", mysql.AllPrivMask) {
|
||||
continue
|
||||
}
|
||||
|
||||
pkType := "NON-CLUSTERED"
|
||||
if !table.IsView() {
|
||||
if table.GetPartitionInfo() != nil {
|
||||
createOptions = "partitioned"
|
||||
@ -474,6 +474,11 @@ func (e *memtableRetriever) setDataFromTables(ctx sessionctx.Context, schemas []
|
||||
default:
|
||||
tableType = "BASE TABLE"
|
||||
}
|
||||
if table.PKIsHandle {
|
||||
pkType = "INT CLUSTERED"
|
||||
} else if table.IsCommonHandle {
|
||||
pkType = "COMMON CLUSTERED"
|
||||
}
|
||||
shardingInfo := infoschema.GetShardingInfo(schema, table)
|
||||
record := types.MakeDatums(
|
||||
infoschema.CatalogVal, // TABLE_CATALOG
|
||||
@ -499,6 +504,7 @@ func (e *memtableRetriever) setDataFromTables(ctx sessionctx.Context, schemas []
|
||||
table.Comment, // TABLE_COMMENT
|
||||
table.ID, // TIDB_TABLE_ID
|
||||
shardingInfo, // TIDB_ROW_ID_SHARDING_INFO
|
||||
pkType, // TIDB_PK_TYPE
|
||||
)
|
||||
rows = append(rows, record)
|
||||
} else {
|
||||
@ -526,6 +532,7 @@ func (e *memtableRetriever) setDataFromTables(ctx sessionctx.Context, schemas []
|
||||
"VIEW", // TABLE_COMMENT
|
||||
table.ID, // TIDB_TABLE_ID
|
||||
nil, // TIDB_ROW_ID_SHARDING_INFO
|
||||
pkType, // TIDB_PK_TYPE
|
||||
)
|
||||
rows = append(rows, record)
|
||||
}
|
||||
|
||||
@ -822,3 +822,16 @@ func (s *testInfoschemaTableSuite) TestTiFlashSystemTables(c *C) {
|
||||
err = tk.QueryToErr("select * from information_schema.TIFLASH_SEGMENTS;")
|
||||
c.Assert(err.Error(), Equals, "Etcd addrs not found")
|
||||
}
|
||||
|
||||
func (s *testInfoschemaTableSuite) TestTablesPKType(c *C) {
|
||||
tk := testkit.NewTestKitWithInit(c, s.store)
|
||||
tk.MustExec("create table t_int (a int primary key, b int)")
|
||||
tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_int'").Check(testkit.Rows("INT CLUSTERED"))
|
||||
tk.MustExec("set @@tidb_enable_clustered_index = 0")
|
||||
tk.MustExec("create table t_implicit (a varchar(64) primary key, b int)")
|
||||
tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_implicit'").Check(testkit.Rows("NON-CLUSTERED"))
|
||||
tk.MustExec("set @@tidb_enable_clustered_index = 1")
|
||||
tk.MustExec("create table t_common (a varchar(64) primary key, b int)")
|
||||
tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'test' and table_name = 't_common'").Check(testkit.Rows("COMMON CLUSTERED"))
|
||||
tk.MustQuery("SELECT TIDB_PK_TYPE FROM information_schema.tables where table_schema = 'INFORMATION_SCHEMA' and table_name = 'TABLES'").Check(testkit.Rows("NON-CLUSTERED"))
|
||||
}
|
||||
|
||||
@ -304,6 +304,7 @@ var tablesCols = []columnInfo{
|
||||
{name: "TABLE_COMMENT", tp: mysql.TypeVarchar, size: 2048},
|
||||
{name: "TIDB_TABLE_ID", tp: mysql.TypeLonglong, size: 21},
|
||||
{name: "TIDB_ROW_ID_SHARDING_INFO", tp: mysql.TypeVarchar, size: 255},
|
||||
{name: "TIDB_PK_TYPE", tp: mysql.TypeVarchar, size: 64},
|
||||
}
|
||||
|
||||
// See: http://dev.mysql.com/doc/refman/5.7/en/columns-table.html
|
||||
|
||||
Reference in New Issue
Block a user