I have a log table. It logs visitor data (time of visit, browser, window size ...).
I want to create reports. I use a query like this (MySQL):
SELECT
COUNT(*) as raw_views ...
FROM logs
WHERE timestamp >= CURDATE()
GROUP BY DATE(timestamp)
The problem is DATE(timestamp). I am using a function on this field, so the index won't work. But the table is huge. Index are very important. But how else can I create hourly, daily, yearly, monthly reports?
I tried to find out how others are doing it. For example Piwik (an open source Google Analytics like script). But I don't really get it.
GROUP BYcan only be used if you have an aggregate, of which you have none. – Remus Rusanu Jul 25 '14 at 08:49user_idwhich stores a id of a user to know to who this entry belongs. Anyway... so there is no "trick" to still use index? – yoshi Jul 25 '14 at 14:08DATE(timestamp)toHOUR(timestamp). In your comments you mention users as well, yet the code has nothing about users. If you want good answers, please edit the question with the queries you have and the table definition. And you really should have done that in the first place, not after 3 days and having 4 people wasting their time answering a question that changes scope. – ypercubeᵀᴹ Jul 28 '14 at 10:18