#At file:///opt/local/work/trunk-runtime/ based on revid:kostja@stripped
3081 Konstantin Osipov 2010-07-16
Make open_and_lock_tables() close thread table in case it fails.
Remove the calls to close_thread_tables that are now unnecessary.
@ mysql-test/r/view.result
A harmless change in CHECK TABLE <view> status for a broken view.
If previously a failure to prelock all functions used in a view
would leave the connection in LTM_PRELOCKED mode, now we call
close_thread_tables() from open_and_lock_tables()
and leave prelocked mode, thus some check in mysql_admin_table() that
work only in prelocked/locked tables mode are no longer activated.
@ sql/event_db_repository.h
Function open_event_table() does not require an instance of Event_db_repository.
modified:
mysql-test/r/view.result
sql/event_db_repository.cc
sql/event_db_repository.h
sql/sp_head.cc
sql/sql_acl.cc
sql/sql_base.cc
sql/sql_parse.cc
sql/sql_plugin.cc
sql/sql_table.cc
=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result 2010-06-06 11:19:29 +0000
+++ b/mysql-test/r/view.result 2010-07-16 08:55:35 +0000
@@ -1955,15 +1955,15 @@ CHECK TABLE v1, v2, v3, v4, v5, v6;
Table Op Msg_type Msg_text
test.v1 check Error FUNCTION test.f1 does not exist
test.v1 check Error View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
-test.v1 check status Operation failed
+test.v1 check error Corrupt
test.v2 check status OK
test.v3 check Error FUNCTION test.f1 does not exist
test.v3 check Error View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
-test.v3 check status Operation failed
+test.v3 check error Corrupt
test.v4 check status OK
test.v5 check Error FUNCTION test.f1 does not exist
test.v5 check Error View 'test.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
-test.v5 check status Operation failed
+test.v5 check error Corrupt
test.v6 check status OK
create function f1 () returns int return (select max(col1) from t1);
DROP TABLE t1;
=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc 2010-03-31 14:05:33 +0000
+++ b/sql/event_db_repository.cc 2010-07-16 08:55:35 +0000
@@ -584,10 +584,7 @@ Event_db_repository::open_event_table(TH
tables.init_one_table("mysql", 5, "event", 5, "event", lock_type);
if (open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
- {
- close_thread_tables(thd);
DBUG_RETURN(TRUE);
- }
*table= tables.table;
tables.table->use_all_columns();
=== modified file 'sql/event_db_repository.h'
--- a/sql/event_db_repository.h 2007-08-15 15:08:44 +0000
+++ b/sql/event_db_repository.h 2010-07-16 08:55:35 +0000
@@ -91,7 +91,7 @@ public:
bool
load_named_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et);
- bool
+ static bool
open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
bool
=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc 2010-07-14 15:52:44 +0000
+++ b/sql/sp_head.cc 2010-07-16 08:55:35 +0000
@@ -2809,8 +2809,6 @@ sp_lex_keeper::reset_lex_and_exec_core(T
}
/*
- Sic: call close_thread_tables() even if
- exec_open_and_lock_tables() failed.
Call after unit->cleanup() to close open table
key read.
*/
=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc 2010-07-01 13:53:46 +0000
+++ b/sql/sql_acl.cc 2010-07-16 08:55:35 +0000
@@ -3163,7 +3163,6 @@ int mysql_table_grant(THD *thd, TABLE_LI
thd->lex->sql_command= backup.sql_command;
if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
{ // Should never happen
- close_thread_tables(thd); /* purecov: deadcode */
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
@@ -3389,7 +3388,6 @@ bool mysql_routine_grant(THD *thd, TABLE
if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
{ // Should never happen
- close_thread_tables(thd);
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
@@ -3544,7 +3542,6 @@ bool mysql_grant(THD *thd, const char *d
if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
{ // This should never happen
- close_thread_tables(thd); /* purecov: deadcode */
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
if (save_binlog_row_based)
@@ -3865,10 +3862,7 @@ static my_bool grant_reload_procs_priv(T
table.open_type= OT_BASE_ONLY;
if (open_and_lock_tables(thd, &table, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
- {
- close_thread_tables(thd);
DBUG_RETURN(TRUE);
- }
mysql_rwlock_wrlock(&LOCK_grant);
/* Save a copy of the current hash if we need to undo the grant load */
@@ -5241,7 +5235,6 @@ int open_grant_tables(THD *thd, TABLE_LI
if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
{ // This should never happen
- close_thread_tables(thd);
DBUG_RETURN(-1);
}
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2010-07-13 08:39:24 +0000
+++ b/sql/sql_base.cc 2010-07-16 08:55:35 +0000
@@ -1597,7 +1597,7 @@ void close_thread_tables(THD *thd)
function or trigger (i.e. statement transaction is already active and
does not belong to statement for which we do close_thread_tables()).
TODO: This should be fixed in later releases.
- */
+ */
if (!(thd->state_flags & Open_tables_state::BACKUPS_AVAIL))
{
thd->stmt_da->can_overwrite_status= TRUE;
@@ -5477,7 +5477,7 @@ bool open_and_lock_tables(THD *thd, TABL
DBUG_PRINT("enter", ("derived handling: %d", derived));
if (open_tables(thd, &tables, &counter, flags, prelocking_strategy))
- DBUG_RETURN(TRUE);
+ goto err;
DBUG_EXECUTE_IF("sleep_open_and_lock_after_open", {
const char *old_proc_info= thd->proc_info;
@@ -5486,15 +5486,18 @@ bool open_and_lock_tables(THD *thd, TABL
thd->proc_info= old_proc_info;});
if (lock_tables(thd, tables, counter, flags))
- DBUG_RETURN(TRUE);
+ goto err;
if (derived &&
(mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
(thd->fill_derived_tables() &&
mysql_handle_derived(thd->lex, &mysql_derived_filling))))
- DBUG_RETURN(TRUE); /* purecov: inspected */
+ goto err;
DBUG_RETURN(FALSE);
+err:
+ close_thread_tables(thd);
+ DBUG_RETURN(TRUE);
}
@@ -5520,13 +5523,18 @@ bool open_and_lock_tables(THD *thd, TABL
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags)
{
+ DML_prelocking_strategy prelocking_strategy;
uint counter;
DBUG_ENTER("open_normal_and_derived_tables");
DBUG_ASSERT(!thd->fill_derived_tables());
- if (open_tables(thd, &tables, &counter, flags) ||
+ if (open_tables(thd, &tables, &counter, flags, &prelocking_strategy) ||
mysql_handle_derived(thd->lex, &mysql_derived_prepare))
- DBUG_RETURN(TRUE); /* purecov: inspected */
+ goto end;
+
DBUG_RETURN(0);
+end:
+ close_thread_tables(thd);
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
@@ -9233,7 +9241,7 @@ open_system_tables_for_read(THD *thd, TA
DBUG_RETURN(FALSE);
error:
- close_system_tables(thd, backup);
+ thd->restore_backup_open_tables_state(backup);
DBUG_RETURN(TRUE);
}
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2010-07-14 16:32:43 +0000
+++ b/sql/sql_parse.cc 2010-07-16 08:55:35 +0000
@@ -1687,6 +1687,9 @@ int prepare_schema_table(THD *thd, LEX *
In brief: take exclusive locks, expel tables from the table
cache, reopen the tables, enter the 'LOCKED TABLES' mode,
downgrade the locks.
+ Note: the function is written to be called from
+ mysql_execute_command(), it is not reusable in arbitrary
+ execution context.
Required privileges
-------------------
@@ -1788,7 +1791,6 @@ static bool flush_tables_with_read_lock(
&lock_tables_prelocking_strategy) ||
thd->locked_tables_list.init_locked_tables(thd))
{
- close_thread_tables(thd);
goto error;
}
=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc 2010-07-08 21:20:08 +0000
+++ b/sql/sql_plugin.cc 2010-07-16 08:55:35 +0000
@@ -1511,8 +1511,8 @@ static void plugin_load(MEM_ROOT *tmp_ro
sql_print_error(ER(ER_GET_ERRNO), my_errno);
end_read_record(&read_record_info);
table->m_needs_reopen= TRUE; // Force close to free memory
-end:
close_thread_tables(new_thd);
+end:
/* Remember that we don't have a THD */
my_pthread_setspecific_ptr(THR_THD, 0);
DBUG_VOID_RETURN;
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2010-07-13 08:39:24 +0000
+++ b/sql/sql_table.cc 2010-07-16 08:55:35 +0000
@@ -4214,8 +4214,14 @@ warn:
}
-/*
- Database and name-locking aware wrapper for mysql_create_table_no_lock(),
+/**
+ Implementation of SQLCOM_CREATE_TABLE.
+
+ Take the metadata locks (including a shared lock on the affected
+ schema) and create the table. Is written to be called from
+ mysql_execute_command(), to which it delegates the common parts
+ with other commands (i.e. implicit commit before and after,
+ close_thread_tables()).
*/
bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
@@ -4231,7 +4237,7 @@ bool mysql_create_table(THD *thd, TABLE_
if (open_and_lock_tables(thd, thd->lex->query_tables, FALSE, 0))
{
result= TRUE;
- goto unlock;
+ goto end;
}
/* Got lock. */
@@ -4253,16 +4259,7 @@ bool mysql_create_table(THD *thd, TABLE_
!(create_info->options & HA_LEX_CREATE_TMP_TABLE))))
result= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
- if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
- {
- /*
- close_thread_tables() takes care about both closing open tables (which
- might be still around in case of error) and releasing metadata locks.
- */
- close_thread_tables(thd);
- }
-
-unlock:
+end:
DBUG_RETURN(result);
}
Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20100716085535-ilm7yjktycugff4d.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk-runtime branch (kostja:3081) | Konstantin Osipov | 16 Jul |