diff options
author | Jon Olav Hauglid <jon.hauglid@sun.com> | 2009-12-08 15:56:06 +0100 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@sun.com> | 2009-12-08 15:56:06 +0100 |
commit | 19ff2445b156a11cbd76e7c741ed05e4eb33dc62 (patch) | |
tree | dff4eda1ae5790913638b8b5813d2e84203f4127 | |
parent | c0b78cc47a2da2710cdf580ddbb3b31f5f691a23 (diff) | |
download | mariadb-git-19ff2445b156a11cbd76e7c741ed05e4eb33dc62.tar.gz |
Backport of revno: 2617.68.9
Bug #43272 HANDLER SQL command does not work under LOCK TABLES
HANDLER commands are now explicitly disallowed in LOCK TABLES mode.
Before, HANDLER OPEN gave the misleading error message: "Table x was
not locked with LOCK TABLES". This patch changes HANDLER OPEN/READ/CLOSE
to give ER_LOCK_OR_ACTIVE_TRANSACTION "Can't execute the given command
because you have active locked tables or an active transaction" in
LOCK TABLES mode.
Test case added to lock.test.
-rw-r--r-- | mysql-test/r/lock.result | 15 | ||||
-rw-r--r-- | mysql-test/t/lock.test | 24 | ||||
-rw-r--r-- | sql/sql_handler.cc | 16 |
3 files changed, 55 insertions, 0 deletions
diff --git a/mysql-test/r/lock.result b/mysql-test/r/lock.result index afb444f8ae9..a542d70c5b9 100644 --- a/mysql-test/r/lock.result +++ b/mysql-test/r/lock.result @@ -319,6 +319,21 @@ alter table t1 add column j int; unlock tables; drop table t1; # +# Bug #43272 HANDLER SQL command does not work under LOCK TABLES +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a INT); +LOCK TABLE t1 WRITE; +# HANDLER commands are not allowed in LOCK TABLES mode +HANDLER t1 OPEN; +ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction +HANDLER t1 READ FIRST; +ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction +HANDLER t1 CLOSE; +ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction +UNLOCK TABLES; +DROP TABLE t1; +# # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against # LOCK TABLE # diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index 4d610559077..64003c9d861 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -385,6 +385,30 @@ alter table t1 add column j int; unlock tables; drop table t1; + +--echo # +--echo # Bug #43272 HANDLER SQL command does not work under LOCK TABLES +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (a INT); +LOCK TABLE t1 WRITE; + +--echo # HANDLER commands are not allowed in LOCK TABLES mode +--error ER_LOCK_OR_ACTIVE_TRANSACTION +HANDLER t1 OPEN; +--error ER_LOCK_OR_ACTIVE_TRANSACTION +HANDLER t1 READ FIRST; +--error ER_LOCK_OR_ACTIVE_TRANSACTION +HANDLER t1 CLOSE; + +UNLOCK TABLES; +DROP TABLE t1; + + --echo # --echo # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against --echo # LOCK TABLE diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 1b7e45cec5d..5bdf8611f5e 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -201,6 +201,11 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) tables->db, tables->table_name, tables->alias, (int) reopen)); + if (thd->locked_tables_mode) + { + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + DBUG_RETURN(TRUE); + } if (tables->schema_table) { my_error(ER_WRONG_USAGE, MYF(0), "HANDLER OPEN", @@ -386,6 +391,11 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) DBUG_PRINT("enter",("'%s'.'%s' as '%s'", tables->db, tables->table_name, tables->alias)); + if (thd->locked_tables_mode) + { + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + DBUG_RETURN(TRUE); + } if ((hash_tables= (TABLE_LIST*) my_hash_search(&thd->handler_tables_hash, (uchar*) tables->alias, strlen(tables->alias) + 1))) @@ -448,6 +458,12 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, DBUG_PRINT("enter",("'%s'.'%s' as '%s'", tables->db, tables->table_name, tables->alias)); + if (thd->locked_tables_mode) + { + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + DBUG_RETURN(TRUE); + } + thd->lex->select_lex.context.resolve_in_table_list_only(tables); list.push_front(new Item_field(&thd->lex->select_lex.context, NULL, NULL, "*")); |