开发者

Are integer queries on MySQL DATE or TIME columns slow?

开发者 https://www.devze.com 2022-12-18 09:24 出处:网络
Is it more efficient for me to store dates as INTs and convert to and fro a string representation such as \"2010-01-30\" or is it alright to store dates as DATE when needing to perform very frequent i

Is it more efficient for me to store dates as INTs and convert to and fro a string representation such as "2010-01-30" or is it alright to store dates as DATE when needing to perform very frequent integer queries such as WHERE Date < 20100130... Ar开发者_C百科e dates internally stored as strings or integers?


DATE is actually only a 3-byte column, as opposed to a normal INT column which is 4 bytes, so are actually smaller. When you do a query on a DATE field, when you're passing in an integer representation of the date (i.e where `date` < 20100210), it will be converted to the 3-byte value and compared that way... Then again, a DATE field will just store dates and no time information.

It's more efficient to store the date as a DATE.

For more info, look here: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

0

精彩评论

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

关注公众号