3.6.7 Searching on Two Keys在两个关键字上搜索

An OR using a single key is well optimized, as is the handling of AND.使用单个键的ORAND的处理都得到了很好的优化。

The one tricky case is that of searching on two different keys combined with OR:一个棘手的情况是在两个不同的键上结合OR进行搜索:

SELECT field1_index, field2_index FROM test_table
WHERE field1_index = '1' OR  field2_index = '1'

This case is optimized. See Section 8.2.1.3, “Index Merge Optimization”.这个案例是经过优化的。参见第8.2.1.3节,“索引合并优化”

You can also solve the problem efficiently by using a UNION that combines the output of two separate SELECT statements. 您还可以通过使用UNION来高效地解决这个问题,UNION将两个单独的SELECT语句的输出组合在一起。See Section 13.2.10.3, “UNION Clause”.请参阅第13.2.10.3节,“UNION子句”

Each SELECT searches only one key and can be optimized:每个SELECT只搜索一个关键字,并且可以进行优化:

SELECT field1_index, field2_index
    FROM test_table WHERE field1_index = '1'
UNION
SELECT field1_index, field2_index
    FROM test_table WHERE field2_index = '1';