Skip to content

Commit

Permalink
infoschema: fix sub_part in information_schema.statistics table (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Sep 3, 2024
1 parent dd180de commit 0816166
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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 @@ -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
7 changes: 6 additions & 1 deletion tests/integrationtest/t/executor/infoschema_reader.test
Original file line number Diff line number Diff line change
Expand Up @@ -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';
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';

0 comments on commit 0816166

Please sign in to comment.