mysql查询性能:字段位置

mysql查询性能:字段位置,mysql,performance,Mysql,Performance,是否有任何查询规则规定,哪一个最好先过滤以获得最佳性能?例如: SELECT * FROM table WHERE date <= '2012-08-01' AND random_field = 4684 AND primary_field = 355 SELECT*FROM table WHERE date条件在WHERE子句中的放置顺序根本不重要。重要的是表上的索引 对于此查询: SELECT * FROM table WHERE random_field = 4684 A

是否有任何查询规则规定,哪一个最好先过滤以获得最佳性能?例如:

SELECT * FROM table WHERE date <= '2012-08-01' AND random_field = 4684 AND primary_field = 355

SELECT*FROM table WHERE date条件在
WHERE
子句中的放置顺序根本不重要。重要的是表上的索引

对于此查询:

SELECT * 
FROM table 
WHERE random_field = 4684 
  AND primary_field = 355 
  AND date <= '2012-08-01' ;
选择*
从桌子上
其中,随机_字段=4684
主_字段=355

我们应该遵循一些规则

1. comparison of primary fields should come first and then indexed (because this will filter out required value )
2. Date or range wise (example 2<id<6) should come at the end.
1。应首先比较主字段,然后编制索引(因为这将过滤掉所需的值)

2.日期或范围(示例2顺序完全不相关。您可以使用EXPLAIN查看mysql将使用什么从索引中获取记录。将其置于或上。此外,如果您的WHERE条件中有PRIMARY_KEY=CONST,则与您拥有的其他索引无关。您是对的,主比较就足够了,但为了示例起见,请替换它使用索引_字段,结果会是什么?如果它不是主键,请阅读我答案的第一部分。Thx。我将投票表决它是否有用。让用户回答并投票,我们将在DBA.SE上看到一个类似的问题,关于Postgres:答案似乎是合乎逻辑的。但我需要一些有详细记录的指南,因为每个人都会说出不同的答案回答..让用户投票
1. comparison of primary fields should come first and then indexed (because this will filter out required value )
2. Date or range wise (example 2<id<6) should come at the end.