Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 优化包含';或';_Mysql_Indexing - Fatal编程技术网

Mysql 优化包含';或';

Mysql 优化包含';或';,mysql,indexing,Mysql,Indexing,查询: 此查询是否使用索引(a,b)?首先,我将尝试使用中的重写此查询: select * from t where (a = '..' or a = '..') and b = '..' 其次,更好的索引应该是t(b,a)。b没有问题,因为它只在where子句中出现一次,带有= 第三,如果这些不能加快查询速度,则使用union all: select * from t where a in ('..', '..') and b = '..'; 这将绕过where子句优化的限制。解释说什么?

查询:


此查询是否使用索引(a,b)?

首先,我将尝试使用
中的
重写此查询:

select * from t where (a = '..' or a = '..') and b = '..'
其次,更好的索引应该是
t(b,a)
b
没有问题,因为它只在
where
子句中出现一次,带有
=

第三,如果这些不能加快查询速度,则使用
union all

select *
from t
where a in ('..', '..') and b = '..';

这将绕过
where
子句优化的限制。

解释说什么?请参阅此处的文档:并升级到MySQL 5.6,因为它比早期版本更好。@BillKarwin。酷。这意味着MySQL 5.6在这种情况下将使用索引
(a,b)
。我还没有对其进行基准测试,但我认为(b,a)上的索引仍然会更好。
select *
from t
where a = '..' and b = '..'
union all
select *
from t
where a = '..' and b = '..';