Skip to content

Commit c8d5112

Browse files
committed
MDEV-8796 Delete with sub query with information_schema.TABLES deletes too many rows
make_cond_for_info_schema() does preserve outer fields
1 parent 504802f commit c8d5112

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

mysql-test/r/information_schema2.result

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ select variable_name from information_schema.session_variables where variable_na
66
(select variable_name from information_schema.session_variables where variable_name = 'basedir');
77
variable_name
88
BASEDIR
9-
create table t1 (a char);
10-
insert t1 values ('a'),('t'),('z');
11-
flush status;
12-
select a, exists (select 1 from information_schema.columns where table_schema=concat('tes',a)) from t1;
13-
a exists (select 1 from information_schema.columns where table_schema=concat('tes',a))
14-
a 0
15-
t 1
16-
z 0
17-
show status like 'created_tmp_tables';
18-
Variable_name Value
19-
Created_tmp_tables 38
20-
drop table t1;
9+
create table t1 (x int);
10+
create table t2 (x int);
11+
create table t3 (x int);
12+
create table t4 AS select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE' ;
13+
delete from t4 where table_name not in (select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE');
14+
select * from t4;
15+
table_name
16+
t1
17+
t2
18+
t3
19+
t4
20+
drop table t1, t2, t3, t4;

mysql-test/t/information_schema2.test

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ select variable_name from information_schema.session_variables where variable_na
88
(select variable_name from information_schema.session_variables where variable_name = 'basedir');
99

1010
#
11-
# information_schema tables inside subqueries, they should not be re-populated
12-
# (i_s.columns needs to scan i_s itself, creating a tmp table for every i_s
13-
# table. if it's re-populated, it'll do that multiple times)
11+
# MDEV-8796 Delete with sub query with information_schema.TABLES deletes too many rows
1412
#
15-
create table t1 (a char);
16-
insert t1 values ('a'),('t'),('z');
17-
flush status;
18-
select a, exists (select 1 from information_schema.columns where table_schema=concat('tes',a)) from t1;
19-
# fix the result in ps-protocol
20-
--replace_result 39 38
21-
show status like 'created_tmp_tables';
22-
drop table t1;
13+
create table t1 (x int);
14+
create table t2 (x int);
15+
create table t3 (x int);
16+
create table t4 AS select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE' ;
17+
delete from t4 where table_name not in (select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE');
18+
select * from t4;
19+
drop table t1, t2, t3, t4;

sql/sql_show.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7730,13 +7730,14 @@ bool get_schema_tables_result(JOIN *join,
77307730
TABLE_LIST *table_list= tab->table->pos_in_table_list;
77317731
if (table_list->schema_table && thd->fill_information_schema_tables())
77327732
{
7733-
#if MYSQL_VERSION_ID > 100105
7734-
#error I_S tables only need to be re-populated if make_cond_for_info_schema() will preserve outer fields
7735-
bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
7736-
lex->current_select->master_unit()->item);
7737-
#else
7738-
#define is_subselect false
7739-
#endif
7733+
/*
7734+
I_S tables only need to be re-populated if make_cond_for_info_schema()
7735+
preserves outer fields
7736+
*/
7737+
bool is_subselect= &lex->unit != lex->current_select->master_unit() &&
7738+
lex->current_select->master_unit()->item &&
7739+
tab->select_cond &&
7740+
tab->select_cond->used_tables() & OUTER_REF_TABLE_BIT;
77407741

77417742
/* A value of 0 indicates a dummy implementation */
77427743
if (table_list->schema_table->fill_table == 0)

0 commit comments

Comments
 (0)