Quote:
Originally Posted by chrishirst
don't use SELECT * in the query, use a fieldlist instead.
SELECT * makes the query optimiser make TWO passes through the table, one to get the column names, the second to get the data.
|
Hmm, I tried that. It helps slightly, but not by a lot:
Code:
SELECT page.domain, COUNT(*) AS count FROM page JOIN hits USING(id_hit) WHERE hits.site_id=9 AND hits.utime BETWEEN 1183269600 AND 1198479599 AND (hits.status=1 OR hits.status=2) GROUP BY page.domain
I tried some other things, like adding id_hit to my new index. This makes it take nearly the same amount of time as without an index, but not slower:
Code:
ALTER TABLE hits ADD INDEX sid_time_status(id_hit, site_id, utime, status)
I notice that if I remove both the COUNT() AS count and GROUP BY page.domain, then the query is extremely quick. I've tried an index on page.domain, and no benefit seems to come of it. I'm thinking it might be faster just to get the rows without the count and just code a count in PHP.
|