Is it a good idea to index datetime field in mysql?

后端 未结 2 1888

I am working on designing a large database. In my application I will have many rows for example I currently have one table with 4 million records. Most of my queries use dat

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 10:43

    Here author performed tests showed that integer unix timestamp is better than DateTime. Note, he used MySql. But I feel no matter what DB engine you use comparing integers are slightly faster than comparing dates so int index is better than DateTime index. Take T1 - time of comparing 2 dates, T2 - time of comparing 2 integers. Search on indexed field takes approximately O(log(rows)) time because index based on some balanced tree - it may be different for different DB engines but anyway Log(rows) is common estimation. (if you not use bitmask or r-tree based index). So difference is (T2-T1)*Log(rows) - may play role if you perform your query oftenly.

提交回复
热议问题