简体   繁体   English

MySQL:在具有条件和操作的列上添加索引

[英]MySQL: Add index on column with condition and operation

In a query like this 在这样的查询中

SELECT * FROM myTable WHERE date = LEAST(maxDate, '2013-12-31')

I am looking for an index that will be used during execution. 我正在寻找执行期间将使用的索引。 date and maxDate are Date types. datemaxDateDate类型。

Any suggestions? 有什么建议么?

Use of function(UDF or built-in) in WHERE clause don't take advantage of existing indexes but you can modify your query like below which will be using the already existing indexes on date or maxdate (if there is any) column like WHERE子句中使用function(UDF或内置)不会利用现有索引,但是您可以像下面这样修改查询,它将使用datemaxdate (如果有)列上已经存在的索引,例如

SELECT * FROM myTable 
WHERE date = case when maxDate > '2013-12-31' then maxDate else '2013-12-31' end 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM