datetime, timestamp 중 어떤 걸 사용할지 확인하고 있습니다.
데이터가 많고 날짜를 조회 조건으로 사용할 예정이고 범위도 넓지 않고 국내에서만 사용합니다.
그래서 datetime을 고려했는데 찾아보니 datetime은 index가 되지 않는다. timestamp가 index가 더 빠르다라는 글들이 있었습니다.
우선 작업은 timestamp로 하면서 다른거 때문에 또 찾아보니 datetime도 index가 잡힌다고 합니다.
그래서 궁금한 점은
datetime은 인덱스가 설정 되는가요? 설정이 된다면.. 아무거나 사용해도 상관없을까요?
https://www.tutorialspoint.com/What-is-the-difference-between-MySQL-DATETIME-and-TIMESTAMP-data-type
블로그가 여기 글을 참고하여 작성했더라고요. datetime은 index가 되지 않는다고 하는데 mysql과 mariadb의 차이일까요?..
datetime 컬럼에 인덱스가 있는데도 인덱스 사용이 안되는 경우라면 선택도가 낮거나 등의 다른 문제가 아닐까 합니다.
datetime, timestamp, int 타입에 대한 성능 토론이 많이 있는데..결론적으로는 데이터 타입에 맞게 쿼리를 사용해야 할 것 같습니다. 아래 두번째 링크의 벤치마크 시나리오에서는 datetime이 대체로 좋은 성능을 보여주네요.
https://stackoverflow.com/questions/4594229/mysql-integer-vs-datetime-index
https://www.vertabelo.com/blog/what-datatype-should-you-use-to-represent-time-in-mysql-we-compare-datetime-timestamp-and-int/