diff options
author | unknown <anozdrin/alik@ibm.opbmk> | 2007-08-31 20:42:14 +0400 |
---|---|---|
committer | unknown <anozdrin/alik@ibm.opbmk> | 2007-08-31 20:42:14 +0400 |
commit | 7e0ad09edff587dadc3e9855fc81e1b7de8f2199 (patch) | |
tree | 38c6a445d870a736939fb8fa36bb8dc40fb08e20 /sql/sql_class.h | |
parent | 3edb630197ae42353905325e9d1c8e78d329c23a (diff) | |
download | mariadb-git-7e0ad09edff587dadc3e9855fc81e1b7de8f2199.tar.gz |
Fix for BUG#25843: changing default database between PREPARE and EXECUTE
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().
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r-- | sql/sql_class.h | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h index abed643f822..80f73945465 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -593,6 +593,22 @@ public: uint32 query_length; // current query length Server_side_cursor *cursor; + /** + Name of the current (default) database. + + If there is the current (default) database, "db" contains its name. If + there is no current (default) database, "db" is NULL and "db_length" is + 0. In other words, "db", "db_length" must either be NULL, or contain a + valid database name. + + @note this attribute is set and alloced by the slave SQL thread (for + the THD of that thread); that thread is (and must remain, for now) the + only responsible for freeing this member. + */ + + char *db; + uint db_length; + public: /* This constructor is called for backup statements */ @@ -1024,18 +1040,21 @@ public: */ char *thread_stack; + /** + Currently selected catalog. + */ + char *catalog; + /* - db - currently selected database - catalog - currently selected catalog - WARNING: some members of THD (currently 'db', 'catalog' and 'query') are - set and alloced by the slave SQL thread (for the THD of that thread); that - thread is (and must remain, for now) the only responsible for freeing these - 3 members. If you add members here, and you add code to set them in - replication, don't forget to free_them_and_set_them_to_0 in replication - properly. For details see the 'err:' label of the handle_slave_sql() - in sql/slave.cc. - */ - char *db, *catalog; + WARNING: some members of THD (currently 'Statement::db', + 'catalog' and 'query') are set and alloced by the slave SQL thread + (for the THD of that thread); that thread is (and must remain, for now) + the only responsible for freeing these 3 members. If you add members + here, and you add code to set them in replication, don't forget to + free_them_and_set_them_to_0 in replication properly. For details see + the 'err:' label of the handle_slave_sql() in sql/slave.cc. + */ + Security_context main_security_ctx; Security_context *security_ctx; @@ -1390,7 +1409,6 @@ public: uint tmp_table, global_read_lock; uint server_status,open_options; enum enum_thread_type system_thread; - uint db_length; uint select_number; //number of select (used for EXPLAIN) /* variables.transaction_isolation is reset to this after each commit */ enum_tx_isolation session_tx_isolation; @@ -1814,11 +1832,10 @@ public: no current database selected (in addition to the error message set by malloc). - @note This operation just sets {thd->db, thd->db_length}. Switching the - current database usually involves other actions, like switching other - database attributes including security context. In the future, this - operation will be made private and more convenient interface will be - provided. + @note This operation just sets {db, db_length}. Switching the current + database usually involves other actions, like switching other database + attributes including security context. In the future, this operation + will be made private and more convenient interface will be provided. @return Operation status @retval FALSE Success @@ -1844,11 +1861,10 @@ public: @param new_db a pointer to the new database name. @param new_db_len length of the new database name. - @note This operation just sets {thd->db, thd->db_length}. Switching the - current database usually involves other actions, like switching other - database attributes including security context. In the future, this - operation will be made private and more convenient interface will be - provided. + @note This operation just sets {db, db_length}. Switching the current + database usually involves other actions, like switching other database + attributes including security context. In the future, this operation + will be made private and more convenient interface will be provided. */ void reset_db(char *new_db, size_t new_db_len) { |