Skip to content

Commit f3e153a

Browse files
authored
executor: filter on table_schema for INFORMATION_SCHEMA.KEY_COLUMN_USAGE table (#55162)
close #55156
1 parent ce45eff commit f3e153a

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

pkg/executor/infoschema_reader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,9 +1842,13 @@ func (e *memtableRetriever) setDataFromKeyColumnUsage(ctx context.Context, sctx
18421842
return nil
18431843
}
18441844
for _, schema := range schemas {
1845+
// `constraint_schema` and `table_schema` are always the same in MySQL.
18451846
if ok && extractor.Filter("constraint_schema", schema.L) {
18461847
continue
18471848
}
1849+
if ok && extractor.Filter("table_schema", schema.L) {
1850+
continue
1851+
}
18481852
tables, err := e.is.SchemaTableInfos(ctx, schema)
18491853
if err != nil {
18501854
return errors.Trace(err)

tests/integrationtest/r/infoschema/infoschema.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,15 @@ pt2 p2
159159
pt2 p3
160160
select TABLE_NAME, PARTITION_NAME from information_schema.partitions where table_name = 'pt0' and table_schema = 'infoschema__infoschema';
161161
TABLE_NAME PARTITION_NAME
162+
create database if not exists db1;
163+
create table db1.table1(id int not null primary key, cat_name varchar(255) not null, cat_description text);
164+
create table db1.table2(id int not null, FOREIGN KEY fk(id) REFERENCES table1(id) ON UPDATE CASCADE ON DELETE RESTRICT);
165+
create database if not exists db2;
166+
create table db2.table1(id int not null primary key, cat_name varchar(255) not null, cat_description text);
167+
create table db2.table2(id int not null, FOREIGN KEY fk(id) REFERENCES table1(id) ON UPDATE CASCADE ON DELETE RESTRICT);
168+
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = 'db1' order by TABLE_NAME;
169+
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME
170+
def db1 PRIMARY def db1 table1 id 1 1 NULL NULL NULL
171+
def db1 fk def db1 table2 id 1 1 db1 table1 id
172+
drop database db1;
173+
drop database db2;

tests/integrationtest/t/infoschema/infoschema.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@ select TABLE_NAME, PARTITION_NAME from information_schema.partitions where table
6969
select TABLE_NAME, PARTITION_NAME from information_schema.partitions where table_name = 'pt2' and table_schema = 'infoschema__infoschema';
7070
-- sorted_result
7171
select TABLE_NAME, PARTITION_NAME from information_schema.partitions where table_name = 'pt0' and table_schema = 'infoschema__infoschema';
72+
73+
# TestFilterKeyColumnUsageTable
74+
create database if not exists db1;
75+
create table db1.table1(id int not null primary key, cat_name varchar(255) not null, cat_description text);
76+
create table db1.table2(id int not null, FOREIGN KEY fk(id) REFERENCES table1(id) ON UPDATE CASCADE ON DELETE RESTRICT);
77+
create database if not exists db2;
78+
create table db2.table1(id int not null primary key, cat_name varchar(255) not null, cat_description text);
79+
create table db2.table2(id int not null, FOREIGN KEY fk(id) REFERENCES table1(id) ON UPDATE CASCADE ON DELETE RESTRICT);
80+
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = 'db1' order by TABLE_NAME;
81+
drop database db1;
82+
drop database db2;

0 commit comments

Comments
 (0)