• unknown's avatar
    Fix for BUG#25843: changing default database between PREPARE and EXECUTE · 87a05da8
    unknown authored
    of statement breaks binlog.
    
    There were two problems discovered by this bug:
    
      1. Default (current) database is not fixed at the creation time.
         That leads to wrong output of DATABASE() function.
    
      2. Database attributes (@@collation_database) are not fixed at
         the creation time. That leads to wrong resultset.
    
    Binlog breakage and Query Cache wrong output happened because of
    the first problem.
    
    The fix is to remember the current database at the PREPARE-time and
    set it each time at EXECUTE.
    
    
    mysql-test/include/query_cache_sql_prepare.inc:
      The first part of the test case for BUG#25843.
    mysql-test/r/query_cache_ps_no_prot.result:
      Update result file.
    mysql-test/r/query_cache_ps_ps_prot.result:
      Update result file.
    mysql-test/suite/rpl/r/rpl_ps.result:
      Update result file.
    mysql-test/suite/rpl/t/rpl_ps.test:
      The second part of the test case for BUG#25843.
    sql/mysql_priv.h:
      Added mysql_opt_change_db() prototype.
    sql/sp.cc:
      1. Polishing;
      2. sp_use_new_db() has been removed;
      3. Use mysql_opt_change_db() instead of sp_use_new_db().
    sql/sp.h:
      sp_use_new_db() has been removed.
      This function has nothing to do with a) sp and b) *new* database.
      It was merely "switch the current database if needed".
    sql/sp_head.cc:
      1. Polishing.
      2. Use mysql_opt_change_db() instead of sp_use_new_db().
    sql/sql_class.cc:
      Move THD::{db, db_length} into Statement.
    sql/sql_class.h:
      Move THD::{db, db_length} into Statement.
    sql/sql_db.cc:
      Introduce mysql_opt_change_db() as a replacement (and inspired by)
      sp_use_new_db().
    sql/sql_prepare.cc:
      1. Remember the current database in Prepared_statement::prepare().
      2. Switch/restore the current database in Prepared_statement::execute().
    87a05da8
sql_class.h 81.3 KB