Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschema: fix sub_part in information_schema.statistics table (#55814) #56210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ func (e *memtableRetriever) setDataForStatisticsInTable(schema model.CIStr, tabl
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
Expand All @@ -465,7 +470,7 @@ func (e *memtableRetriever) setDataForStatisticsInTable(schema model.CIStr, tabl
colName, // COLUMN_NAME
"A", // COLLATION
0, // CARDINALITY
nil, // SUB_PART
subPart, // SUB_PART
nil, // PACKED
nullable, // NULLABLE
"BTREE", // INDEX_TYPE
Expand Down
6 changes: 6 additions & 0 deletions tests/integrationtest/r/executor/infoschema_reader.result
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,9 @@ sleep(1)
select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t' AND TABLE_SCHEMA='executor__infoschema_reader';
table_rows avg_row_length data_length index_length
3 18 54 6
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
6 changes: 6 additions & 0 deletions tests/integrationtest/t/executor/infoschema_reader.test
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,9 @@ insert into t(a, b, c) values(1, 2, 'c'), (7, 3, 'd'), (12, 4, 'e');
analyze table t;
select sleep(1);
select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t' AND TABLE_SCHEMA='executor__infoschema_reader';


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';