开发者

Optimize SQL Query on calculated value?

开发者 https://www.devze.com 2022-12-14 14:30 出处:网络
I have a query that requires a where statement on a calculated value: select * from table where date( timestamp ) = ?

I have a query that requires a where statement on a calculated value:

select * from table where date( timestamp ) = ?

An explain on this query yields the expected AL开发者_开发百科L select type, which is not ideal. Using MySQL, what's the best way to optimize this?


Another option might be to rewrite the query such that the calculations are all done on the other side of the equation. For example:

timestamp >= <some date> AND timestamp < <some date + 1>

In this query, "some date" would be midnight of that date.


select * from table where  timestamp  = UNIX_TIMESTAMP('?');
0

精彩评论

暂无评论...
验证码 换一张
取 消