I have a datetime column and I have to filter by date and group it by day or month. This is a million rows table.
|IssueDate |
--------------------
|2015-11-24 16:46:00|
This is the first choice without any index because I always must use a date function:
select * from myTable where DATE(IssueDate)='2015-11-24'
select * from myTable group by DATE(IssueDate)
select * from myTable group by YEAR(IssueDate), MONTH(IssueDate)
This is the second choice, to separate time and date in the table:
|IssueDate |Issuetime|
----------------------
|2015-11-24|16:46:00 |
Here I can index the date field:
select * from myTable where IssueDate='2015-11-24'
select * from myTable group by IssueDate
select * from myTable group by YEAR(IssueDate), MONTH(IssueDate)
Another try with redundancy fest:
|IssueDate |Issuetime|IssueMonth|IssueYear|
-------------------------------------------
|2015-11-24|16:46:00 |11 |2015 |
Here I can index all my fields:
select * from myTable where IssueDate='2015-11-24'
select * from myTable group by IssueDate
select * from myTable group by IssueYear, IssueMonth
What is the way to index this for the best performance?