简体   繁体   中英

indexed varchar column can not be used when query condition is now() function in mysql

Background:

In my case, mysql is 5.7.

There is a table named A and a indexed column named date_str . Data in date_str looks like 2017-01-16 00:00:00 .

Problem:

I've found out that the index can not be used in a range query such as select * from A where date_str > now() . 在此处输入图片说明

But the index is used when the query condition is another function right() .

在此处输入图片说明

Do anyone know why is that? Thanks.

As per your query plan, your index will be used if required.

Before applying any index, database query analyzer analyze the query and estimates the cost of different operations.

If query analyzer finds that applying index will improve the query performance then only it will use the index.

These stats changes by increased/decreased/updated data in table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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