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

planner/core: filter temp tables for information_schema #55209

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions pkg/planner/core/memtable_infoschema_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ func findNameAndAppendToTableMap(
return errors.Trace(err)
}
tblInfo := tbl.Meta()
if tblInfo.TempTableType != model.TempTableNone {
continue
}
tables[tblInfo.ID] = tblInfo
}
return nil
Expand All @@ -345,12 +348,15 @@ func findTablesByID(
if !ok {
continue
}
tblInfo := tbl.Meta()
if tblInfo.TempTableType != model.TempTableNone {
continue
}
if len(tableNames) > 0 {
if _, ok := tblNameMap[tbl.Meta().Name.L]; ok {
if _, ok := tblNameMap[tblInfo.Name.L]; ok {
continue
}
}
tblInfo := tbl.Meta()
tables[tblInfo.ID] = tblInfo
}
}
Expand Down Expand Up @@ -402,6 +408,9 @@ func findTableAndSchemaByName(
return nil, nil, errors.Trace(err)
}
tblInfo := tbl.Meta()
if tblInfo.TempTableType != model.TempTableNone {
continue
}
tableMap[tblInfo.ID] = schemaAndTable{s, tblInfo}
}
}
Expand Down
16 changes: 14 additions & 2 deletions tests/integrationtest/r/infoschema/infoschema.result
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SELECT count(*) FROM information_schema.TABLES WHERE (TABLE_NAME = 't1' or TABLE
count(*)
2
drop table mysql.t1, mysql.t2, mysql.t3;
drop table test.t1;
create table infoschema__infoschema.t4(a int, INDEX i1 (a));
create table infoschema__infoschema.t5(a int, INDEX i1 (a));
insert into infoschema__infoschema.t4 values(1);
Expand Down Expand Up @@ -177,12 +178,12 @@ select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics
TABLE_SCHEMA TABLE_NAME COLUMN_NAME
infoschema__infoschema t1 a
infoschema__infoschema t1 b
test t1 c1
test t1 c2
select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics where table_name = 't2' and table_schema = 'infoschema__infoschema_2';
TABLE_SCHEMA TABLE_NAME COLUMN_NAME
infoschema__infoschema_2 t2 b
infoschema__infoschema_2 t2 a
drop table infoschema__infoschema.t1;
drop table infoschema__infoschema_2.t2;
use infoschema__infoschema;
select SCHEMA_NAME from information_schema.schemata where schema_name = 'infoschema__infoschema_2';
SCHEMA_NAME
Expand All @@ -203,3 +204,14 @@ def db1 PRIMARY def db1 table1 id 1 1 NULL NULL NULL
def db1 fk def db1 table2 id 1 1 db1 table1 id
drop database db1;
drop database db2;
create temporary table temp_table (a int, index idx(a));
select count(1) from information_schema.tables where table_schema = 'infoschema__infoschema';
count(1)
0
select count(1) from information_schema.tables where table_name = 'temp_table';
count(1)
0
select count(1) from information_schema.statistics where table_name = 'temp_table';
count(1)
0
drop table temp_table;
10 changes: 10 additions & 0 deletions tests/integrationtest/t/infoschema/infoschema.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ desc format='brief' SELECT count(*) FROM information_schema.TABLES WHERE TABLE_S
SELECT count(*) FROM information_schema.TABLES WHERE TABLE_NAME in ('t1', 't2') and TABLE_SCHEMA = 'mysql';
SELECT count(*) FROM information_schema.TABLES WHERE (TABLE_NAME = 't1' or TABLE_NAME = 't2') and TABLE_SCHEMA = 'mysql';
drop table mysql.t1, mysql.t2, mysql.t3;
drop table test.t1;

# TestTablesColumn
create table infoschema__infoschema.t4(a int, INDEX i1 (a));
Expand Down Expand Up @@ -86,6 +87,8 @@ insert into t2 values (1, 'aaa');
select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics where table_schema = 'infoschema__infoschema';
select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics where table_name = 't1';
select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics where table_name = 't2' and table_schema = 'infoschema__infoschema_2';
drop table infoschema__infoschema.t1;
drop table infoschema__infoschema_2.t2;

# TestSchemataColumns
use infoschema__infoschema;
Expand All @@ -103,3 +106,10 @@ create table db2.table2(id int not null, FOREIGN KEY fk(id) REFERENCES table1(id
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = 'db1' order by TABLE_NAME;
drop database db1;
drop database db2;

# TestTemporaryTableShouldNotAppear
create temporary table temp_table (a int, index idx(a));
select count(1) from information_schema.tables where table_schema = 'infoschema__infoschema';
select count(1) from information_schema.tables where table_name = 'temp_table';
select count(1) from information_schema.statistics where table_name = 'temp_table';
drop table temp_table;