From: Date: July 5 2007 12:20am Subject: bk commit into 5.0 tree (kostja:1.2514) BUG#28551 List-Archive: http://lists.mysql.com/commits/30340 X-Bug: 28551 Message-Id: <20070704222036.59B3728001@vajra.local> Below is the list of changes that have just been committed into a local 5.0 repository of kostja. When kostja does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-07-05 02:20:32+04:00, kostja@bodhi.(none) +4 -0 A fix and a teset case for Bug#28551 The warning 'No database selected' is reported when calling stored procedures Remove the offending warning introduced by the fix for Bug 25082 This minimal patch relies on the intrinsic knowledge of the fact that mysql_change_db is never called with 'force_switch' set to TRUE when such a warning may be needed: * every stored routine belongs to a database (unlike, e.g., a user defined function, which does not), so if we're activating the database of a stored routine, it can never be NULL. Therefore, this branch is never called for activation. * if we're restoring the 'old' current database after routine execution is complete, we should not issue a warning, since it's OK to call a routine without having previously selected the current database. TODO: 'force_switch' is an ambiguous flag, since we do not actually have to 'force' the switch in case of stored routines at all. When we activate the routine's database, we should perform all the checks as in case of 'use db', and so we already do (in this case 'force_switch' is unused). When we load a routine into cache, we should not use mysql_change_db at all, since there it's enough to call thd->reset_db(). We do it this way for triggers, but code for routines is different (wrongly). TODO: bugs are lurking in replication, since it bypasses mysql_change_db and calls thd->[re_]set_db to set the current database. The latter does not change thd->db_charset, thd->sctx->db_access and thd->variables.collation_database (and this may have nasty side effects). These todo items are to be addressed in a separate patch, if at all. mysql-test/r/sp.result@stripped, 2007-07-05 02:20:30+04:00, kostja@bodhi.(none) +7 -0 Update results (Bug#28551) mysql-test/t/sp.test@stripped, 2007-07-05 02:20:30+04:00, kostja@bodhi.(none) +12 -0 Add a test case (Bug#28551) sql/sp.cc@stripped, 2007-07-05 02:20:30+04:00, kostja@bodhi.(none) +4 -8 Remove an obsolete comment. Replace a check with an assert. sql/sql_db.cc@stripped, 2007-07-05 02:20:30+04:00, kostja@bodhi.(none) +4 -4 Remove the offending warning introduced by the fix for Bug 25082 This minimal patch relies on the intrinsic knowledge of the fact that mysql_change_db is never called with 'force_switch' set to TRUE when such a warning may be needed. diff -Nrup a/mysql-test/r/sp.result b/mysql-test/r/sp.result --- a/mysql-test/r/sp.result 2007-06-07 11:07:38 +04:00 +++ b/mysql-test/r/sp.result 2007-07-05 02:20:30 +04:00 @@ -6176,4 +6176,11 @@ v1 CREATE ALGORITHM=UNDEFINED DEFINER=`r DROP VIEW v1; DROP FUNCTION metered; DROP TABLE t1; +drop database if exists mysqltest_db1; +create database mysqltest_db1; +create procedure mysqltest_db1.sp_bug28551() begin end; +call mysqltest_db1.sp_bug28551(); +show warnings; +Level Code Message +drop database mysqltest_db1; End of 5.0 tests diff -Nrup a/mysql-test/t/sp.test b/mysql-test/t/sp.test --- a/mysql-test/t/sp.test 2007-06-02 02:42:03 +04:00 +++ b/mysql-test/t/sp.test 2007-07-05 02:20:30 +04:00 @@ -7130,5 +7130,17 @@ DROP VIEW v1; DROP FUNCTION metered; DROP TABLE t1; +# +# Bug#28551 "The warning 'No database selected' is reported when calling +# stored procedures" +# +--disable_warnings +drop database if exists mysqltest_db1; +--enable_warnings +create database mysqltest_db1; +create procedure mysqltest_db1.sp_bug28551() begin end; +call mysqltest_db1.sp_bug28551(); +show warnings; +drop database mysqltest_db1; --echo End of 5.0 tests diff -Nrup a/sql/sp.cc b/sql/sp.cc --- a/sql/sp.cc 2007-06-19 01:54:33 +04:00 +++ b/sql/sp.cc 2007-07-05 02:20:30 +04:00 @@ -1873,15 +1873,11 @@ sp_use_new_db(THD *thd, LEX_STRING new_d DBUG_PRINT("enter", ("newdb: %s", new_db.str)); /* - Set new_db to an empty string if it's NULL, because mysql_change_db - requires a non-NULL argument. - new_db.str can be NULL only if we're restoring the old database after - execution of a stored procedure and there were no current database - selected. The stored procedure itself must always have its database - initialized. + A stored routine always belongs to some database. The + old database (old_db) might be NULL, but to restore the + old database we will use mysql_change_db. */ - if (new_db.str == NULL) - new_db.str= empty_c_string; + DBUG_ASSERT(new_db.str && new_db.length); if (thd->db) { diff -Nrup a/sql/sql_db.cc b/sql/sql_db.cc --- a/sql/sql_db.cc 2007-04-03 15:11:32 +04:00 +++ b/sql/sql_db.cc 2007-07-05 02:20:30 +04:00 @@ -1240,10 +1240,10 @@ bool mysql_change_db(THD *thd, const LEX { if (force_switch) { - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, - ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR)); - - /* Change db to NULL. */ + /* + This can only happen when we restore the old db in THD after + execution of a routine is complete. Change db to NULL. + */ mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server);