diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index 1894c57b60467..ae20ed6578bbb 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -472,6 +472,11 @@ func (e *memtableRetriever) setDataForStatisticsInTable( expression = tblCol.GeneratedExprString } + var subPart any + if key.Length != types.UnspecifiedLength { + subPart = key.Length + } + record := types.MakeDatums( infoschema.CatalogVal, // TABLE_CATALOG schema.O, // TABLE_SCHEMA @@ -483,7 +488,7 @@ func (e *memtableRetriever) setDataForStatisticsInTable( colName, // COLUMN_NAME "A", // COLLATION 0, // CARDINALITY - nil, // SUB_PART + subPart, // SUB_PART nil, // PACKED nullable, // NULLABLE "BTREE", // INDEX_TYPE diff --git a/tests/integrationtest/r/executor/infoschema_reader.result b/tests/integrationtest/r/executor/infoschema_reader.result index 4c193dd8780fd..9da5cdee9d0da 100644 --- a/tests/integrationtest/r/executor/infoschema_reader.result +++ b/tests/integrationtest/r/executor/infoschema_reader.result @@ -439,3 +439,9 @@ count(*) select count(table_name) from information_schema.tables where table_name = 't'; count(table_name) 1 +drop table if exists t; +create table t (c text); +alter table t add index idx_t (c(16)); +select SUB_PART from information_schema.statistics where TABLE_SCHEMA = 'executor__infoschema_reader' and TABLE_NAME = 't'; +SUB_PART +16 diff --git a/tests/integrationtest/t/executor/infoschema_reader.test b/tests/integrationtest/t/executor/infoschema_reader.test index 57afa0f441ca8..021a0ffd59324 100644 --- a/tests/integrationtest/t/executor/infoschema_reader.test +++ b/tests/integrationtest/t/executor/infoschema_reader.test @@ -314,4 +314,9 @@ select table_name, table_schema from information_schema.tables where table_name select table_name from information_schema.tables where table_name = 't'; explain format='brief' select table_name, table_schema from information_schema.tables; select count(*) from information_schema.tables where table_name = 't'; -select count(table_name) from information_schema.tables where table_name = 't'; \ No newline at end of file +select count(table_name) from information_schema.tables where table_name = 't'; + +drop table if exists t; +create table t (c text); +alter table t add index idx_t (c(16)); +select SUB_PART from information_schema.statistics where TABLE_SCHEMA = 'executor__infoschema_reader' and TABLE_NAME = 't';