• Sergey Glukhov's avatar
    Bug#11747970 34660: CRASH WHEN FEDERATED TABLE LOSES CONNECTION DURING INSERT ... SELECT · 14dc91ff
    Sergey Glukhov authored
    Problematic query:
    insert ignore into `t1_federated` (`c1`) select `c1` from  `t1_local` a
    where not exists (select 1 from `t1_federated` b where a.c1 = b.c1);
    When this query is killed in another connection it could lead to crash.
    The problem is follwing:
    An attempt to obtain table statistics for subselect table in killed query
    fails with an error. So JOIN::optimize() for subquery is failed but
    it does not prevent further subquery evaluation.
    At the first subquery execution JOIN::optimize() is called
    (see subselect_single_select_engine::exec()) and fails with
    an error. 'executed' flag is set to TRUE and it prevents
    further subquery evaluation. At the second call
    JOIN::optimize() does not happen as 'JOIN::optimized' is TRUE
    and in case of uncacheable subquery the 'executed' flag is set
    to FALSE before subquery evaluation. So we loose 'optimize stage'
    error indication (see subselect_single_select_engine::exec()).
    In other words 'executed' flag is used for two purposes, for
    error indication at JOIN::optimize() stage and for an
    indication of subquery execution. And it seems it's wrong
    as the flag could be reset.
    
    
    mysql-test/r/error_simulation.result:
      test case
    mysql-test/t/error_simulation.test:
      test case
    sql/item_subselect.cc:
      added new flag subselect_single_select_engine::optimize_error
      which is used for error detection which could happen at optimize
      stage.
    sql/item_subselect.h:
      added new flag subselect_single_select_engine::optimize_error
    sql/sql_select.cc:
      test case
    14dc91ff
item_subselect.h 18.2 KB