HANDLERtbl_name
OPEN [ [AS]alias
] HANDLERtbl_name
READindex_name
{ = | <= | >= | < | > } (value1
,value2
,...) [ WHEREwhere_condition
] [LIMIT ... ] HANDLERtbl_name
READindex_name
{ FIRST | NEXT | PREV | LAST } [ WHEREwhere_condition
] [LIMIT ... ] HANDLERtbl_name
READ { FIRST | NEXT } [ WHEREwhere_condition
] [LIMIT ... ] HANDLERtbl_name
CLOSE
The HANDLER
statement provides direct access to table storage engine interfaces. HANDLER
语句提供对表存储引擎接口的直接访问。It is available for 它可用于InnoDB
and MyISAM
tables.InnoDB
和MyISAM
表。
The HANDLER ... OPEN
statement opens a table, making it accessible using subsequent HANDLER ... READ
statements. HANDLER ... OPEN
语句打开一个表,使它能被后续的HANDLER ... READ
语句访问。This table object is not shared by other sessions and is not closed until the session calls 此表对象不被其他会话共享,并且在会话调用HANDLER ... CLOSE
or the session terminates.HANDLER ... CLOSE
之前或会话终止之前不会关闭。
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. HANDLER
语句对打开表的进一步引用必须使用别名而不是表名。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
.mydb.mytable
打开的表,进一步的引用必须使用mytable
。
The first 第一个HANDLER ... READ
syntax fetches a row where the index specified satisfies the given values and the WHERE
condition is met. HANDLER ... READ
语法获取指定索引满足给定值且满足WHERE
条件的行。If you have a multiple-column index, specify the index column values as a comma-separated list. 如果有多列索引,请将索引列值指定为逗号分隔的列表。Either specify values for all the columns in the index, or specify values for a leftmost prefix of the index columns. 为索引中的所有列指定值,或为索引列的最左侧前缀指定值。Suppose that an index 假设索引my_idx
includes three columns named col_a
, col_b
, and col_c
, in that order. my_idx
包含三列,按顺序命名为col_a
、col_b
和col_c
。The HANDLER
statement can specify values for all three columns in the index, or for the columns in a leftmost prefix. HANDLER
语句可以为索引中的所有三列指定值,也可以为最左侧前缀中的列指定值。For example:例如:
HANDLER ... READ my_idx = (col_a_val,col_b_val,col_c_val) ... HANDLER ... READ my_idx = (col_a_val,col_b_val) ... HANDLER ... READ my_idx = (col_a_val) ...
To employ the 要使用HANDLER
interface to refer to a table's PRIMARY KEY
, use the quoted identifier `PRIMARY`
:HANDLER
接口引用表的主键,请使用带引号的标识符`PRIMARY`
:
HANDLER tbl_name
READ `PRIMARY` ...
The second 第二个HANDLER ... READ
syntax fetches a row from the table in index order that matches the WHERE
condition.HANDLER ... READ
语法按与WHERE
条件匹配的索引顺序从表中获取行。
The third 第三个HANDLER ... READ
syntax fetches a row from the table in natural row order that matches the WHERE
condition. HANDLER ... READ
语法按与WHERE
条件匹配的自然行顺序从表中获取行。It is faster than 当需要全表扫描时,它比HANDLER
when a full table scan is desired. tbl_name
READ index_name
HANDLER
要快。tbl_name
READ index_name
Natural row order is the order in which rows are stored in a 自然行顺序是在MyISAM
table data file. MyISAM
表数据文件中存储行的顺序。This statement works for 这个语句也适用于InnoDB
tables as well, but there is no such concept because there is no separate data file.InnoDB
表,但是没有这样的概念,因为没有单独的数据文件。
Without a 没有LIMIT
clause, all forms of HANDLER ... READ
fetch a single row if one is available. LIMIT
子句,HANDLER ... READ
的所有形式,如果一行可用,则只读取一行。To return a specific number of rows, include a 要返回特定数量的行,请包含LIMIT
clause. LIMIT
子句。It has the same syntax as for the 它的语法与SELECT
statement. SELECT
语句相同。See Section 13.2.10, “SELECT Statement”.请参阅第13.2.10节,“SELECT语句”。
HANDLER ... CLOSE
closes a table that was opened with HANDLER ... OPEN
.HANDLER ... CLOSE
关闭用HANDLER ... OPEN
打开的表。
There are several reasons to use the 使用HANDLER
interface instead of normal SELECT
statements:HANDLER
接口而不是普通的SELECT
语句有几个原因:
HANDLER
is faster than SELECT
:HANDLER
比SELECT
更快:
A designated storage engine handler object is allocated for the 已为HANDLER ... OPEN
. HANDLER ... OPEN
分配指定的存储引擎处理程序对象。The object is reused for subsequent 针对该表的后续HANDLER
statements for that table; it need not be reinitialized for each one.HANDLER
语句,对象被重复使用;它不需要为每一个重新初始化。
There is less parsing involved.涉及的解析更少。
There is no optimizer or query-checking overhead.没有优化器或查询检查开销。
The handler interface does not have to provide a consistent look of the data (for example, dirty reads are permitted), so the storage engine can use optimizations that 处理程序接口不必提供一致的数据外观(例如,允许脏读),因此存储引擎可以使用SELECT
does not normally permit.SELECT
通常不允许的优化。
HANDLER
makes it easier to port to MySQL applications that use a low-level ISAM
-like interface. HANDLER
使移植到使用类似ISAM
的低级接口的MySQL应用程序变得更容易。(See Section 15.20, “InnoDB memcached Plugin” for an alternative way to adapt applications that use the key-value store paradigm.)(请参阅第15.20节,“InnoDB memcached Plugin”,以了解适应使用键值存储范例的应用程序的替代方法。)
HANDLER
enables you to traverse a database in a manner that is difficult (or even impossible) to accomplish with SELECT
. HANDLER
使您能够以使用SELECT
很难(甚至不可能)完成的方式遍历数据库。The 在处理为数据库提供交互式用户界面的应用程序时,HANDLER
interface is a more natural way to look at data when working with applications that provide an interactive user interface to the database.HANDLER
界面是查看数据的更自然的方式。
HANDLER
is a somewhat low-level statement. HANDLER
是一个有点低级的语句。For example, it does not provide consistency. 例如,它不提供一致性。That is, 也就是说,HANDLER ... OPEN
does not take a snapshot of the table, and does not lock the table. HANDLER ... OPEN
不获取表的快照,也不锁定表。This means that after a 这意味着在HANDLER ... OPEN
statement is issued, table data can be modified (by the current session or other sessions) and these modifications might be only partially visible to HANDLER ... NEXT
or HANDLER ... PREV
scans.HANDLER ... OPEN
语句发出之后,可以修改表数据(由当前会话或其他会话修改),并且这些修改可能仅对HANDLER ... NEXT
扫描或HANDLER ... PREV
扫描部分可见。
An open handler can be closed and marked for reopen, in which case the handler loses its position in the table. 打开的处理程序可以关闭并标记为重新打开,在这种情况下,处理程序将丢失其在表中的位置。This occurs when both of the following circumstances are true:当以下两种情况都成立时,就会发生这种情况:
Any session executes 任何会话都在处理程序的表上执行FLUSH TABLES
or DDL statements on the handler's table.FLUSH TABLES
或DDL语句。
The session in which the handler is open executes non-打开处理程序的会话执行使用表的非HANDLER
statements that use tables.HANDLER
语句。
TRUNCATE TABLE
for a table closes all handlers for the table that were opened with HANDLER OPEN
.TRUNCATE TABLE
对某个表关闭在HANDLER OPEN
中打开的表的所有处理程序。
If a table is flushed with 如果用FLUSH TABLES
was opened with tbl_name
WITH READ LOCKHANDLER
, the handler is implicitly flushed and loses its position.HANDLER
打开FLUSH TABLES
,则处理程序将隐式刷新并丢失其位置。tbl_name
WITH READ LOCK