Commit 19ff2445 authored by Jon Olav Hauglid's avatar Jon Olav Hauglid

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.
parent c0b78cc4
...@@ -319,6 +319,21 @@ alter table t1 add column j int; ...@@ -319,6 +319,21 @@ alter table t1 add column j int;
unlock tables; unlock tables;
drop table t1; 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 # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against
# LOCK TABLE # LOCK TABLE
# #
......
...@@ -385,6 +385,30 @@ alter table t1 add column j int; ...@@ -385,6 +385,30 @@ alter table t1 add column j int;
unlock tables; unlock tables;
drop table t1; 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 #
--echo # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against --echo # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against
--echo # LOCK TABLE --echo # LOCK TABLE
......
...@@ -201,6 +201,11 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) ...@@ -201,6 +201,11 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
tables->db, tables->table_name, tables->alias, tables->db, tables->table_name, tables->alias,
(int) reopen)); (int) reopen));
if (thd->locked_tables_mode)
{
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
DBUG_RETURN(TRUE);
}
if (tables->schema_table) if (tables->schema_table)
{ {
my_error(ER_WRONG_USAGE, MYF(0), "HANDLER OPEN", my_error(ER_WRONG_USAGE, MYF(0), "HANDLER OPEN",
...@@ -386,6 +391,11 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) ...@@ -386,6 +391,11 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables)
DBUG_PRINT("enter",("'%s'.'%s' as '%s'", DBUG_PRINT("enter",("'%s'.'%s' as '%s'",
tables->db, tables->table_name, tables->alias)); 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, if ((hash_tables= (TABLE_LIST*) my_hash_search(&thd->handler_tables_hash,
(uchar*) tables->alias, (uchar*) tables->alias,
strlen(tables->alias) + 1))) strlen(tables->alias) + 1)))
...@@ -448,6 +458,12 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -448,6 +458,12 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
DBUG_PRINT("enter",("'%s'.'%s' as '%s'", DBUG_PRINT("enter",("'%s'.'%s' as '%s'",
tables->db, tables->table_name, tables->alias)); 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); thd->lex->select_lex.context.resolve_in_table_list_only(tables);
list.push_front(new Item_field(&thd->lex->select_lex.context, list.push_front(new Item_field(&thd->lex->select_lex.context,
NULL, NULL, "*")); NULL, NULL, "*"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment