Bug #71481 Manual does not explain how to refer to table in specific database in HANDLER
Submitted: 26 Jan 2014 11:37 Modified: 18 Feb 2016 17:03
Reporter: Valeriy Kravchuk Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.6.17 OS:Any
Assigned to: Paul DuBois CPU Architecture:Any
Tags: handler

[26 Jan 2014 11:37] Valeriy Kravchuk
Description:
Manual page for HANDLER (http://dev.mysql.com/doc/refman/5.6/en/handler.html) does not say much on what can be the value for tbl_name in:

"HANDLER tbl_name OPEN [ [AS] alias]

HANDLER tbl_name READ index_name { = | <= | >= | < | > } (value1,value2,...)
    [ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST }
    [ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ { FIRST | NEXT }
    [ WHERE where_condition ] [LIMIT ... ]

HANDLER tbl_name CLOSE"

It only explains how to use alias if it was set:

"If you open the table using an alias, further references to the open table with other HANDLER statements must use the alias rather than the table name."

In reality one can use table name qualified by database name in OPEN, but then it seems we have an implicit alias (just table name) defined that must be used in other statements referring to the same handle. This is not at all documented.

How to repeat:
mysql> use mysql
Database changed
mysql> show create table test.tc\G
*************************** 1. row ***************************
       Table: tc
Create Table: CREATE TABLE `tc` (
  `id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> select * from test.tc;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

mysql> handler test.tc open;
Query OK, 0 rows affected (0.00 sec)

mysql> handler test.tc read `PRIMARY` FIRST;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'read
`PRIMARY` FIRST' at line 1
mysql> handler tc read `PRIMARY` FIRST;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

mysql> handler test.tc close;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'close
' at line 1
mysql> handler tc close;
Query OK, 0 rows affected (0.00 sec)

Suggested fix:
Explain the case presented in "How to repeat" above in the manual.
[26 Jan 2014 13:26] Sveta Smirnova
Thank you for the report.

Verified as described.
[18 Feb 2016 17:03] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly.

Updated description:

If you open the table using an alias, further references to the open
table with other HANDLER statements must use the alias rather than
the table name. If you do not use an alias, but open the table using
a table name qualified by the database name, further references must
use the unqualified table name. For example, for a table opened using
mydb.mytable, further references must use mytable.