Skip to content
Permalink
Browse files

MDEV-8796 Delete with sub query with information_schema.TABLES delete…

…s too many rows

make_cond_for_info_schema() does preserve outer fields
  • Loading branch information...
vuvova committed Oct 7, 2015
1 parent 504802f commit c8d511293aae155210089b6de4143d11569af18d
Showing with 28 additions and 30 deletions.
  1. +12 −12 mysql-test/r/information_schema2.result
  2. +8 −11 mysql-test/t/information_schema2.test
  3. +8 −7 sql/sql_show.cc
@@ -6,15 +6,15 @@ select variable_name from information_schema.session_variables where variable_na
(select variable_name from information_schema.session_variables where variable_name = 'basedir');
variable_name
BASEDIR
create table t1 (a char);
insert t1 values ('a'),('t'),('z');
flush status;
select a, exists (select 1 from information_schema.columns where table_schema=concat('tes',a)) from t1;
a exists (select 1 from information_schema.columns where table_schema=concat('tes',a))
a 0
t 1
z 0
show status like 'created_tmp_tables';
Variable_name Value
Created_tmp_tables 38
drop table t1;
create table t1 (x int);
create table t2 (x int);
create table t3 (x int);
create table t4 AS select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE' ;
delete from t4 where table_name not in (select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE');
select * from t4;
table_name
t1
t2
t3
t4
drop table t1, t2, t3, t4;
@@ -8,15 +8,12 @@ select variable_name from information_schema.session_variables where variable_na
(select variable_name from information_schema.session_variables where variable_name = 'basedir');

#
# information_schema tables inside subqueries, they should not be re-populated
# (i_s.columns needs to scan i_s itself, creating a tmp table for every i_s
# table. if it's re-populated, it'll do that multiple times)
# MDEV-8796 Delete with sub query with information_schema.TABLES deletes too many rows
#
create table t1 (a char);
insert t1 values ('a'),('t'),('z');
flush status;
select a, exists (select 1 from information_schema.columns where table_schema=concat('tes',a)) from t1;
# fix the result in ps-protocol
--replace_result 39 38
show status like 'created_tmp_tables';
drop table t1;
create table t1 (x int);
create table t2 (x int);
create table t3 (x int);
create table t4 AS select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE' ;
delete from t4 where table_name not in (select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE');
select * from t4;
drop table t1, t2, t3, t4;
@@ -7730,13 +7730,14 @@ bool get_schema_tables_result(JOIN *join,
TABLE_LIST *table_list= tab->table->pos_in_table_list;
if (table_list->schema_table && thd->fill_information_schema_tables())
{
#if MYSQL_VERSION_ID > 100105
#error I_S tables only need to be re-populated if make_cond_for_info_schema() will preserve outer fields
bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
lex->current_select->master_unit()->item);
#else
#define is_subselect false
#endif
/*
I_S tables only need to be re-populated if make_cond_for_info_schema()
preserves outer fields
*/
bool is_subselect= &lex->unit != lex->current_select->master_unit() &&
lex->current_select->master_unit()->item &&
tab->select_cond &&
tab->select_cond->used_tables() & OUTER_REF_TABLE_BIT;

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

0 comments on commit c8d5112

Please sign in to comment.
You can’t perform that action at this time.