planner/core: filter temp tables for information_schema (#55209)

close pingcap/tidb#55166
This commit is contained in:
tangenta
2024-08-06 23:51:40 +08:00
committed by GitHub
parent d940b7ddc2
commit 7d0abb96ea
3 changed files with 35 additions and 4 deletions

View File

@ -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
@ -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
}
}
@ -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}
}
}

View File

@ -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);
@ -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 a
infoschema__infoschema_2 t2 b
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
@ -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;

View File

@ -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));
@ -89,6 +90,8 @@ select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics
select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.statistics where table_name = 't1';
--sorted_result
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;
@ -106,3 +109,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;